Repository navigation
Conversation
…uilds Without separate compilation, find_attr_initializers collected the defaults of every class in the MRO, so a subclass that overrides a base default got two initializer stores in __mypyc_defaults_setup. An initializer store doesn't release the previous value, so the base default leaked once per instance. Keep only the last default per name.
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.
Part of #22446.
Without separate compilation,
find_attr_initializerswould collect the defaults for all classes in the MRO. If a subclass overrode a base default,__mypyc_defaults_setupwould store both: the base value, then its own. As an initializer store does not release the previous value, this would cause the base default to leak (once per instance). With this change there is only one entry per name, for the last default. Default values from a base class that have been overridden are no longer evaluated at all. When using theleakmod.pyfrom the issue (built bymypyc leakmod.pyon Linux with CPython 3.13.16),measure.pynow prints 0.0 B for all four classes. At commit 0952029,OverridesandOverridesWithInitprint 56.0 B.When
separate=True, overriding an inherited default will still cause a leak. This is because the subclass's setup method calls the base class's setup method, causing the base default to be stored first. To resolve this we need to know the base class's defaults while building the subclass. However, separate compilation doesn't have them before the IR is built. I left this for a follow-up, and the issue remains open.The new test
testDefaultVarsOverriddenInSubclassfails on master. This is becauseB.__mypyc_defaults_setupstoresxtwice there.