Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tracked by #122548
jaltmayerpizzorno opened this issue Aug 15, 2024 · 2 comments
Closed
Tracked by #122548

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

jaltmayerpizzorno opened this issue Aug 15, 2024 · 2 comments
Assignees
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@jaltmayerpizzorno
Copy link

jaltmayerpizzorno commented Aug 15, 2024

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

@markshannon
Copy link
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.

@nedbat
Copy link
Member

nedbat commented Aug 20, 2024

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?

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 20, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Aug 20, 2024
iritkatriel added a commit that referenced this issue Aug 20, 2024
GH-123167) (#123169)

gh-123048: Fix missing source location in pattern matching code (GH-123167)
(cherry picked from commit bffed80)

Co-authored-by: Irit Katriel <[email protected]>
iritkatriel added a commit that referenced this issue Sep 6, 2024
GH-123167) (#123170)

gh-123048: Fix missing source location in pattern matching code (GH-123167)
(cherry picked from commit bffed80)

Co-authored-by: Irit Katriel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

5 participants