File tree Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Expand file tree Collapse file tree 3 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -1616,12 +1616,13 @@ infer_BINARY_OP(
1616
1616
PyTypeObject * righttype = (PyTypeObject * )_Py_TYPENODE_CLEAR_TAG (rightroot );
1617
1617
1618
1618
if (_Py_TYPENODE_IS_POSITIVE_NULL (leftroot )
1619
- && (righttype == & PyLong_Type
1619
+ && (righttype == & PyLong_Type || righttype == & PySmallInt_Type
1620
1620
|| righttype == & PyFloat_Type || righttype == & PyRawFloat_Type )) {
1621
1621
// Check if same type as right
1622
1622
* needs_guard = true;
1623
1623
write_curr = emit_type_guard (write_curr ,
1624
- righttype == & PyLong_Type ? CHECK_INT : CHECK_FLOAT , 1 , bb_id );
1624
+ (righttype == & PyLong_Type || righttype == & PySmallInt_Type )
1625
+ ? CHECK_INT : CHECK_FLOAT , 1 , bb_id );
1625
1626
return write_curr ;
1626
1627
}
1627
1628
if (_Py_TYPENODE_GET_TAG (leftroot ) == TYPE_ROOT_NEGATIVE ) {
@@ -1661,7 +1662,8 @@ infer_BINARY_OP(
1661
1662
type_propagate (opcode , 0 , type_context , NULL );
1662
1663
return write_curr ;
1663
1664
}
1664
- if (righttype == & PyLong_Type && lefttype == & PyLong_Type ) {
1665
+ if ((righttype == & PyLong_Type || righttype == & PySmallInt_Type )
1666
+ && (lefttype == & PyLong_Type || lefttype == & PySmallInt_Type )) {
1665
1667
int opcode = oparg == NB_ADD
1666
1668
? BINARY_OP_ADD_INT_REST
1667
1669
: oparg == NB_SUBTRACT
Original file line number Diff line number Diff line change @@ -138,6 +138,7 @@ We provide pre-compiled binaries for 64-bit Windows 10/11 via GitHub releases.
138
138
* Mark interpreter frames as tier 2 or not in https://github.com/pylbbv/pylbbv/pull/34
139
139
* Make instruction offset calculation frame aware in https://github.com/pylbbv/pylbbv/pull/37
140
140
* Support multiple entry points in a Basic Block in https://github.com/pylbbv/pylbbv/pull/39 and https://github.com/pylbbv/pylbbv/pull/40
141
+ * ` BINARY_OP ` specialisations now apply to ` PySmallInt_Type ` in https://github.com/pylbbv/pylbbv/pull/46
141
142
* Improved workflow:
142
143
* workflow: enable CI GH actions tests in https://github.com/pylbbv/pylbbv/pull/35
143
144
* Improved type propagator:
Original file line number Diff line number Diff line change @@ -615,6 +615,36 @@ def f(x, items):
615
615
616
616
# As long as it doesn't crash, everything's good
617
617
618
+ with TestInfo ("infer_BINARY_OP to be compatible with smallint" ):
619
+ # See https://github.com/pylbbv/pylbbv/issues/45 for more information.
620
+
621
+ # Testing left smallint
622
+ def f (a , b ):
623
+ z = a + b
624
+ return z + 1
625
+
626
+ trigger_tier2 (f , (1 ,1 ))
627
+ insts = dis .get_instructions (test_typeprop1 , tier2 = True )
628
+ assert [x .opname for x in insts ].count ("BINARY_OP_ADD_INT_REST" ) == 2
629
+
630
+ # Testing right smallint
631
+ def f (a , b ):
632
+ z = a + b
633
+ return 1 + z
634
+
635
+ trigger_tier2 (f , (1 ,1 ))
636
+ insts = dis .get_instructions (test_typeprop1 , tier2 = True )
637
+ assert [x .opname for x in insts ].count ("BINARY_OP_ADD_INT_REST" ) == 2
638
+
639
+ # Testing both sides smallint
640
+ def f (a , b ):
641
+ z = a + b
642
+ w = 1
643
+ return 1 + w
644
+ trigger_tier2 (f , (1 ,1 ))
645
+ insts = dis .get_instructions (test_typeprop1 , tier2 = True )
646
+ assert [x .opname for x in insts ].count ("BINARY_OP_ADD_INT_REST" ) == 2
647
+
618
648
print ("Regression tests...Done!" )
619
649
620
650
print ("Tests completed ^-^" )
You can’t perform that action at this time.
0 commit comments