@@ -98,6 +98,8 @@ def effect_size(effect: StackEffect) -> tuple[int, str]:
98
98
assert not effect .cond , "Array effects cannot have a condition"
99
99
return 0 , effect .size
100
100
elif effect .cond :
101
+ if effect .cond in ("0" , "1" ):
102
+ return 0 , effect .cond
101
103
return 0 , f"{ maybe_parenthesize (effect .cond )} ? 1 : 0"
102
104
else :
103
105
return 1 , ""
@@ -217,7 +219,7 @@ def stack_adjust(
217
219
self .emit (f"STACK_GROW({ osym } );" )
218
220
219
221
def declare (self , dst : StackEffect , src : StackEffect | None ):
220
- if dst .name == UNUSED :
222
+ if dst .name == UNUSED or dst . cond == "0" :
221
223
return
222
224
typ = f"{ dst .type } " if dst .type else "PyObject *"
223
225
if src :
@@ -241,7 +243,10 @@ def assign(self, dst: StackEffect, src: StackEffect):
241
243
self .emit (f"Py_XSETREF({ dst .name } , { cast } { src .name } );" )
242
244
else :
243
245
stmt = f"{ dst .name } = { cast } { src .name } ;"
244
- if src .cond :
246
+ if src .cond and src .cond != "1" :
247
+ if src .cond == "0" :
248
+ # It will not be executed
249
+ return
245
250
stmt = f"if ({ src .cond } ) {{ { stmt } }}"
246
251
self .emit (stmt )
247
252
@@ -1067,7 +1072,10 @@ def effect_str(effects: list[StackEffect]) -> str:
1067
1072
for effect in comp .instr .output_effects :
1068
1073
assert not effect .size , effect
1069
1074
if effect .cond :
1070
- pushed_symbolic .append (maybe_parenthesize (f"{ maybe_parenthesize (effect .cond )} ? 1 : 0" ))
1075
+ if effect .cond in ("0" , "1" ):
1076
+ pushed_symbolic .append (effect .cond )
1077
+ else :
1078
+ pushed_symbolic .append (maybe_parenthesize (f"{ maybe_parenthesize (effect .cond )} ? 1 : 0" ))
1071
1079
sp += 1
1072
1080
high = max (sp , high )
1073
1081
if high != max (0 , sp ):
0 commit comments