GeezerVison is showing github.com — gh-127773: Disable attribute cache on incompatible MRO entries by encukou · Pull Request #127924 · python/cpython
Conversation
encukou
commented
Dec 13, 2024
•
edited by bedevere-app
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
This brings back the functionality of Py_TPFLAGS_HAVE_VERSION_TAG, which should have been named “use version tag”, as the field itself is always present -- see #27260 where I mistakenly removed it.
The type attribute cache relies on a class being able to invalidate caches of all of its subclasses. If a type's MRO contains an entry that's not that type's base, the cache needs to be disabled.
This requires a single bit, which was in tp_flags in 3.9 and below.
I'd like to avoid using tp_flags for an internal flag (even one that's currently reserved for ABI compatibility).
We already have a mechanism for disabling the cache: it's disabled after 1000 modifications to a single type, using tp_versions_used as a counter. It would be possible to set this to 1000 (MAX_VERSIONS_PER_CLASS) when an incompatible MRO is found. To make the code & logic more understandable, this PR uses a new bigger constant, _Py_ATTR_CACHE_UNUSED. The existing tp_versions_used check is reused.
If the tp_versions_used mechanism is dropped in the future, _Py_ATTR_CACHE_UNUSED can become a single bit stored elsewhere in PyTypeObject. Ideally in a private (underscore-prefixed) field; not in tp_flags.
@markshannon @colesbury Does this sound right? I'm not much of an attribute cache expert and I don't know about future plans in this area.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
This makes sense to me, but @markshannon is probably more familiar with the MRO cache and tp_versions_used.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
We define `static_assert` in `pymacro.h`.
|
🤖 New build scheduled with the buildbot fleet by @encukou for commit 5dbbdf4 🤖
If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
The issues on failed buildbots are unrelated (the ctypes one on RHEL8 is fixed in #128034).
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
If there are no objections, I'll merge this next week.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
Eclips4
Eclips4 left review comments
markshannon
Awaiting requested review from markshannon
markshannon is a code owner
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|