@@ -43,6 +43,13 @@ RequirementEnvironment::RequirementEnvironment(
4343 auto concreteType = conformanceDC->getSelfInterfaceType ();
4444 auto conformanceSig = conformanceDC->getGenericSignatureOfContext ();
4545
46+ auto conformanceToWitnessThunkGenericParamFn = [&](GenericTypeParamType *genericParam)
47+ -> GenericTypeParamType * {
48+ return GenericTypeParamType::get (genericParam->isParameterPack (),
49+ genericParam->getDepth () + (covariantSelf ? 1 : 0 ),
50+ genericParam->getIndex (), ctx);
51+ };
52+
4653 // This is a substitution function from the generic parameters of the
4754 // conforming type to the witness thunk environment.
4855 //
@@ -53,25 +60,20 @@ RequirementEnvironment::RequirementEnvironment(
5360 // This is a raw function rather than a substitution map because we need to
5461 // keep generic parameters as generic, even if the conformanceSig (the best
5562 // way to create the substitution map) equates them to concrete types.
56- auto conformanceToWitnessThunkTypeFn = [&](SubstitutableType *type) {
63+ auto conformanceToWitnessThunkTypeFn = [&](SubstitutableType *type) -> Type {
5764 auto *genericParam = cast<GenericTypeParamType>(type);
58- if (covariantSelf) {
59- return GenericTypeParamType::get (genericParam->isParameterPack (),
60- genericParam->getDepth () + 1 ,
61- genericParam->getIndex (), ctx);
62- }
65+ auto t = conformanceToWitnessThunkGenericParamFn (genericParam);
66+ if (t->isParameterPack ())
67+ return PackType::getSingletonPackExpansion (t);
6368
64- return GenericTypeParamType::get (genericParam->isParameterPack (),
65- genericParam->getDepth (),
66- genericParam->getIndex (), ctx);
69+ return t;
6770 };
6871 auto conformanceToWitnessThunkConformanceFn =
6972 MakeAbstractConformanceForGenericType ();
7073
7174 auto substConcreteType = concreteType.subst (
7275 conformanceToWitnessThunkTypeFn,
73- conformanceToWitnessThunkConformanceFn,
74- SubstFlags::PreservePackExpansionLevel);
76+ conformanceToWitnessThunkConformanceFn);
7577
7678 // Calculate the depth at which the requirement's generic parameters
7779 // appear in the witness thunk signature.
@@ -168,9 +170,8 @@ RequirementEnvironment::RequirementEnvironment(
168170 // Now, add all generic parameters from the conforming type.
169171 if (conformanceSig) {
170172 for (auto param : conformanceSig.getGenericParams ()) {
171- auto substParam = Type (param).subst (conformanceToWitnessThunkTypeFn,
172- conformanceToWitnessThunkConformanceFn);
173- genericParamTypes.push_back (substParam->castTo <GenericTypeParamType>());
173+ auto substParam = conformanceToWitnessThunkGenericParamFn (param);
174+ genericParamTypes.push_back (substParam);
174175 }
175176 }
176177
0 commit comments