@@ -1062,6 +1062,41 @@ def test_conditional_jump_forward_non_const_condition(self):
1062
1062
consts = [0 , 1 , 2 , 3 , 4 ],
1063
1063
expected_consts = [0 , 2 , 3 ])
1064
1064
1065
+ def test_multiple_foldings (self ):
1066
+ before = [
1067
+ ('LOAD_SMALL_INT' , 1 , 0 ),
1068
+ ('LOAD_SMALL_INT' , 2 , 0 ),
1069
+ ('BUILD_TUPLE' , 1 , 0 ),
1070
+ ('LOAD_SMALL_INT' , 0 , 0 ),
1071
+ ('BINARY_SUBSCR' , None , 0 ),
1072
+ ('BUILD_TUPLE' , 2 , 0 ),
1073
+ ('RETURN_VALUE' , None , 0 )
1074
+ ]
1075
+ after = [
1076
+ ('LOAD_CONST' , 1 , 0 ),
1077
+ ('RETURN_VALUE' , None , 0 )
1078
+ ]
1079
+ self .cfg_optimization_test (before , after , consts = [], expected_consts = [(2 ,), (1 , 2 )])
1080
+
1081
+ def test_fold_tuple_of_constants_nops (self ):
1082
+ before = [
1083
+ ('NOP' , None , 0 ),
1084
+ ('LOAD_SMALL_INT' , 1 , 0 ),
1085
+ ('NOP' , None , 0 ),
1086
+ ('LOAD_SMALL_INT' , 2 , 0 ),
1087
+ ('NOP' , None , 0 ),
1088
+ ('NOP' , None , 0 ),
1089
+ ('LOAD_SMALL_INT' , 3 , 0 ),
1090
+ ('NOP' , None , 0 ),
1091
+ ('BUILD_TUPLE' , 3 , 0 ),
1092
+ ('RETURN_VALUE' , None , 0 ),
1093
+ ]
1094
+ after = [
1095
+ ('LOAD_CONST' , 0 , 0 ),
1096
+ ('RETURN_VALUE' , None , 0 ),
1097
+ ]
1098
+ self .cfg_optimization_test (before , after , consts = [], expected_consts = [(1 , 2 , 3 )])
1099
+
1065
1100
def test_conditional_jump_forward_const_condition (self ):
1066
1101
# The unreachable branch of the jump is removed, the jump
1067
1102
# becomes redundant and is replaced by a NOP (for the lineno)
0 commit comments