|
23 | 23 | # For frozendict JIT tests |
24 | 24 | FROZEN_DICT_CONST = frozendict(x=1, y=2) |
25 | 25 |
|
| 26 | +# For frozenset JIT tests |
| 27 | +FROZEN_SET_CONST = frozenset({1, 2, 3}) |
| 28 | + |
26 | 29 | class _GenericKey: |
27 | 30 | pass |
28 | 31 |
|
@@ -2169,7 +2172,8 @@ def f(n): |
2169 | 2172 | self.assertIsNotNone(ex) |
2170 | 2173 | uops = get_opnames(ex) |
2171 | 2174 | self.assertNotIn("_GUARD_TOS_ANY_SET", uops) |
2172 | | - self.assertIn("_CONTAINS_OP_SET", uops) |
| 2175 | + # _CONTAINS_OP_SET is constant-folded away for frozenset literals |
| 2176 | + self.assertIn("_INSERT_2_LOAD_CONST_INLINE_BORROW", uops) |
2173 | 2177 |
|
2174 | 2178 | def test_remove_guard_for_known_type_tuple(self): |
2175 | 2179 | def f(n): |
@@ -4399,6 +4403,20 @@ def testfunc(n): |
4399 | 4403 | # lookup result is folded to constant 1, so comparison is optimized away |
4400 | 4404 | self.assertNotIn("_COMPARE_OP_INT", uops) |
4401 | 4405 |
|
| 4406 | + def test_contains_op_frozenset_const_fold(self): |
| 4407 | + def testfunc(n): |
| 4408 | + x = 0 |
| 4409 | + for _ in range(n): |
| 4410 | + if 1 in FROZEN_SET_CONST: |
| 4411 | + x += 1 |
| 4412 | + return x |
| 4413 | + |
| 4414 | + res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD) |
| 4415 | + self.assertEqual(res, TIER2_THRESHOLD) |
| 4416 | + self.assertIsNotNone(ex) |
| 4417 | + uops = get_opnames(ex) |
| 4418 | + self.assertNotIn("_CONTAINS_OP_SET", uops) |
| 4419 | + |
4402 | 4420 | def test_binary_subscr_list_slice(self): |
4403 | 4421 | def testfunc(n): |
4404 | 4422 | x = 0 |
|
0 commit comments