-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
gh-119258: Eliminate Type Guards in Tier 2 Optimizer with Watcher #119365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Fidget-Spinner
merged 42 commits into
python:main
from
saulshanabrook:optimizer-type-version-watcher
Jun 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
e7b7d5d
Add type version and offset to optimizer header
saulshanabrook c902276
Start adding type version
saulshanabrook 89e3649
Add type version functions and struct initialization
saulshanabrook b8525be
fix typo
saulshanabrook 4bd1608
Add failing test case
saulshanabrook ddbfd94
breakpoints and prints
dpdani f22130b
Add function definitions
saulshanabrook 77bc293
wooohoooo
dpdani a2ebc49
unprint
dpdani e982837
Remove generated printf
saulshanabrook 0e7e7eb
Remove test breakpoints
saulshanabrook 4060ab8
📜🤖 Added by blurb_it.
blurb-it[bot] 1520928
Revert "📜🤖 Added by blurb_it."
saulshanabrook 5e0792b
Use global type watcher to invalidate type versions
saulshanabrook fd979f0
Revert formatting changes to tests
saulshanabrook 5da1a40
Add additional test
saulshanabrook 84860ea
Remove printf and make slightly more threadsafe
saulshanabrook c12bb90
fix typo
saulshanabrook 53ab262
Update type watcher ID in test bc we know have a default one at 0
saulshanabrook 88e2e59
Fix panic and add test for it
saulshanabrook 1eabca9
add manual cast
saulshanabrook 1f7cc74
Properly fixed the frame creation with discussion with Ken Jin
saulshanabrook f892ea7
Change type_assign_specific_version_unsafe to use safe setting
saulshanabrook 06ed18f
📜🤖 Added by blurb_it.
blurb-it[bot] 1343571
Fix more places where tp_version_tag is being set manually
brandtbucher 2ee5126
Merge branch 'main' into optimizer-type-version-watcher
brandtbucher 37aeea5
_PyType_ClearCodeByVersion isn't necessary
brandtbucher 9d6171d
Merge branch 'main' into optimizer-type-version-watcher
Fidget-Spinner 545c40b
Merge branch 'main' into optimizer-type-version-watcher
saulshanabrook c4436eb
Rename typ_version to type_version
saulshanabrook 0d0c647
Change type of type_version to unsigned int
saulshanabrook 9b80acb
C formatting fix
saulshanabrook 6ddb1e7
Rephrase test names
saulshanabrook 9d3f914
Rephrase comments
saulshanabrook 3e0a1e7
Make existing inline test clear
saulshanabrook 3420a42
Add a test for escaping behavior, but allow it to fail for now
saulshanabrook 6886b36
Verify that expected type version is non zero
saulshanabrook 376bb5e
Fix typo
saulshanabrook e025cc7
Assert pytype watch never errors
saulshanabrook 88f2d89
Fix assertion
saulshanabrook 82bc177
Remove unnecessary assert
saulshanabrook bdf0a4a
Handle if type versions are different
saulshanabrook File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix typo
- Loading branch information
commit 376bb5e75769f8441b172a9f85c427d3a4418642
There are no files selected for viewing
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Staring at this a bit harder, it seems like there are a couple of different cases that we want to distinguish:
Cases 1 and 2 should be impossible, and we can
assert(type_version)
above this line.Case 3 is what we're correctly handling in the
else
currently.Case 4 is what we're correctly handling in the
if
currently.Case 5 should result in narrowing
owner
to the "bottom" type, right? If so, this should probably happen insym_set_type_version
, which is called on line 127.@Fidget-Spinner or @markshannon, can you confirm that my understanding is correct here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for thinking through all of these. For case 5, I am unclear how/when this could happen. This would only occur if
_CHECK_TYPE_VERSION
was ommitted twice, the first time with one type version, and then the second time with a different type version as an arg, but for the same symbolic value.I am a little fuzzy on how these versions are generated. Are they captured based on the current type version of the type when it's generating the opcodes? If so, how could it be two different values?
If there is an example/test case here that would be helpful. Also is it possible to see in the test runner the additional args passed to each op, like the
type_version
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup the type version is the one at the time of specialization (bytecode rewriting). So if it just so happens that for example, a re-specialization is happening, the bytecode might have out of sync versions in their cache entries, leading to the scenario Brandt said in 5.
In general, we should hit the bottom if we're trying to set a type on something that is contradictory. E.g. if we're setting a type version on something that already has a type version. That is a contradiction. You can see an example test here
cpython/Python/optimizer_symbols.c
Line 484 in 82bc177
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. I changed it so that it would set it to bottom if they are different versions (and not add the watcher b/c it must have already been added then).
After this change, I wonder if the logic would be clearer if it was all just in this block instead of in the get/set helper functions.