Skip to content

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
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented Jul 31, 2025

Copy link
Member

@brandtbucher brandtbucher left a 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)
Copy link
Member

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy