Skip to content

gh-150490: Raise PyType_Modified for insertion into split dictionary - #150489

Merged
DinoV merged 2 commits into
python:mainfrom
DinoV:sharedkeys_type
Jun 11, 2026
Merged

gh-150490: Raise PyType_Modified for insertion into split dictionary#150489
DinoV merged 2 commits into
python:mainfrom
DinoV:sharedkeys_type

Conversation

@DinoV

@DinoVDinoV commented May 26, 2026

Copy link
Copy Markdown
Contributor

When we insert into a split dictionary we update the shared keys version - this is used to invalidate caches for loading methods and loading class values and requires us to check the keys version. Instead we can raise PyType_Modified which lets us rely on the type version check + has inline values check instead of validating that we have the correct keys version. This gets rid of loading the cached keys version, the objects type (although likely the compiler eliminates this already), loading the cached keys from the type, and then loading the keys version and comparing it against the cached value.

@DinoVDinoV changed the title Raise PyType_Modified for insertion into split dictionarygh-150490: Raise PyType_Modified for insertion into split dictionaryMay 26, 2026
@DinoV
DinoVforce-pushed the sharedkeys_type branch 5 times, most recently from 226cf29 to 8406f6fCompareMay 26, 2026 20:17
@DinoV
DinoV marked this pull request as ready for review May 26, 2026 20:52

@markshannonmarkshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The change to the dict and removal of the keys version check seems good, but why have you removed several seemingly unrelated tests?

Comment threadInclude/internal/pycore_dict.h Outdated
Comment threadLib/test/test_capi/test_opt.py
Comment threadObjects/dictobject.c
}

static PyDictKeysObject*
new_keys_object(uint8_t log2_size, bool unicode)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not pass the kind directly, instead of a bool?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

It's not actually changed the diff is just doing a bad job of seeing that part of this was pulled into init_keys_object so it's showing this both deleted and added. But the callers tend to have. the bool value already in hand and new_keys_object seems to want to do a couple of truthy checks so I think it makes sense.

@markshannonmarkshannon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was hoping that #142889 would be implemented first, but it looks like progress there has stalled.

So, let's merge this.

@DinoV
DinoV merged commit efb2fff into python:mainJun 11, 2026
79 checks passed
@vstinner

Copy link
Copy Markdown
Member

This change introduced a regression: ./python -m test test_abc --parallel-threads=10 now hangs on Free Threading, see issue gh-151593.

philthompson10 pushed a commit to philthompson10/cpython that referenced this pull request Jun 17, 2026
…onary (python#150489)
Raise PyType_Modified for insertion into split dictionary
nascheme added a commit that referenced this pull request Jun 26, 2026
Revert commits:
gh-151593: Fix dead lock in PyDict insert_split_key() (#152200)
gh-150490: Raise PyType_Modified for insertion into split dictionary (#150489)
For gh-150489, it violates locking discipline and results in deadlocks,
gh-151593 is an example of it being hit in CI. The attempted fixgh-152200 avoids the deadlock but introduces a data-race. The race
window is small but can be triggered with pure Python code.
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@DinoV@vstinner@markshannon