Skip to content

Commit 38dfe29

Browse files
committed
SILGen: Remove selfType parameter from SILGenFunction::emitProtocolWitness()
1 parent 5bf63b2 commit 38dfe29

File tree

3 files changed

+25
-48
lines changed

3 files changed

+25
-48
lines changed

lib/SILGen/SILGenFunction.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
548548
///
549549
/// This is used for both concrete witness thunks and default witness
550550
/// thunks.
551-
void emitProtocolWitness(Type selfType,
552-
AbstractionPattern reqtOrigTy,
551+
void emitProtocolWitness(AbstractionPattern reqtOrigTy,
553552
CanAnyFunctionType reqtSubstTy,
554553
SILDeclRef requirement,
555554
SILDeclRef witness,

lib/SILGen/SILGenPoly.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3304,8 +3304,7 @@ static CanType dropLastElement(CanType type) {
33043304
return TupleType::get(elts, type->getASTContext())->getCanonicalType();
33053305
}
33063306

3307-
void SILGenFunction::emitProtocolWitness(Type selfType,
3308-
AbstractionPattern reqtOrigTy,
3307+
void SILGenFunction::emitProtocolWitness(AbstractionPattern reqtOrigTy,
33093308
CanAnyFunctionType reqtSubstTy,
33103309
SILDeclRef requirement,
33113310
SILDeclRef witness,
@@ -3325,12 +3324,6 @@ void SILGenFunction::emitProtocolWitness(Type selfType,
33253324
SmallVector<ManagedValue, 8> origParams;
33263325
collectThunkParams(loc, origParams);
33273326

3328-
// Handle special abstraction differences in "self".
3329-
// If the witness is a free function, drop it completely.
3330-
// WAY SPECULATIVE TODO: What if 'self' comprised multiple SIL-level params?
3331-
if (isFree)
3332-
origParams.pop_back();
3333-
33343327
// Get the type of the witness.
33353328
auto witnessInfo = getConstantInfo(witness);
33363329
CanAnyFunctionType witnessSubstTy = witnessInfo.LoweredType;
@@ -3349,6 +3342,7 @@ void SILGenFunction::emitProtocolWitness(Type selfType,
33493342
// For a free function witness, discard the 'self' parameter of the
33503343
// requirement.
33513344
if (isFree) {
3345+
origParams.pop_back();
33523346
reqtOrigInputTy = reqtOrigInputTy.dropLastTupleElement();
33533347
reqtSubstInputTy = dropLastElement(reqtSubstInputTy);
33543348
}

lib/SILGen/SILGenType.cpp

Lines changed: 22 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -609,24 +609,6 @@ SILGenModule::getWitnessTable(ProtocolConformance *conformance) {
609609
return table;
610610
}
611611

612-
static bool maybeOpenCodeProtocolWitness(
613-
SILGenFunction &SGF, ProtocolConformanceRef conformance, SILLinkage linkage,
614-
Type selfInterfaceType, Type selfType, GenericEnvironment *genericEnv,
615-
SILDeclRef requirement, SILDeclRef witness, SubstitutionList witnessSubs) {
616-
if (auto witnessFn = dyn_cast<FuncDecl>(witness.getDecl())) {
617-
if (witnessFn->getAccessorKind() == AccessorKind::IsMaterializeForSet) {
618-
auto reqFn = cast<FuncDecl>(requirement.getDecl());
619-
assert(reqFn->getAccessorKind() == AccessorKind::IsMaterializeForSet);
620-
return SGF.maybeEmitMaterializeForSetThunk(conformance, linkage,
621-
selfInterfaceType, selfType,
622-
genericEnv, reqFn, witnessFn,
623-
witnessSubs);
624-
}
625-
}
626-
627-
return false;
628-
}
629-
630612
SILFunction *SILGenModule::emitProtocolWitness(
631613
ProtocolConformanceRef conformance, SILLinkage linkage,
632614
IsSerialized_t isSerialized, SILDeclRef requirement, SILDeclRef witnessRef,
@@ -695,34 +677,36 @@ SILFunction *SILGenModule::emitProtocolWitness(
695677
PrettyStackTraceSILFunction trace("generating protocol witness thunk", f);
696678

697679
// Create the witness.
698-
Type selfInterfaceType;
699-
Type selfType;
700-
701-
// If the witness is a free function, there is no Self type.
702-
if (!isFree) {
703-
auto *proto = cast<ProtocolDecl>(requirement.getDecl()->getDeclContext());
704-
selfInterfaceType = proto->getSelfInterfaceType().subst(reqtSubMap);
705-
selfType = GenericEnvironment::mapTypeIntoContext(
706-
genericEnv, selfInterfaceType);
707-
}
708-
709680
SILGenFunction SGF(*this, *f);
710681

711682
// Substitutions mapping the generic parameters of the witness to
712683
// archetypes of the witness thunk generic environment.
713684
auto witnessSubs = witness.getSubstitutions();
714685

715-
// Open-code certain protocol witness "thunks".
716-
if (maybeOpenCodeProtocolWitness(SGF, conformance, linkage,
717-
selfInterfaceType, selfType, genericEnv,
718-
requirement, witnessRef, witnessSubs)) {
719-
assert(!isFree);
720-
return f;
686+
// Open-code protocol witness thunks for materializeForSet.
687+
if (auto witnessFn = dyn_cast<FuncDecl>(witnessRef.getDecl())) {
688+
if (witnessFn->getAccessorKind() == AccessorKind::IsMaterializeForSet) {
689+
assert(!isFree);
690+
691+
auto *proto = cast<ProtocolDecl>(requirement.getDecl()->getDeclContext());
692+
auto selfInterfaceType = proto->getSelfInterfaceType().subst(reqtSubMap);
693+
auto selfType = GenericEnvironment::mapTypeIntoContext(
694+
genericEnv, selfInterfaceType);
695+
696+
auto reqFn = cast<FuncDecl>(requirement.getDecl());
697+
assert(reqFn->getAccessorKind() == AccessorKind::IsMaterializeForSet);
698+
699+
if (SGF.maybeEmitMaterializeForSetThunk(conformance, linkage,
700+
selfInterfaceType, selfType,
701+
genericEnv, reqFn, witnessFn,
702+
witnessSubs))
703+
return f;
704+
705+
// Proceed down the normal path.
706+
}
721707
}
722708

723-
SGF.emitProtocolWitness(selfType,
724-
AbstractionPattern(reqtOrigTy),
725-
reqtSubstTy,
709+
SGF.emitProtocolWitness(AbstractionPattern(reqtOrigTy), reqtSubstTy,
726710
requirement, witnessRef,
727711
witnessSubs, isFree);
728712

0 commit comments

Comments
 (0)