Skip to content

sys.monitoring branch for match case mapping to None #123048

Description

@jaltmayerpizzorno

Bug report

Bug description:

With the code from PR 122564, the destination of the "not taken" branch out of line 9 below, offset 46, maps (through co_locations()) to None, making it difficult (if not impossible) to interpret for coverage:

x = 0
v = 1
match v:
    case 1:
        if x < 0:
            x = 1
    case 2:
        if x < 0:
            x = 1
x += 1

Result:

   0          0       RESUME                   0

   1          2       LOAD_CONST               0 (0)
              4       STORE_NAME               0 (x)

   2          6       LOAD_CONST               1 (1)
              8       STORE_NAME               1 (v)

   3         10       LOAD_NAME                1 (v)

   4         12       COPY                     1
             14       LOAD_CONST               1 (1)
             16       COMPARE_OP              88 (bool(==))
             20       POP_JUMP_IF_FALSE       12 (to L2)
             24       NOT_TAKEN
             26       POP_TOP

   5         28       LOAD_NAME                0 (x)
             30       LOAD_CONST               0 (0)
             32       COMPARE_OP              18 (bool(<))
             36       POP_JUMP_IF_FALSE        3 (to L1)
             40       NOT_TAKEN

   6         42       LOAD_CONST               1 (1)
             44       STORE_NAME               0 (x)

  --   L1:   46       JUMP_FORWARD            15 (to L3)

   7   L2:   48       LOAD_CONST               2 (2)
             50       COMPARE_OP              88 (bool(==))
             54       POP_JUMP_IF_FALSE       10 (to L3)
             58       NOT_TAKEN

   8         60       LOAD_NAME                0 (x)
             62       LOAD_CONST               0 (0)
             64       COMPARE_OP              18 (bool(<))
             68       POP_JUMP_IF_FALSE        3 (to L3)
             72       NOT_TAKEN

   9         74       LOAD_CONST               1 (1)
             76       STORE_NAME               0 (x)

  10   L3:   78       LOAD_NAME                0 (x)
             80       LOAD_CONST               1 (1)
             82       BINARY_OP               13 (+=)
             86       STORE_NAME               0 (x)
             88       RETURN_CONST             3 (None)
'<module>' branches:
    ex9.py 4:9-4:10 "1" (<module>@20) -> 4:9-4:10 "1" (<module>@26) [case -> out]
    ex9.py 4:9-4:10 "1" (<module>@20) -> 7:9-7:10 "2" (<module>@48) [case -> next case]
    ex9.py 5:11-5:16 "x < 0" (<module>@36) -> 6:16-6:17 "1" (<module>@42) [if/while -> block]
    ex9.py 5:11-5:16 "x < 0" (<module>@36) -> (start_line=None) (<module>@46) [(dst.start_line=None)]
    ex9.py 7:9-7:10 "2" (<module>@54) -> 8:11-8:12 "x" (<module>@60) [case -> body]
    ex9.py 7:9-7:10 "2" (<module>@54) -> 10:0-10:1 "x" (<module>@78) [case -> next stmt]
    ex9.py 8:11-8:16 "x < 0" (<module>@68) -> 9:16-9:17 "1" (<module>@74) [if/while -> block]
    ex9.py 8:11-8:16 "x < 0" (<module>@68) -> 10:0-10:1 "x" (<module>@78) [if/while -> next stmt]

This may be related to #123044.

@markshannon @nedbat

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. markshannon commented on Aug 16, 2024

    @markshannon
    Member

    For some reason, jump threading hasn't converted the jump at 36, POP_JUMP_IF_FALSE 3 (to L1) to a jump to L3.
    Not only that, but the jump at L1 lacks a location.
    Fixing the jump threading, or adding a location to 46 JUMP_FORWARD 15 (to L3) would fix this.

  2. added 2 commits that reference this issue on Aug 20, 2024
  3. nedbat commented on Aug 20, 2024

    @nedbat
    Member

    Thanks! @markshannon would it be possible to get these kinds of fixes onto your branch as well, so there is one place to try the latest code?

  4. added 2 commits that reference this issue on Aug 20, 2024
  5. added a commit that references this issue on Aug 20, 2024
  6. added a commit that references this issue on Aug 22, 2024
  7. added a commit that references this issue on Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

interpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions