Skip to content

Restore _GUARD_KEYS_VERSION in LOAD_ATTR specializations - #130

Open
ddorian wants to merge 3 commits into
facebookincubator:mainfrom
ddorian:fix-load-attr-keys-version
Open

Restore _GUARD_KEYS_VERSION in LOAD_ATTR specializations#130
ddorian wants to merge 3 commits into
facebookincubator:mainfrom
ddorian:fix-load-attr-keys-version

Conversation

@ddorian

@ddorian ddorian commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

partial fix for #115

The 3.14 and 3.15 interpreters were missing the shared-keys version
check in LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES and
LOAD_ATTR_METHOD_WITH_VALUES, so a warmed load site kept returning the
cached class attribute after an instance stored the attribute through
the type's shared keys. This is what breaks SQLAlchemy's deferred
column loads in facebookincubatorgh-115.

The restored blocks match what CPython's case generator emits for
these opcodes on 3.14, and the cache entry they read is already
populated: specialize_attr_loadclassattr writes the keys version
whenever META_PYTHON is not defined.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Jul 10, 2026
)


class LoadAttrKeysVersionTests(unittest.TestCase):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same feedback as #129, put this in test_jit_specialization.py and drop the cinderx.init().

@DinoV

DinoV commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Oh, this is interesting, and is going to need some changes to how we build things internally too. We end up generating the generated_cases.c.h from Meta Python 3.14 https://github.com/facebookincubator/cinder/tree/meta/3.14 where we've backported the upstream support for not needing the guards keys version. In addition to the backout here we'll need to update our internal syncing scripts too.

Or maybe what's easier would be to update cinder-bytecodes.c to have the _GUARD_KEYS_VERSION inlined into the opcode and if it ifdef'd under META_PYTHON.

@DinoV

DinoV commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Oh, this is interesting, and is going to need some changes to how we build things internally too. We end up generating the generated_cases.c.h from Meta Python 3.14 https://github.com/facebookincubator/cinder/tree/meta/3.14 where we've backported the upstream support for not needing the guards keys version. In addition to the backout here we'll need to update our internal syncing scripts too.

Or maybe what's easier would be to update cinder-bytecodes.c to have the _GUARD_KEYS_VERSION inlined into the opcode and if it ifdef'd under META_PYTHON.

@ddorian If you'd like to land the full fix for it I think we just need to add:

        op(_GUARD_KEYS_VERSION, (keys_version/2, owner -- owner)) {
#ifndef META_PYTHON
            PyTypeObject *owner_cls = Py_TYPE(PyStackRef_AsPyObjectBorrow(owner));
            PyHeapTypeObject *owner_heap_type = (PyHeapTypeObject *)owner_cls;
            PyDictKeysObject *keys = owner_heap_type->ht_cached_keys;
            DEOPT_IF(FT_ATOMIC_LOAD_UINT32_RELAXED(keys->dk_version) != keys_version);
#endif
        }

        // Added for compatibility w/ non meta Python where we need to do _GUARD_KEYS_VERSION still
        macro(LOAD_ATTR_METHOD_WITH_VALUES) =
            unused/1 +
            _GUARD_TYPE_VERSION +
            _GUARD_DORV_VALUES_INST_ATTR_FROM_DICT +
            _GUARD_KEYS_VERSION +
            _LOAD_ATTR_METHOD_WITH_VALUES;

``` into cinderx/Interpreter/3.14/cinder-bytecodes.c and the equivalent version for 3.15 and then your `_GUARD_KEYS_VERSION` in the generated_cases file would get the same ifndef as well. Or we can land the fix to the bytecodes internally and just land this w/ the tests.

@ddorian

ddorian commented Jul 15, 2026

Copy link
Copy Markdown
Contributor Author

@DinoV

Oh, this is interesting, and is going to need some changes to how we build things internally too. We end up generating the generated_cases.c.h from Meta Python 3.14 https://github.com/facebookincubator/cinder/tree/meta/3.14 where we've backported the upstream support for not needing the guards keys version. In addition to the backout here we'll need to update our internal syncing scripts too.

Can you do the syncing and I rebase on top of it?

ddorian added 2 commits July 22, 2026 13:03
Meta Python invalidates the type version when shared keys change, so _GUARD_TYPE_VERSION covers it there; check dk_version under #ifndef META_PYTHON. Move the regression tests into test_jit_specialization.py.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants