Skip to content

[5.4] Introduce "all members" query to reduce non-determinism in serialization & interface printing #35540

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

Conversation

DougGregor
Copy link
Member

Eliminate some problematic sources of non-determinism involving the ordering of the members within an iterable declaration context. This pull request does a few things in that direction:

  • Mark more declarations (and more kinds of declarations) as "synthesized" when the compiler creates them, including (e.g.) properties (like hashValue), enums (like CodingKeys), and type aliases (inferred from associated types).
  • Rename "semantic members" query to "ABI members", because it is the set that is needed to make the ABI of a type (particularly classes) deterministic. This includes synthesized properties like hashValue.
  • Introduce an "all members" query based on the same infrastructure, which also includes synthesized types like enums and type aliases, as mentioned above. Use this for serialization and interface printing, to make those operations more deterministic.

The combination of the second and third bullets fixes rdar://63294687, a crash that occurs due to the synthesized hashValue property getting a different vtable slot in the defining module vs. a client module.

Cherry-pick of #35523

When evaluating the semantic members request, we would sort the members
before we return them to ensure a stable ordering for (e.g.) vtable
layout. However, when not in a source file, we would assume that the
resulting members were always sorted. However, they are not always
sorted, because we write the iterative decl contexts directly rather
than writing the semantic members.

Fixes rdar://72833032.

(cherry picked from commit 5426117)
(cherry picked from commit 3dc4c78)
The "semantic members" query produces the list of members that can
affect the ABI, e.g., of classes. It does not produce the complete
list of members suitable for semantic queries.

(cherry picked from commit a8f7f0d)
Introduce an "all members" request to compute all of the members of a
given iterable declaration context in stable order. This builds on ABI
members so that it will also include, e.g., type aliases synthesized
for associated types.

(cherry picked from commit c4e265e)
When serializing the members of a nominal type or extension, use
`getAllMembers()` instead of `getMembers()` to provide a deterministic
ordering.

Fixes rdar://63294687.

(cherry picked from commit ce12778)
Use getAllMembers() when printing members to get deterministic ordering.

(cherry picked from commit 85cd87a)
…uery.

The "synthesized" bit of declarations was never serialized, so sorting
deserialized declarations was already a no-op. Make it explicitly a
no-op to save some work. The fact that we serialize deterministically
is what actually fixed the problem here.

(cherry picked from commit 344747c)
@DougGregor DougGregor requested a review from a team as a code owner January 21, 2021 17:04
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit 9e9b4f5 into swiftlang:release/5.4 Jan 26, 2021
@DougGregor DougGregor deleted the all-members-determinism-5.4 branch January 26, 2021 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants