Skip to content

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

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 9 commits into from
Jan 21, 2021

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.

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.
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.
When serializing the members of a nominal type or extension, use
`getAllMembers()` instead of `getMembers()` to provide a deterministic
ordering.

Fixes rdar://63294687.
Use getAllMembers() when printing members to get deterministic ordering.
…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.
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for fixing the non-deterministic issue of module interface printing!

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