gh-131798: JIT: Narrow the return type of _CALL_LEN to int#132940
Merged
Fidget-Spinner merged 4 commits intopython:mainfrom Apr 25, 2025
Merged
gh-131798: JIT: Narrow the return type of _CALL_LEN to int#132940Fidget-Spinner merged 4 commits intopython:mainfrom
Fidget-Spinner merged 4 commits intopython:mainfrom
Conversation
Reduce unnecessary guards whenever `len()` is called and used in arithmetic operations.
Member
|
Windows JIT builds might've been broken by #132852. That PR did not trigger JIT CI. |
tomasr8
reviewed
Apr 25, 2025
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) |
Member
There was a problem hiding this comment.
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:
Suggested change
| 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) |
Contributor
Author
There was a problem hiding this comment.
Good point, I'll do it.
Contributor
Author
There was a problem hiding this comment.
OK the problem is if I add this, _GUARD_TOS_INT and _GUARD_NOS_INT are appearing in the uops list.
Member
There was a problem hiding this comment.
Yeah we can't do it. x is from outside the loop (trace), so the first x += 1 has to have a guard somewhere.
tekknolagi
reviewed
Apr 25, 2025
Misc/NEWS.d/next/Core_and_Builtins/2025-04-25-14-56-45.gh-issue-131798.NpcKub.rst
Outdated
Show resolved
Hide resolved
…e-131798.NpcKub.rst Co-authored-by: Max Bernstein <tekknolagi@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reduce unnecessary guards whenever
len()is called and used in arithmetic operations.