@@ -189,62 +189,38 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
189
189
}
190
190
191
191
SubstitutionMap getOpSubstitutionMap (SubstitutionMap Subs) {
192
- // If we have local archetypes to substitute, check whether that's
193
- // relevant to this particular substitution.
194
- if (!LocalArchetypeSubs.empty ()) {
195
- if (Subs.hasLocalArchetypes ()) {
196
- // If we found a type containing a local archetype, substitute
197
- // open existentials throughout the substitution map.
198
- Subs = Subs.subst (QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
199
- MakeAbstractConformanceForGenericType ());
200
- }
192
+ // If we have local archetypes to substitute, do so now.
193
+ if (Subs.hasLocalArchetypes () && !LocalArchetypeSubs.empty ()) {
194
+ Subs = Subs.subst (QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
195
+ MakeAbstractConformanceForGenericType ());
201
196
}
202
197
203
198
return asImpl ().remapSubstitutionMap (Subs)
204
199
.getCanonical (/* canonicalizeSignature*/ false );
205
200
}
206
201
207
- SILType getTypeInClonedContext (SILType Ty) {
208
- auto objectTy = Ty.getASTType ();
209
- // Do not substitute local archetypes, if we do not have any.
210
- if (!objectTy->hasLocalArchetype ())
211
- return Ty;
212
- // Do not substitute local archetypes, if it is not required.
213
- // This is often the case when cloning basic blocks inside the same
214
- // function.
215
- if (LocalArchetypeSubs.empty ())
216
- return Ty;
217
-
218
- // Substitute local archetypes, if we have any.
219
- return Ty.subst (
220
- Builder.getModule (),
221
- QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
222
- MakeAbstractConformanceForGenericType (),
223
- CanGenericSignature ());
224
- }
225
202
SILType getOpType (SILType Ty) {
226
- Ty = getTypeInClonedContext (Ty);
227
- return asImpl ().remapType (Ty);
228
- }
229
-
230
- CanType getASTTypeInClonedContext (Type ty) {
231
- // Do not substitute local archetypes, if we do not have any.
232
- if (!ty->hasLocalArchetype ())
233
- return ty->getCanonicalType ();
234
- // Do not substitute local archetypes, if it is not required.
235
- // This is often the case when cloning basic blocks inside the same
236
- // function.
237
- if (LocalArchetypeSubs.empty ())
238
- return ty->getCanonicalType ();
203
+ // Substitute local archetypes, if we have any.
204
+ if (Ty.hasLocalArchetype () && !LocalArchetypeSubs.empty ()) {
205
+ Ty = Ty.subst (
206
+ Builder.getModule (),
207
+ QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
208
+ MakeAbstractConformanceForGenericType (),
209
+ CanGenericSignature ());
210
+ }
239
211
240
- return ty.subst (
241
- QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
242
- MakeAbstractConformanceForGenericType ()
243
- )->getCanonicalType ();
212
+ return asImpl ().remapType (Ty);
244
213
}
245
214
246
215
CanType getOpASTType (CanType ty) {
247
- ty = getASTTypeInClonedContext (ty);
216
+ // Substitute local archetypes, if we have any.
217
+ if (ty->hasLocalArchetype () && !LocalArchetypeSubs.empty ()) {
218
+ ty = ty.subst (
219
+ QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
220
+ MakeAbstractConformanceForGenericType ()
221
+ )->getCanonicalType ();
222
+ }
223
+
248
224
return asImpl ().remapASTType (ty);
249
225
}
250
226
@@ -356,13 +332,14 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
356
332
if (ty->hasLocalArchetype () && !LocalArchetypeSubs.empty ()) {
357
333
conformance =
358
334
conformance.subst (ty,
359
- QueryTypeSubstitutionMapOrIdentity{
360
- LocalArchetypeSubs},
335
+ QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
361
336
MakeAbstractConformanceForGenericType ());
337
+ ty = ty.subst (
338
+ QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
339
+ MakeAbstractConformanceForGenericType ());
362
340
}
363
341
364
- return asImpl ().remapConformance (getASTTypeInClonedContext (ty),
365
- conformance);
342
+ return asImpl ().remapConformance (ty, conformance);
366
343
}
367
344
368
345
ArrayRef<ProtocolConformanceRef>
0 commit comments