gh-131798: JIT: Narrow the return type of _CALL_LEN to int by diegorusso · Pull Request #132940 · python/cpython
Comment on lines +1916 to +1920
| a = [1, 2, 3, 4] | ||
| for _ in range(n): | ||
| _ = len(a) - 1 | ||
|
|
||
| _, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD) |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if it's needed in this case, but for other tests there's normally a 'control' variable that checks that the result is still correct even with the optimization. Something like this:
| a = [1, 2, 3, 4] | |
| for _ in range(n): | |
| _ = len(a) - 1 | |
| _, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD) | |
| x = 0 | |
| a = [1, 2, 3, 4] | |
| for _ in range(n): | |
| _ = len(a) - 1 | |
| if _ == 3: | |
| x += 1 | |
| _, ex = self._run_with_optimizer(testfunc, TIER2_THRESHOLD) | |
| self.assertEqual(res, TIER2_THRESHOLD) |
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, I'll do it.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK the problem is if I add this, _GUARD_TOS_INT and _GUARD_NOS_INT are appearing in the uops list.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we can't do it. x is from outside the loop (trace), so the first x += 1 has to have a guard somewhere.