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

no_redundant_jumps: Assertion `0' failed #120367

Closed
15r10nk opened this issue Jun 11, 2024 · 7 comments · Fixed by #120425 or #120714
Closed

no_redundant_jumps: Assertion `0' failed #120367

15r10nk opened this issue Jun 11, 2024 · 7 comments · Fixed by #120425 or #120714
Assignees
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@15r10nk
Copy link
Contributor

15r10nk commented Jun 11, 2024

Bug report

Bug description:

The following code causes a crash on cpython 3.13 branch (f5289c4) and the current main.

import ast

code="""
try:
    if name_4:
        pass
    else:
        pass
except* name_0:
    pass
else:
    name_4
"""

tree = ast.parse(code)
for node in ast.walk(tree):
    if hasattr(node,"lineno"):
         del   node.lineno
         del   node.end_lineno
         del   node.col_offset
         del   node.end_col_offset

compile(ast.fix_missing_locations(tree), "<file>", "exec")

output (Python 3.13.0a3+):

python: Python/flowgraph.c:511: no_redundant_jumps: Assertion `0' failed.

I bisected the problem down to 2091fb2.
@iritkatriel can you take a look at it?

CPython versions tested on:

3.13, CPython main branch

Operating systems tested on:

No response

Linked PRs

@15r10nk 15r10nk added the type-bug An unexpected behavior, bug, or error label Jun 11, 2024
@15r10nk
Copy link
Contributor Author

15r10nk commented Jun 12, 2024

I have also several other code samples which trigger the same assertion like:

try:
    pass
except:
    pass
else:
    match name_2:
        case b'':
            pass
finally:
    something

let me know if you need more of them to fix the issue. (The good news is that I have only samples for this issue 😄)

@aisk
Copy link
Contributor

aisk commented Jun 12, 2024

I can re-produce the same crash with f5289c4 or current main branch(7dd8c37).

@aisk aisk added type-crash A hard crash of the interpreter, possibly with a core dump and removed type-bug An unexpected behavior, bug, or error labels Jun 12, 2024
@picnixz
Copy link
Contributor

picnixz commented Jun 12, 2024

On main (e16aed6), I can reproduce the first crash but not the one given in #120367 (comment). The second one only gives me NameError on name_2 (which is fine).

@15r10nk
Copy link
Contributor Author

15r10nk commented Jun 12, 2024

@picnixz sorry I that I did not post the complete example.

import ast

code="""
try:
    pass
except:
    pass
else:
    match name_2:
        case b'':
            pass
finally:
    something
"""

tree = ast.parse(code)
for node in ast.walk(tree):
    if hasattr(node,"lineno"):
         del   node.lineno
         del   node.end_lineno
         del   node.col_offset
         del   node.end_col_offset

compile(ast.fix_missing_locations(tree), "<file>", "exec")

This fails for me also on main

@picnixz
Copy link
Contributor

picnixz commented Jun 12, 2024

Oh yes, now it works (I mean, it works in its failure).

@AlexWaygood AlexWaygood added interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Jun 12, 2024
@iritkatriel iritkatriel self-assigned this Jun 12, 2024
iritkatriel added a commit to iritkatriel/cpython that referenced this issue Jun 12, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 17, 2024
…ring hot-cold blocks (pythonGH-120425)

(cherry picked from commit 21866c8)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
iritkatriel added a commit that referenced this issue Jun 17, 2024
…ering hot-cold blocks (GH-120425) (#120621)

gh-120367: fix removal of redundant NOPs and jumps after reordering hot-cold blocks (GH-120425)
(cherry picked from commit 21866c8)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
@15r10nk
Copy link
Contributor Author

15r10nk commented Jun 18, 2024

@iritkatriel this fix solved most of the samples I found, but there are two samples which look similar and are still failing with the current 3.13 branch (71ad34d)

import ast
source='''
if name_2:
    pass
else:
    try:
        pass
    except:
        pass
~name_5
'''
tree = ast.parse(source)
for node in ast.walk(tree):
    if hasattr(node, 'lineno'):
        del node.lineno
ast.fix_missing_locations(tree)
compile(tree, '', 'exec')

output (Python 3.13.0b2+):

python: Python/flowgraph.c:511: no_redundant_jumps: Assertion `0' failed.

and the second:

import ast
source='''
for [] in b'':
    if name_0:
        pass
    else:
        try:
            pass
        except* name_0:
            pass
    name_2
'''
tree = ast.parse(source)
for node in ast.walk(tree):
    if hasattr(node, 'lineno'):
        del node.lineno
ast.fix_missing_locations(tree)
compile(tree, '', 'exec')

output (Python 3.13.0b2+):

python: Python/flowgraph.c:511: no_redundant_jumps: Assertion `0' failed.

Can you take a look at it?

@iritkatriel iritkatriel reopened this Jun 18, 2024
@iritkatriel
Copy link
Member

iritkatriel commented Jun 18, 2024

I see, what's happening is that we get:

-1: [EH=0 CLD=0 WRM=1 NO_FT=1 0x108866f20] used: 1, depth: 0, preds: 1 
  [00] line: 1, JUMP_NO_INTERRUPT (257)  target: 0x1088673a0 [21] jump 
6: [EH=0 CLD=0 WRM=1 NO_FT=0 0x1088670a0] used: 1, depth: 0, preds: 1 
  [00] line: 1, SETUP_FINALLY (261)  target: 0x108867340 [10] 
-1: [EH=0 CLD=0 WRM=0 NO_FT=0 0x108866fe0] used: 0, depth: 0, preds: 0 
21: [EH=0 CLD=0 WRM=1 NO_FT=1 0x1088673a0] used: 4, depth: 0, preds: 3 return 
  [00] line: 1, LOAD_NAME (92)  arg: 1 
  [01] line: 1, UNARY_INVERT (40)  
  [02] line: 1, POP_TOP (31)  
  [03] line: 1, RETURN_CONST (103)  arg: 0 

The jump is not identified as redundant because of the SETUP_FINALLY, but that is later removed and then the assertion trips. I'll think how to fix it.

(The jump would not be redundant if it, as well as the SETUP_FINALLY, were not artificially forced to appear to be on the same line as the next instruction).

iritkatriel added a commit to iritkatriel/cpython that referenced this issue Jun 18, 2024
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 18, 2024
…pseudo op replacement (pythonGH-120714)

(cherry picked from commit b7f4789)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
iritkatriel pushed a commit that referenced this issue Jun 18, 2024
mrahtz pushed a commit to mrahtz/cpython that referenced this issue Jun 30, 2024
mrahtz pushed a commit to mrahtz/cpython that referenced this issue Jun 30, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
noahbkim pushed a commit to hudson-trading/cpython that referenced this issue Jul 11, 2024
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
estyxx pushed a commit to estyxx/cpython that referenced this issue Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.13 bugs and security fixes 3.14 new features, bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
5 participants