Skip to content

Commit 53e52ab

Browse files
committed
SILGen: Fix invalid substitution map formation in coroutine witness thunk emission
If the conformance generic signature fixes all generic parameters, F.getForwardingSubstitutionMap() is empty. Instead, map the replacement types of the substitution map into the generic environment earlier, before we strip off a fully-concrete generic signature.
1 parent 4e17871 commit 53e52ab

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7230,8 +7230,7 @@ void SILGenFunction::emitProtocolWitness(
72307230
auto deallocCleanup = std::get<3>(tokenAndCleanups);
72317231

72327232
YieldInfo witnessYieldInfo(SGM, witness, witnessFTy, witnessSubs);
7233-
YieldInfo reqtYieldInfo(SGM, requirement, thunkTy,
7234-
reqtSubs.subst(getForwardingSubstitutionMap()));
7233+
YieldInfo reqtYieldInfo(SGM, requirement, thunkTy, reqtSubs);
72357234

72367235
translateYields(*this, loc, witnessYields, witnessYieldInfo, reqtYieldInfo);
72377236

lib/SILGen/SILGenType.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -752,13 +752,6 @@ SILFunction *SILGenModule::emitProtocolWitness(
752752
reqtOrigTy->substGenericArgs(reqtSubMap)
753753
->getReducedType(genericSig));
754754

755-
// Generic signatures where all parameters are concrete are lowered away
756-
// at the SILFunctionType level.
757-
if (genericSig && genericSig->areAllParamsConcrete()) {
758-
genericSig = nullptr;
759-
genericEnv = nullptr;
760-
}
761-
762755
// Rewrite the conformance in terms of the requirement environment's Self
763756
// type, which might have a different generic signature than the type
764757
// itself.
@@ -772,6 +765,16 @@ SILFunction *SILGenModule::emitProtocolWitness(
772765
auto self = requirement->getSelfInterfaceType()->getCanonicalType();
773766

774767
conformance = reqtSubMap.lookupConformance(self, requirement);
768+
769+
if (genericEnv)
770+
reqtSubMap = reqtSubMap.subst(genericEnv->getForwardingSubstitutionMap());
771+
}
772+
773+
// Generic signatures where all parameters are concrete are lowered away
774+
// at the SILFunctionType level.
775+
if (genericSig && genericSig->areAllParamsConcrete()) {
776+
genericSig = nullptr;
777+
genericEnv = nullptr;
775778
}
776779

777780
reqtSubstTy =

0 commit comments

Comments
 (0)