Teach the generic specializer how to create SILWitnessTable declarations if a specialized conformance does not have a witness table.

This also teaches IRGen not to emit WitnessTable declarations. This
causes them to be left as unknown symbols in the resulting executable.

Swift SVN r15361
This commit is contained in:
Michael Gottesman
2014-03-22 05:05:47 +00:00
parent 084d468236
commit 3ad6f33202
9 changed files with 115 additions and 0 deletions

View File

@@ -93,6 +93,38 @@ SILModule::~SILModule() {
delete (SILTypeListUniquingType*)TypeListUniquing;
}
SILWitnessTable *
SILModule::createWitnessTableDeclaration(ProtocolConformance *C) {
// Walk down to the base NormalProtocolConformance.
ProtocolConformance *ParentC = C;
ArrayRef<Substitution> Subs;
while (!isa<NormalProtocolConformance>(ParentC)) {
switch (ParentC->getKind()) {
case ProtocolConformanceKind::Normal:
llvm_unreachable("should have exited the loop?!");
case ProtocolConformanceKind::Inherited:
ParentC = cast<InheritedProtocolConformance>(ParentC)
->getInheritedConformance();
break;
case ProtocolConformanceKind::Specialized: {
auto SC = cast<SpecializedProtocolConformance>(ParentC);
ParentC = SC->getGenericConformance();
assert(Subs.empty() && "multiple conformance specializations?!");
Subs = SC->getGenericSubstitutions();
break;
}
}
}
NormalProtocolConformance *NormalC
= cast<NormalProtocolConformance>(ParentC);
SILWitnessTable *WT = SILWitnessTable::create(*this,
SILLinkage::PublicExternal,
NormalC);
WitnessTableLookupCache[NormalC] = WT;
return WT;
}
std::pair<SILWitnessTable *, ArrayRef<Substitution>>
SILModule::lookUpWitnessTable(const ProtocolConformance *C) {
// Walk down to the base NormalProtocolConformance.
@@ -143,6 +175,7 @@ SILModule::lookUpWitnessTable(const ProtocolConformance *C) {
return {nullptr, Subs};
}
SILFunction *SILModule::getOrCreateSharedFunction(SILLocation loc,
StringRef name,
CanSILFunctionType type,