Skip to content

[5.0] [Runtime] Cache and unique based on protocol conformance descriptors, not witness tables #20774

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

Conversation

DougGregor
Copy link
Member

The conformance cache was caching the witness table for a conformance
T: P, where T is a concrete type and P is a protocol. However, it
essentially picked one of potentially many witness tables for that
conformance, because retroactive conformances might produce different results
from different modules.

Make the conformance cache what is says it is: a cache of the conformance
descriptor for a given T: P. Clients of the conformance cache can choose how to interpret
the protocol conformance descriptor, e.g., by instantiating a witness table with a
particular set of arguments.

Moreover, unique metadata entries based on conformance descriptors, rather than witness tables.
This is both a correctness fix (when there are multiple, synthesized conformances in multiple modules)
and enables future optimizations (e.g., the use of pre-specialized witness tables).

The conformance cache was caching the witness table for a conformance
`T: P`, where `T` is a concrete type and `P` is a protocol. However, it
essentially picked one of potentially many witness tables for that
conformance, because retroactive conformances might produce different results
from different modules.

Make the conformance cache what is says it is: a cache of the conformance
descriptor for a given `T: P`, potentially filtered by a module (when
requested). Clients of the conformance cache can choose how to interpret
the protocol conformance descriptor, e.g., by instantiating a witness table.

We can bring back a specific conformance cache for swift_conformsToProtocol()
if it is profitable.

(cherry picked from commit 0af2af00a739a4d912d2a9c3b196449e4164484f)
(cherry picked from commit d9bb81b)
…metadata.

Metadata uniquing might encounter witness tables that were distinctly
generated but come from identical descriptors. Handle this case in metadata
uniquing be looking into the protocol conformance descriptors themselves.

(cherry picked from commit 32f577a)
Rather than scanning the type descriptor each time we perform a comparison
or hash of a metadata cache entry, do so only once to establish the number
of key parameters and the number of witness tables. Use those values to
more efficiently compare keys.

(cherry picked from commit 06807c2)
Rather than scanning through the generic parameters and generic requirements
each time we form a key for the generic metadata cache, compute these
values once, when the cache itself is first initialized.

(cherry picked from commit 3948114)
@DougGregor DougGregor requested a review from a team as a code owner November 26, 2018 21:21
@DougGregor
Copy link
Member Author

@swift-ci please test

Copy link
Contributor

@jckarter jckarter left a comment

Choose a reason for hiding this comment

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

Looks good.

Copy link
Contributor

@AnnaZaks AnnaZaks left a comment

Choose a reason for hiding this comment

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

Approved. However, this should wait for a week or so until we've converged.

@DougGregor DougGregor merged commit 2323904 into swiftlang:swift-5.0-branch Dec 4, 2018
@DougGregor DougGregor deleted the runtime-conformance-descriptor-cache-5.0 branch December 4, 2018 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants