gh-103571: Add runtime-global strings to the initial per-interpreter interned_dict #103572
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.
bpo-46430 caused an interesting side effect; the code
x = 'a'; x[0] is x
no longer returned True. This in turn is because there are two different cached versions of 'a':However, some characters do not have this behaviour (for example, 'g', 'u', and 'z'). I suspect it because these characters are not used in co_consts of frozen modules.
The interned_dict is per interpreter, and is initialized by
init_interned_dict(PyInterpreterState *)
. The prior implementation initialize it to an empty dict, which allows code in frozen modules to use their (different and per interpreter) singleton strings instead of the runtime-global one.The new implementation add all runtime-global singleton strings to the interned_dict when it initialized, causing the frozen modules to use the same immortal singleton string and for
x = 'a'; x[0] is x
to return True.