Skip to content

Preliminary "opaque conformance" support in SIL #15784

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions lib/IRGen/GenArchetype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,6 @@ llvm::Value *irgen::emitArchetypeWitnessTableRef(IRGenFunction &IGF,
auto wtable = IGF.tryGetLocalTypeData(archetype, localDataKind);
if (wtable) return wtable;

// It can happen with class constraints that Sema will consider a
// constraint to be abstract, but the minimized signature will
// eliminate it as concrete. Handle this by performing a concrete
// lookup.
// TODO: maybe Sema shouldn't ever do this?
if (Type classBound = archetype->getSuperclass()) {
auto conformance =
IGF.IGM.getSwiftModule()->lookupConformance(classBound, protocol);
if (conformance && conformance->isConcrete()) {
return emitWitnessTableRef(IGF, archetype, *conformance);
}
}

// If we don't have an environment, this must be an implied witness table
// reference.
// FIXME: eliminate this path when opened types have generic environments.
Expand Down
16 changes: 6 additions & 10 deletions lib/ParseSIL/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4084,17 +4084,13 @@ bool SILParser::parseSILInstruction(SILBuilder &B) {
P.diagnose(TyLoc, diag::sil_witness_method_not_protocol);
return true;
}
ProtocolConformanceRef Conformance(proto);
if (!isa<ArchetypeType>(LookupTy)) {
auto lookup = P.SF.getParentModule()->lookupConformance(LookupTy, proto);
if (!lookup) {
P.diagnose(TyLoc, diag::sil_witness_method_type_does_not_conform);
return true;
}
Conformance = ProtocolConformanceRef(*lookup);
auto conformance = P.SF.getParentModule()->lookupConformance(LookupTy, proto);
if (!conformance) {
P.diagnose(TyLoc, diag::sil_witness_method_type_does_not_conform);
return true;
}
ResultVal = B.createWitnessMethod(InstLoc, LookupTy, Conformance, Member,

ResultVal = B.createWitnessMethod(InstLoc, LookupTy, *conformance, Member,
MethodTy);
break;
}
Expand Down
5 changes: 1 addition & 4 deletions lib/SIL/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2396,10 +2396,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
require(AMI->getTypeDependentOperands().empty(),
"Should not have an operand for the opened existential");
}
if (isa<ArchetypeType>(lookupType) || lookupType->isAnyExistentialType()) {
require(AMI->getConformance().isAbstract(),
"archetype or existential lookup should have abstract conformance");
} else {
if (!isa<ArchetypeType>(lookupType)) {
require(AMI->getConformance().isConcrete(),
"concrete type lookup requires concrete conformance");
auto conformance = AMI->getConformance().getConcrete();
Expand Down
16 changes: 9 additions & 7 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -590,18 +590,20 @@ class Callee {
case Kind::WitnessMethod: {
auto constantInfo = SGF.getConstantInfo(*constant);

auto proto = cast<ProtocolDecl>(
Constant.getDecl()->getDeclContext());
auto lookupType = getSubstFormalType()
.getInput()
->getRValueInstanceType()
->getCanonicalType();
auto proto = cast<ProtocolDecl>(Constant.getDecl()->getDeclContext());
auto genericSig = cast<AbstractFunctionDecl>(Constant.getDecl())
->getGenericSignature();
auto subMap = genericSig->getSubstitutionMap(Substitutions);
auto selfType = proto->getSelfInterfaceType()->getCanonicalType();
auto lookupType = selfType.subst(subMap)->getCanonicalType();
auto conformance = *subMap.lookupConformance(selfType, proto);

SILValue fn;

if (!constant->isForeign) {

fn = SGF.B.createWitnessMethod(
Loc, lookupType, ProtocolConformanceRef(proto), *constant,
Loc, lookupType, conformance, *constant,
constantInfo.getSILType());
} else {
fn = SGF.B.createObjCMethod(Loc, borrowedSelf->getValue(),
Expand Down