@@ -168,9 +168,28 @@ SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
168
168
SubstitutionMap SubstitutionMap::get (GenericSignature genericSig,
169
169
ArrayRef<Type> types,
170
170
LookupConformanceFn lookupConformance) {
171
- return get (genericSig,
172
- QueryReplacementTypeArray{genericSig, types},
173
- lookupConformance);
171
+ QueryReplacementTypeArray subs{genericSig, types};
172
+ InFlightSubstitution IFS (subs, lookupConformance, std::nullopt);
173
+ return get (genericSig, types, IFS);
174
+ }
175
+
176
+ SubstitutionMap SubstitutionMap::get (GenericSignature genericSig,
177
+ ArrayRef<Type> types,
178
+ InFlightSubstitution &IFS) {
179
+ // Form the stored conformances.
180
+ SmallVector<ProtocolConformanceRef, 4 > conformances;
181
+ for (const auto &req : genericSig.getRequirements ()) {
182
+ if (req.getKind () != RequirementKind::Conformance) continue ;
183
+
184
+ CanType depTy = req.getFirstType ()->getCanonicalType ();
185
+ auto replacement = depTy.subst (IFS);
186
+ auto *proto = req.getProtocolDecl ();
187
+ auto conformance = IFS.lookupConformance (depTy, replacement, proto,
188
+ /* level=*/ 0 );
189
+ conformances.push_back (conformance);
190
+ }
191
+
192
+ return SubstitutionMap (genericSig, types, conformances);
174
193
}
175
194
176
195
SubstitutionMap SubstitutionMap::get (GenericSignature genericSig,
@@ -185,29 +204,17 @@ SubstitutionMap SubstitutionMap::get(GenericSignature genericSig,
185
204
186
205
for (auto *gp : genericSig.getGenericParams ()) {
187
206
// Record the replacement.
188
- Type replacement = Type (gp).subst (IFS);
189
-
190
- assert ((!replacement || replacement->hasError () ||
207
+ Type replacement = IFS.substType (gp, /* level=*/ 0 );
208
+ if (!replacement)
209
+ replacement = ErrorType::get (gp->getASTContext ());
210
+ assert ((replacement->hasError () ||
191
211
gp->isParameterPack () == replacement->is <PackType>()) &&
192
212
" replacement for pack parameter must be a pack type" );
193
213
194
214
replacementTypes.push_back (replacement);
195
215
}
196
216
197
- // Form the stored conformances.
198
- SmallVector<ProtocolConformanceRef, 4 > conformances;
199
- for (const auto &req : genericSig.getRequirements ()) {
200
- if (req.getKind () != RequirementKind::Conformance) continue ;
201
-
202
- CanType depTy = req.getFirstType ()->getCanonicalType ();
203
- auto replacement = depTy.subst (IFS);
204
- auto *proto = req.getProtocolDecl ();
205
- auto conformance = IFS.lookupConformance (depTy, replacement, proto,
206
- /* level=*/ 0 );
207
- conformances.push_back (conformance);
208
- }
209
-
210
- return SubstitutionMap (genericSig, replacementTypes, conformances);
217
+ return SubstitutionMap::get (genericSig, replacementTypes, IFS);
211
218
}
212
219
213
220
Type SubstitutionMap::lookupSubstitution (GenericTypeParamType *genericParam) const {
0 commit comments