|
20 | 20 | #For test of issue 136154 |
21 | 21 | GLOBAL_136154 = 42 |
22 | 22 |
|
| 23 | +# For frozendict JIT tests |
| 24 | +FROZEN_DICT_CONST = frozendict(x=1, y=2) |
| 25 | + |
| 26 | + |
23 | 27 | @contextlib.contextmanager |
24 | 28 | def clear_executors(func): |
25 | 29 | # Clear executors in func before and after running a block |
@@ -4155,6 +4159,35 @@ def testfunc(n): |
4155 | 4159 | self.assertLessEqual(count_ops(ex, "_POP_TOP_INT"), 1) |
4156 | 4160 | self.assertIn("_POP_TOP_NOP", uops) |
4157 | 4161 |
|
| 4162 | + def test_binary_subscr_frozendict_lowering(self): |
| 4163 | + def testfunc(n): |
| 4164 | + x = 0 |
| 4165 | + for _ in range(n): |
| 4166 | + x += FROZEN_DICT_CONST['x'] |
| 4167 | + return x |
| 4168 | + |
| 4169 | + res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD) |
| 4170 | + self.assertEqual(res, TIER2_THRESHOLD) |
| 4171 | + self.assertIsNotNone(ex) |
| 4172 | + uops = get_opnames(ex) |
| 4173 | + self.assertIn("_INSERT_2_LOAD_CONST_INLINE_BORROW", uops) |
| 4174 | + self.assertNotIn("_BINARY_OP_SUBSCR_DICT", uops) |
| 4175 | + |
| 4176 | + def test_binary_subscr_frozendict_const_fold(self): |
| 4177 | + def testfunc(n): |
| 4178 | + x = 0 |
| 4179 | + for _ in range(n): |
| 4180 | + if FROZEN_DICT_CONST['x'] == 1: |
| 4181 | + x += 1 |
| 4182 | + return x |
| 4183 | + |
| 4184 | + res, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD) |
| 4185 | + self.assertEqual(res, TIER2_THRESHOLD) |
| 4186 | + self.assertIsNotNone(ex) |
| 4187 | + uops = get_opnames(ex) |
| 4188 | + # lookup result is folded to constant 1, so comparison is optimized away |
| 4189 | + self.assertNotIn("_COMPARE_OP_INT", uops) |
| 4190 | + |
4158 | 4191 | def test_binary_subscr_list_slice(self): |
4159 | 4192 | def testfunc(n): |
4160 | 4193 | x = 0 |
|
0 commit comments