@@ -79,7 +79,6 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
7979 SILBuilder Builder;
8080 DominanceInfo *DomTree = nullptr ;
8181 SubstitutionMapWithLocalArchetypes Functor;
82- TypeSubstitutionMap &LocalArchetypeSubs;
8382
8483 // The old-to-new value map.
8584 llvm::DenseMap<SILValue, SILValue> ValueMap;
@@ -106,10 +105,10 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
106105 using SILInstructionVisitor<ImplClass>::asImpl;
107106
108107 explicit SILCloner (SILFunction &F, DominanceInfo *DT = nullptr )
109- : Builder(F), DomTree(DT), LocalArchetypeSubs(Functor.LocalArchetypeSubs) {}
108+ : Builder(F), DomTree(DT) {}
110109
111110 explicit SILCloner (SILGlobalVariable *GlobVar)
112- : Builder(GlobVar), LocalArchetypeSubs(Functor.LocalArchetypeSubs) {}
111+ : Builder(GlobVar) {}
113112
114113 void clearClonerState () {
115114 ValueMap.clear ();
@@ -198,7 +197,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
198197 // / Register a re-mapping for local archetypes such as opened existentials.
199198 void registerLocalArchetypeRemapping (ArchetypeType *From,
200199 ArchetypeType *To) {
201- auto result = LocalArchetypeSubs.insert (
200+ auto result = Functor. LocalArchetypeSubs .insert (
202201 std::make_pair (CanArchetypeType (From), CanType (To)));
203202 assert (result.second );
204203 (void )result;
@@ -336,17 +335,6 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
336335
337336 ProtocolConformanceRef getOpConformance (Type ty,
338337 ProtocolConformanceRef conformance) {
339- // If we have local archetypes to substitute, do so now.
340- if (ty->hasLocalArchetype () && !LocalArchetypeSubs.empty ()) {
341- conformance =
342- conformance.subst (ty,
343- QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
344- MakeAbstractConformanceForGenericType ());
345- ty = ty.subst (
346- QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
347- MakeAbstractConformanceForGenericType ());
348- }
349-
350338 return asImpl ().remapConformance (ty, conformance);
351339 }
352340
@@ -448,8 +436,13 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
448436 }
449437
450438 ProtocolConformanceRef remapConformance (Type Ty, ProtocolConformanceRef C) {
439+ // If we have local archetypes to substitute, do so now.
440+ if (Ty->hasLocalArchetype ())
441+ C = C.subst (Ty, Functor, Functor);
442+
451443 return C;
452444 }
445+
453446 // / Get the value that takes the place of the given `Value` within the cloned
454447 // / region. The given value must already have been mapped by this cloner.
455448 SILValue getMappedValue (SILValue Value);
0 commit comments