Repository navigation
Conversation
…nstants makecode() merges the co_names and co_localsplusnames tuples with the constant cache, so they can become an equal tuple constant of another code object, and _PyCode_New() then interns the items of that tuple in place. If an equal string was already interned in the process, the string of the constant was replaced by it; otherwise the string of the constant itself became the interned one. The constants which are the same object, and so the marshal output, depended on the process state. The parser interns identifiers and the compiler interns the ASCII identifier-like string constants, so this needs a name which is not interned yet and is not an ASCII identifier: a private name of a class with a non-ASCII name, which each compilation mangles into a new string, or an identifier of an AST passed to compile() which was not created by the parser. Intern the names before the merge.
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.
The compiler merges the
co_namesand local variable names tuples of a code object with its constant cache, so they can be the same object as an equal tuple constant of an earlier function._PyCode_New()then interns the items of that shared tuple in place: if an equal string was already interned in the process, the constant's string is replaced by it, otherwise the constant's own string becomes the interned one. Which constants are the same object, and so the bytesmarshalwrites, depended on what was interned before. This change interns the names inmakecode()before the merge.It needs a name that is not interned yet and is not an ASCII identifier, since the parser interns identifiers and the compiler interns ASCII identifier-like string constants: a private name of a class with a non-ASCII name, which each compilation mangles into a new string, or an identifier of an AST passed to
compile()that the parser did not create.On main the two digests differ, and compiling the same source twice in one process also gives different bytes. The free-threaded build was not affected, because it interns all string constants.
Part of gh-129724.