GH-137276: Don't mark uop as escaping if the escaping call is on an exit branch#137277
Merged
markshannon merged 4 commits intopython:mainpython/cpython:mainfrom Aug 2, 2025
faster-cpython:exits-arent-escapesfaster-cpython/cpython:exits-arent-escapesCopy head branch name to clipboard
Merged
GH-137276: Don't mark uop as escaping if the escaping call is on an exit branch#137277markshannon merged 4 commits intopython:mainpython/cpython:mainfrom faster-cpython:exits-arent-escapesfaster-cpython/cpython:exits-arent-escapesCopy head branch name to clipboard
markshannon merged 4 commits intopython:mainpython/cpython:mainfrom
faster-cpython:exits-arent-escapesfaster-cpython/cpython:exits-arent-escapesCopy head branch name to clipboard
Conversation
brandtbucher
approved these changes
Aug 2, 2025
Member
brandtbucher
left a comment
There was a problem hiding this comment.
Seems correct, nice fix.
Tools/cases_generator/analyzer.py
Outdated
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) |
Member
There was a problem hiding this comment.
The way these functions are nested is sort of weird. Is there a reason they're not just defined at the top level?
Member
Author
There was a problem hiding this comment.
Just grouping. I've flattened the hierarchy to be more consistent with the rest of the code.
Agent-Hellboy
pushed a commit
to Agent-Hellboy/cpython
that referenced
this pull request
Aug 19, 2025
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
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.