[mypyc] Clear only subtype refs in tp_dealloc of built-in subtypes - #21872
Merged
p-sawicki merged 1 commit intoAug 19, 2026
Merged
Conversation
JukkaL
approved these changes
Aug 19, 2026
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.
Fixes #21859
Deallocating an instance of a class that inherits from a built-in type might fail an assertion because when we clear references during the deallocation, we call the generated
tp_clearfunction that in turn callstp_clearof the base class.The functions put in the
tp_clearslot of built-in types require that the instance is still alive (references > 0) which is not the case during deallocation.To avoid this, split the
tp_clearfunction for types with built-in bases into two: first (subtype_clear) clears only the references owned by the subtype, second (clear) does the same plus calls base typetp_clear.clearis put into thetp_clearslot whilesubtype_clearcan be called fromtp_dealloc.tp_deallocalso calls base typetp_deallocwhich clears the references owned by the base type, so the base typetp_clearcall was not necessary.For classes without a builtin base we continue to clear all their references in a single function.