Repository navigation
Conversation
make_frozenset() assumed that the set built for frozenset() of a set display or comprehension is uniquely referenced and froze it in place. A trace function or pdb can still hold the set returned by a comprehension that is not inlined, such as one in a class annotation. Copy the set in that case.
Comment on lines
+215
to
+217
| if (!_PyObject_IsUniquelyReferenced(set)) { | ||
| return PyFrozenSet_New(set); | ||
| } |
Member
There was a problem hiding this comment.
The whole point of this intrinsic is that we assume the incoming set is uniquely referenced (though the naming is kind of bad). I think we should disable the optimization in the annotations path, not add extra cost to every instance of frozenset({...}).
…lined Instead of copying a shared set in make_frozenset(), don't use the frozenset() fast path for a set comprehension that is not inlined. Only such a comprehension returns its set from a call, where a trace function can keep it, so make_frozenset() keeps its assumption that the set is uniquely referenced and other uses pay for no extra check.
ZeroIntensity
left a comment
Member
There was a problem hiding this comment.
The crux of the fix looks good, but while we're here, can you rename that intrinsic to something like FREEZE_SET?
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.
frozenset()of a set comprehension froze the comprehension's set in place, but a comprehension that is not inlined, such as one in a class annotation, returns its set from a call, where a trace function or pdb can keep it. The compiler now uses the fast path only for comprehensions that are inlined.frozenset({...})freezes a set that is still referenced #158490