Runtime: Do awful things to implement "swift_conformsToProtocol" for Swift protocols.

Given our constraints for 1.0, we can actually sort-of look up protocol conformances just by dlsym'ing the symbol for their protocol witness table, since we won't be implementing runtime witness table instantiation or private conformances anytime soon. To make this work for generic types, distastefully regress our mangling for protocol conformances by assuming all generic conformances are completely general to the unbound generic type and leave the generic parameters out of the mangling.

Swift SVN r13901
This commit is contained in:
Joe Groff
2014-02-14 05:15:32 +00:00
parent 36cc5ab4fa
commit 802df0bdf3
3 changed files with 115 additions and 4 deletions

View File

@@ -1247,17 +1247,26 @@ void Mangler::mangleProtocolConformance(ProtocolConformance *conformance) {
// protocol-conformance ::= ('U' generic-parameter+ '_')?
// type protocol module
// FIXME: explosion level?
CanType type = conformance->getType()->getCanonicalType();
// FIXME: Assume that all generic conformances add no additional constraints
// to the conforming type's generic parameters and swallow them. This makes
// it easier for our hacked-up implementation of swift_conformsToProtocol
// to find them.
if (conformance->getGenericParams())
type = UnboundGenericType::get(type->getNominalOrBoundGenericNominal(),
nullptr,
type->getASTContext())->getCanonicalType();
#if 0
ContextStack context(*this);
// If the conformance is generic, mangle its generic parameters.
if (auto gp = conformance->getGenericParams()) {
Buffer << 'U';
bindGenericParameters(gp, /*mangle*/ true);
}
#endif
mangleType(conformance->getType()->getCanonicalType(),
ResilienceExpansion::Minimal, 0);
mangleType(type, ResilienceExpansion::Minimal, 0);
mangleProtocolName(conformance->getProtocol());
mangleModule(conformance->getDeclContext()->getParentModule());
}