Skip to content

[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

Conversation

DougGregor
Copy link
Member

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.

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.
@DougGregor
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Nov 8, 2018

Build failed
Swift Test Linux Platform
Git Sha - 30606e2fe000ba0815513e0f4ee0494437beeeb1

@DougGregor
Copy link
Member Author

@swift-ci please test Linux

@swift-ci
Copy link
Contributor

swift-ci commented Nov 8, 2018

Build failed
Swift Test Linux Platform
Git Sha - 30606e2fe000ba0815513e0f4ee0494437beeeb1

…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.
@DougGregor DougGregor force-pushed the retroactive-conformance-to-metadata branch from 30606e2 to 3fa6084 Compare November 8, 2018 18:10
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

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.

@shahmishal
Copy link
Member

Please update the base branch to main by Oct 5th otherwise the pull request will be closed automatically.

  • How to change the base branch: (Link)
  • More detail about the branch update: (Link)

@shahmishal shahmishal closed this Oct 5, 2020
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.

3 participants