Skip to content

🌸[NFC] [PrintAsClang] Add tiebreaking rule to sort #74643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 25, 2024

Conversation

beccadax
Copy link
Contributor

  • Explanation: Adds additional sort rules to PrintAsClang to eliminate nondeterministic behavior in generated headers.
  • Scope: Affects projects using generated headers (-Swift.h headers) in both ObjC and C++ modes. Should only cause different behavior in edge cases where two declarations would previously have been printed in an arbitrary order.
  • Issue: rdar://129485103
  • Original PR: [NFC] [PrintAsClang] Add tiebreaking rule to sort #74597
  • Risk: Low. The new rules mean that the compiler will now process declarations in a consistent order when it would otherwise have processed them in an arbitrary order. The logic that ensures types are declared before they're used has not been changed, so this should make no semantic difference—it just helps ensure consistency.
  • Testing: Includes new unit tests.
  • Reviewer: @tshortli and @nkcsgexi

Because the underlying API for fetching top-level decls returns them in an unspecified order, PrintAsClang sorts the decls before printing them to make the output order more stable. However, the rules currently implemented have at least one known defect (they compare only the unqualified name of a nested class, so two nested classes with the same Swift name sort in an arbitrary order), and there are likely many more.

Add a fallback rule which sorts declarations by their mangled name; this should at least distinguish all non-colliding ValueDecls from each other, albeit according to fairly opaque criteria. Additionally add a rule to help distinguish extensions with very similar content, and tweak other logic so that the comparison function is less likely to give up early rather than continuing to look for a usable difference.

Fixes rdar://129485103.
@beccadax beccadax requested a review from a team as a code owner June 22, 2024 08:49
@beccadax
Copy link
Contributor Author

@swift-ci please test

@beccadax beccadax changed the title [NFC] [PrintAsClang] Add tiebreaking rule to sort 🌸[NFC] [PrintAsClang] Add tiebreaking rule to sort Jun 24, 2024
@beccadax beccadax added the 🍒 release cherry pick Flag: Release branch cherry picks label Jun 24, 2024
@beccadax beccadax merged commit 6c74cce into swiftlang:release/6.0 Jun 25, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants