Repository navigation
gh-162600: Don't specialize calls of abstract classes to CALL_ALLOC_AND_ENTER_INIT - #162883
Open
Robertboy18 wants to merge 1 commit into
Open
Robertboy18 wants to merge 1 commit into
Robertboy18 wants to merge 1 commit into
Conversation
…LLOC_AND_ENTER_INIT
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.
This fixes the case from #162600. A class with
__abstractmethods__set directly (withoutABCMeta) raisesTypeErroron the first call, but once the call site specializes toCALL_ALLOC_AND_ENTER_INITit gets instantiated, because that instruction allocates the object itself and never reaches the abstract check inobject_new().specialize_class_callnow skipsCALL_ALLOC_AND_ENTER_INITfor a class withPy_TPFLAGS_IS_ABSTRACT. The call site becomesCALL_NON_PY_GENERALinstead, which calls the class the normal way, soobject_new()raises. The flag is read after thetp_versionlookup, so a class that becomes abstract afterwards still invalidates the cached version. The check only runs when a call site specializes, soCALL_ALLOC_AND_ENTER_INITitself doesn't change. On the issue, picnixz asked for numbers on a PGO+LTO build (plain classes, dataclasses, pydantic models); I haven't run those yet and will post them here.The new test in
test_opcachecovers both orders: a class that's abstract before its call site specializes, and one made abstract afterwards, which then raises and isn't specialized toCALL_ALLOC_AND_ENTER_INITagain after the cooldown.I used AI tools to help write and review the patch, and checked it myself.
__abstractmethods__can be instantiated once its call is specialized toCALL_ALLOC_AND_ENTER_INIT#162600