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