@@ -189,62 +189,38 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
189189 }
190190
191191 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 ());
201196 }
202197
203198 return asImpl ().remapSubstitutionMap (Subs)
204199 .getCanonical (/* canonicalizeSignature*/ false );
205200 }
206201
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- }
225202 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+ }
239211
240- return ty.subst (
241- QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
242- MakeAbstractConformanceForGenericType ()
243- )->getCanonicalType ();
212+ return asImpl ().remapType (Ty);
244213 }
245214
246215 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+
248224 return asImpl ().remapASTType (ty);
249225 }
250226
@@ -356,13 +332,14 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
356332 if (ty->hasLocalArchetype () && !LocalArchetypeSubs.empty ()) {
357333 conformance =
358334 conformance.subst (ty,
359- QueryTypeSubstitutionMapOrIdentity{
360- LocalArchetypeSubs},
335+ QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
361336 MakeAbstractConformanceForGenericType ());
337+ ty = ty.subst (
338+ QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
339+ MakeAbstractConformanceForGenericType ());
362340 }
363341
364- return asImpl ().remapConformance (getASTTypeInClonedContext (ty),
365- conformance);
342+ return asImpl ().remapConformance (ty, conformance);
366343 }
367344
368345 ArrayRef<ProtocolConformanceRef>
0 commit comments