@@ -76,6 +76,18 @@ def __init__(self, state):
7676 self .state = state
7777
7878 def run_pass (self ):
79+ """
80+ The function could return exxeption. It means that the IR transformation can not be completed.
81+ This is acceptable behaviour.
82+ """
83+
84+ try :
85+ self .run_pass_throw ()
86+ return True
87+ except ValueError :
88+ return False
89+
90+ def run_pass_throw (self ):
7991 blocks = self .state .func_ir .blocks
8092 # topo_order necessary so DataFrame data replacement optimization can
8193 # be performed in one pass
@@ -109,8 +121,7 @@ def run_pass(self):
109121 # TODO: add this to dead_branch_prune pass
110122 for inst in self .state .func_ir .blocks [dead_label ].body :
111123 if is_assign (inst ):
112- self .state .func_ir ._definitions [inst .target .name ].remove (
113- inst .value )
124+ self .state .func_ir ._definitions [inst .target .name ].remove (inst .value )
114125
115126 del self .state .func_ir .blocks [dead_label ]
116127 else :
@@ -124,9 +135,7 @@ def run_pass(self):
124135 used_vars = set ()
125136 new_body = []
126137 for inst in reversed (block .body ):
127- if (is_assign (inst )
128- and inst .target .name not in used_vars
129- and inst .target .name in jmp_defs ):
138+ if (is_assign (inst ) and inst .target .name not in used_vars and inst .target .name in jmp_defs ):
130139 self .state .func_ir ._definitions [inst .target .name ].remove (inst .value )
131140 continue
132141 used_vars .update (v .name for v in inst .list_vars ())
@@ -140,7 +149,8 @@ def run_pass(self):
140149 out_nodes = [inst ]
141150
142151 if isinstance (inst , ir .Assign ):
143- self .state .func_ir ._definitions [inst .target .name ].remove (inst .value )
152+ if inst .value in self .state .func_ir ._definitions [inst .target .name ]:
153+ self .state .func_ir ._definitions [inst .target .name ].remove (inst .value )
144154 out_nodes = self ._run_assign (inst )
145155 elif isinstance (inst , (ir .SetItem , ir .StaticSetItem )):
146156 out_nodes = self ._run_setitem (inst )
0 commit comments