@@ -826,60 +826,59 @@ def stack_effect_only_peeks(instr: parser.InstDef) -> bool:
826826 )
827827
828828
829- def op_escapes (op : parser .CodeDef ) -> bool :
829+ def stmt_is_simple_exit (stmt : Stmt ) -> bool :
830+ if not isinstance (stmt , SimpleStmt ):
831+ return False
832+ tokens = stmt .contents
833+ if len (tokens ) < 4 :
834+ return False
835+ return (
836+ tokens [0 ].text in ("ERROR_IF" , "DEOPT_IF" , "EXIT_IF" )
837+ and
838+ tokens [1 ].text == "("
839+ and
840+ tokens [2 ].text in ("true" , "1" )
841+ and
842+ tokens [3 ].text == ")"
843+ )
830844
831- def is_simple_exit (stmt : Stmt ) -> bool :
832- if not isinstance (stmt , SimpleStmt ):
833- return False
834- tokens = stmt .contents
835- if len (tokens ) < 4 :
836- return False
837- return (
838- tokens [0 ].text in ("ERROR_IF" , "DEOPT_IF" , "EXIT_IF" )
839- and
840- tokens [1 ].text == "("
841- and
842- tokens [2 ].text in ("true" , "1" )
843- and
844- tokens [3 ].text == ")"
845- )
846845
847- def escapes_list (stmts : list [Stmt ]) -> bool :
848- if not stmts :
849- return False
850- if is_simple_exit (stmts [- 1 ]):
851- return False
852- for stmt in stmts :
853- if escapes (stmt ):
854- return True
846+ def stmt_list_escapes (stmts : list [Stmt ]) -> bool :
847+ if not stmts :
848+ return False
849+ if stmt_is_simple_exit (stmts [- 1 ]):
855850 return False
851+ for stmt in stmts :
852+ if stmt_escapes (stmt ):
853+ return True
854+ return False
856855
857- def escapes (stmt : Stmt ) -> bool :
858- if isinstance (stmt , BlockStmt ):
859- return escapes_list (stmt .body )
860- elif isinstance (stmt , SimpleStmt ):
861- for tkn in stmt .contents :
862- if tkn .text == "DECREF_INPUTS" :
863- return True
864- d : dict [SimpleStmt , EscapingCall ] = {}
865- escaping_call_in_simple_stmt (stmt , d )
866- return bool (d )
867- elif isinstance (stmt , IfStmt ):
868- if stmt .else_body and escapes (stmt .else_body ):
869- return True
870- return escapes (stmt .body )
871- elif isinstance (stmt , MacroIfStmt ):
872- if stmt .else_body and escapes_list (stmt .else_body ):
856+
857+ def stmt_escapes (stmt : Stmt ) -> bool :
858+ if isinstance (stmt , BlockStmt ):
859+ return stmt_list_escapes (stmt .body )
860+ elif isinstance (stmt , SimpleStmt ):
861+ for tkn in stmt .contents :
862+ if tkn .text == "DECREF_INPUTS" :
873863 return True
874- return escapes_list (stmt .body )
875- elif isinstance (stmt , ForStmt ):
876- return escapes (stmt .body )
877- elif isinstance (stmt , WhileStmt ):
878- return escapes (stmt .body )
879- else :
880- assert False , "Unexpected statement type"
864+ d : dict [SimpleStmt , EscapingCall ] = {}
865+ escaping_call_in_simple_stmt (stmt , d )
866+ return bool (d )
867+ elif isinstance (stmt , IfStmt ):
868+ if stmt .else_body and stmt_escapes (stmt .else_body ):
869+ return True
870+ return stmt_escapes (stmt .body )
871+ elif isinstance (stmt , MacroIfStmt ):
872+ if stmt .else_body and stmt_list_escapes (stmt .else_body ):
873+ return True
874+ return stmt_list_escapes (stmt .body )
875+ elif isinstance (stmt , ForStmt ):
876+ return stmt_escapes (stmt .body )
877+ elif isinstance (stmt , WhileStmt ):
878+ return stmt_escapes (stmt .body )
879+ else :
880+ assert False , "Unexpected statement type"
881881
882- return escapes (op .block )
883882
884883def compute_properties (op : parser .CodeDef ) -> Properties :
885884 escaping_calls = find_escaping_api_calls (op )
@@ -902,7 +901,7 @@ def compute_properties(op: parser.CodeDef) -> Properties:
902901 )
903902 error_with_pop = has_error_with_pop (op )
904903 error_without_pop = has_error_without_pop (op )
905- escapes = op_escapes (op )
904+ escapes = stmt_escapes (op . block )
906905 pure = False if isinstance (op , parser .LabelDef ) else "pure" in op .annotations
907906 no_save_ip = False if isinstance (op , parser .LabelDef ) else "no_save_ip" in op .annotations
908907 return Properties (
0 commit comments