@@ -43,6 +43,13 @@ RequirementEnvironment::RequirementEnvironment(
43
43
auto concreteType = conformanceDC->getSelfInterfaceType ();
44
44
auto conformanceSig = conformanceDC->getGenericSignatureOfContext ();
45
45
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
+
46
53
// This is a substitution function from the generic parameters of the
47
54
// conforming type to the witness thunk environment.
48
55
//
@@ -53,25 +60,20 @@ RequirementEnvironment::RequirementEnvironment(
53
60
// This is a raw function rather than a substitution map because we need to
54
61
// keep generic parameters as generic, even if the conformanceSig (the best
55
62
// way to create the substitution map) equates them to concrete types.
56
- auto conformanceToWitnessThunkTypeFn = [&](SubstitutableType *type) {
63
+ auto conformanceToWitnessThunkTypeFn = [&](SubstitutableType *type) -> Type {
57
64
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);
63
68
64
- return GenericTypeParamType::get (genericParam->isParameterPack (),
65
- genericParam->getDepth (),
66
- genericParam->getIndex (), ctx);
69
+ return t;
67
70
};
68
71
auto conformanceToWitnessThunkConformanceFn =
69
72
MakeAbstractConformanceForGenericType ();
70
73
71
74
auto substConcreteType = concreteType.subst (
72
75
conformanceToWitnessThunkTypeFn,
73
- conformanceToWitnessThunkConformanceFn,
74
- SubstFlags::PreservePackExpansionLevel);
76
+ conformanceToWitnessThunkConformanceFn);
75
77
76
78
// Calculate the depth at which the requirement's generic parameters
77
79
// appear in the witness thunk signature.
@@ -168,9 +170,8 @@ RequirementEnvironment::RequirementEnvironment(
168
170
// Now, add all generic parameters from the conforming type.
169
171
if (conformanceSig) {
170
172
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);
174
175
}
175
176
}
176
177
0 commit comments