[ClangImporter] Import C++ subscript overloads in stable order#89478
Open
airspeedswift wants to merge 1 commit into
Open
[ClangImporter] Import C++ subscript overloads in stable order#89478airspeedswift wants to merge 1 commit into
airspeedswift wants to merge 1 commit into
Conversation
`lookupAndImportSubscripts` grouped operator[] overloads in a SmallDenseMap keyed by CXXOverloadArgTypes, whose hash is built from clang::QualType opaque pointers. ASLR makes those pointer values vary across runs, so iteration order over the map varies too — and that order determined the order of subscripts added to the imported Swift struct. Downstream, that fed the constraint solver's overload set in varying order; for cases with multiple equally-ranked viable candidates, *which one wins* could change run-to-run. Switch to SmallMapVector so iteration follows insertion order. The hash-keyed lookup that groups same-arg-type getters/setters is preserved; only iteration becomes deterministic. Concrete repro: typechecking test/Interop/Cxx/operators/subscript-overloads-typechecker.swift 20 times produced 3 distinct outputs before this change and 1 afterwards.
Member
Author
|
@swift-ci please smoke test |
j-hui
approved these changes
May 27, 2026
Contributor
j-hui
left a comment
There was a problem hiding this comment.
Oof, thanks for catching this!
Out of curiosity, how did this manifest elsewhere/outside of that test?
Member
Author
|
I was trying to fix diagnostics like this and the tests for the fix were failing because the results varied run to run. That would mean if there were multiple diagnostics, the order would change (including the top one Xcode shows) unless we sorted them. |
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.
lookupAndImportSubscriptsgrouped operator[] overloads in a SmallDenseMap keyed by CXXOverloadArgTypes, whose hash is built from clang::QualType opaque pointers. ASLR makes those pointer values vary across runs, so iteration order over the map varies too — and that order determined the order of subscripts added to the imported Swift struct. Downstream, that fed the constraint solver's overload set in varying order; for cases with multiple equally-ranked viable candidates, which one wins could change run-to-run.Switch to SmallMapVector so iteration follows insertion order. The hash-keyed lookup that groups same-arg-type getters/setters is preserved; only iteration becomes deterministic.
Concrete repro: typechecking
test/Interop/Cxx/operators/subscript-overloads-typechecker.swift 20 times produced 3 distinct outputs before this change and 1 afterwards.