-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[WIP] [Runtime] Use retroactive protocol conformances when demangling to metadata #20424
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
[WIP] [Runtime] Use retroactive protocol conformances when demangling to metadata #20424
Conversation
Thread a module name into the protocol conformance lookup function (e.g., the function implementing swift_conformsToProtocol), and compare that against the module context of retroactive conformances. When we don’t care where we find the resulting conformance (e.g., the module name is NULL), and more than one retroactive conformance found, produce a warning like this: ***Swift runtime warning: multiple conformances for 'RetroactiveCommon.CommonStruct: CommonP1' found in modules 'RetroactiveA' and 'RetroactiveB'. Arbitrarily selecting conformance from module 'RetroactiveA' This code will also be used to select specific conformances.
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.
…col. Our future clients will want to traffic in StringRef.
@swift-ci please test |
Build failed |
@swift-ci please test Linux |
Build failed |
…tadata Extend TypeDecoder with the ability to demangle (concrete) protocol conformances, and pass along demangled retroactive conformances to it’s builder’s createBoundGenericType(). Extend the mangled name -> metadata code in the runtime to use retroactive conformances when satisfying generic requirements. If a retroactive conformance is provided, the corresponding witness table will be used instead of the one found by swift_conformsToProtocol(). This allows us to properly demangle type names involving retroactive conformances.
…iptor. When we are looking for the specific type for a protocol conformance (e.g., because we may have a subclass of the type that declared conformances), don't go back through swift_conformsToProtocol() multiple times, which requires more lookups in the global conformance table. Instead, use the (known) protocol conformance descriptor.
Make the new runtime conformance collision warnings opt-it, via the environment variable SWIFT_ENABLE_CONFLICTING_CONFORMANCES_CHECK.
30606e2
to
3fa6084
Compare
@swift-ci please smoke test |
This PR is probably the wrong direction to go. The fifth commit already got merged; the second commit has been pulled out into #20491; and I think I'd prefer to stage in the conformance demangling more directly (e.g., via a compiler flag to enable it for associated conformances in witness tables) than this retroactive-conformances approach. |
Extend TypeDecoder with the ability to demangle (concrete) protocol
conformances, and pass along demangled retroactive conformances to
it’s builder’s createBoundGenericType().
Extend the mangled name -> metadata code in the runtime to use retroactive
conformances when satisfying generic requirements. If a retroactive
conformance is provided, the corresponding witness table will be used
instead of the one found by swift_conformsToProtocol(). This allows us to
properly demangle type names involving retroactive conformances.