-
-
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
Conversation
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.
Tools/cases_generator/analyzer.py
Outdated
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?
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.
Just grouping. I've flattened the hierarchy to be more consistent with the rest of the code.
Uh oh!
There was an error while loading. Please reload this page.