-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
GH-137276: Don't mark uop as escaping if the escaping call is on an exit branch #137277
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
Open
markshannon
wants to merge
3
commits into
python:main
Choose a base branch
from
faster-cpython:exits-arent-escapes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+109
−50
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
brandtbucher
approved these changes
Aug 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems correct, nice fix.
Comment on lines
+829
to
+882
def op_escapes(op: parser.CodeDef) -> bool: | ||
|
||
def is_simple_exit(stmt: Stmt) -> bool: | ||
if not isinstance(stmt, SimpleStmt): | ||
return False | ||
tokens = stmt.contents | ||
if len(tokens) < 4: | ||
return False | ||
return ( | ||
tokens[0].text in ("ERROR_IF", "DEOPT_IF", "EXIT_IF") | ||
and | ||
tokens[1].text == "(" | ||
and | ||
tokens[2].text in ("true", "1") | ||
and | ||
tokens[3].text == ")" | ||
) | ||
|
||
def escapes_list(stmts: list[Stmt]) -> bool: | ||
if not stmts: | ||
return False | ||
if is_simple_exit(stmts[-1]): | ||
return False | ||
for stmt in stmts: | ||
if escapes(stmt): | ||
return True | ||
return False | ||
|
||
def escapes(stmt: Stmt) -> bool: | ||
if isinstance(stmt, BlockStmt): | ||
return escapes_list(stmt.body) | ||
elif isinstance(stmt, SimpleStmt): | ||
for tkn in stmt.contents: | ||
if tkn.text == "DECREF_INPUTS": | ||
return True | ||
d: dict[SimpleStmt, EscapingCall] = {} | ||
escaping_call_in_simple_stmt(stmt, d) | ||
return bool(d) | ||
elif isinstance(stmt, IfStmt): | ||
if stmt.else_body and escapes(stmt.else_body): | ||
return True | ||
return escapes(stmt.body) | ||
elif isinstance(stmt, MacroIfStmt): | ||
if stmt.else_body and escapes_list(stmt.else_body): | ||
return True | ||
return escapes_list(stmt.body) | ||
elif isinstance(stmt, ForStmt): | ||
return escapes(stmt.body) | ||
elif isinstance(stmt, WhileStmt): | ||
return escapes(stmt.body) | ||
else: | ||
assert False, "Unexpected statement type" | ||
|
||
return escapes(op.block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The way these functions are nested is sort of weird. Is there a reason they're not just defined at the top level?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.