Skip to content

Commit 86fef48

Browse files
authored
Merge pull request #15784 from slavapestov/concrete-witness-method-fix
Preliminary "opaque conformance" support in SIL
2 parents a4b91d2 + 7147d35 commit 86fef48

File tree

4 files changed

+16
-34
lines changed

4 files changed

+16
-34
lines changed

lib/IRGen/GenArchetype.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -173,19 +173,6 @@ llvm::Value *irgen::emitArchetypeWitnessTableRef(IRGenFunction &IGF,
173173
auto wtable = IGF.tryGetLocalTypeData(archetype, localDataKind);
174174
if (wtable) return wtable;
175175

176-
// It can happen with class constraints that Sema will consider a
177-
// constraint to be abstract, but the minimized signature will
178-
// eliminate it as concrete. Handle this by performing a concrete
179-
// lookup.
180-
// TODO: maybe Sema shouldn't ever do this?
181-
if (Type classBound = archetype->getSuperclass()) {
182-
auto conformance =
183-
IGF.IGM.getSwiftModule()->lookupConformance(classBound, protocol);
184-
if (conformance && conformance->isConcrete()) {
185-
return emitWitnessTableRef(IGF, archetype, *conformance);
186-
}
187-
}
188-
189176
// If we don't have an environment, this must be an implied witness table
190177
// reference.
191178
// FIXME: eliminate this path when opened types have generic environments.

lib/ParseSIL/ParseSIL.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4084,17 +4084,13 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
40844084
P.diagnose(TyLoc, diag::sil_witness_method_not_protocol);
40854085
return true;
40864086
}
4087-
ProtocolConformanceRef Conformance(proto);
4088-
if (!isa<ArchetypeType>(LookupTy)) {
4089-
auto lookup = P.SF.getParentModule()->lookupConformance(LookupTy, proto);
4090-
if (!lookup) {
4091-
P.diagnose(TyLoc, diag::sil_witness_method_type_does_not_conform);
4092-
return true;
4093-
}
4094-
Conformance = ProtocolConformanceRef(*lookup);
4087+
auto conformance = P.SF.getParentModule()->lookupConformance(LookupTy, proto);
4088+
if (!conformance) {
4089+
P.diagnose(TyLoc, diag::sil_witness_method_type_does_not_conform);
4090+
return true;
40954091
}
4096-
4097-
ResultVal = B.createWitnessMethod(InstLoc, LookupTy, Conformance, Member,
4092+
4093+
ResultVal = B.createWitnessMethod(InstLoc, LookupTy, *conformance, Member,
40984094
MethodTy);
40994095
break;
41004096
}

lib/SIL/SILVerifier.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,10 +2396,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
23962396
require(AMI->getTypeDependentOperands().empty(),
23972397
"Should not have an operand for the opened existential");
23982398
}
2399-
if (isa<ArchetypeType>(lookupType) || lookupType->isAnyExistentialType()) {
2400-
require(AMI->getConformance().isAbstract(),
2401-
"archetype or existential lookup should have abstract conformance");
2402-
} else {
2399+
if (!isa<ArchetypeType>(lookupType)) {
24032400
require(AMI->getConformance().isConcrete(),
24042401
"concrete type lookup requires concrete conformance");
24052402
auto conformance = AMI->getConformance().getConcrete();

lib/SILGen/SILGenApply.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -590,18 +590,20 @@ class Callee {
590590
case Kind::WitnessMethod: {
591591
auto constantInfo = SGF.getConstantInfo(*constant);
592592

593-
auto proto = cast<ProtocolDecl>(
594-
Constant.getDecl()->getDeclContext());
595-
auto lookupType = getSubstFormalType()
596-
.getInput()
597-
->getRValueInstanceType()
598-
->getCanonicalType();
593+
auto proto = cast<ProtocolDecl>(Constant.getDecl()->getDeclContext());
594+
auto genericSig = cast<AbstractFunctionDecl>(Constant.getDecl())
595+
->getGenericSignature();
596+
auto subMap = genericSig->getSubstitutionMap(Substitutions);
597+
auto selfType = proto->getSelfInterfaceType()->getCanonicalType();
598+
auto lookupType = selfType.subst(subMap)->getCanonicalType();
599+
auto conformance = *subMap.lookupConformance(selfType, proto);
599600

600601
SILValue fn;
601602

602603
if (!constant->isForeign) {
604+
603605
fn = SGF.B.createWitnessMethod(
604-
Loc, lookupType, ProtocolConformanceRef(proto), *constant,
606+
Loc, lookupType, conformance, *constant,
605607
constantInfo.getSILType());
606608
} else {
607609
fn = SGF.B.createObjCMethod(Loc, borrowedSelf->getValue(),

0 commit comments

Comments
 (0)