Skip to content

Commit 0a0b17a

Browse files
committed
SIL: Sink local archetype substitution into remapASTType()
1 parent 3b5846d commit 0a0b17a

File tree

4 files changed

+25
-17
lines changed

4 files changed

+25
-17
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,14 +238,6 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
238238
}
239239

240240
CanType getOpASTType(CanType ty) {
241-
// Substitute local archetypes, if we have any.
242-
if (ty->hasLocalArchetype() && !LocalArchetypeSubs.empty()) {
243-
ty = ty.subst(
244-
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
245-
MakeAbstractConformanceForGenericType()
246-
)->getCanonicalType();
247-
}
248-
249241
return asImpl().remapASTType(ty);
250242
}
251243

@@ -450,8 +442,16 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
450442
return Ty;
451443
}
452444

453-
CanType remapASTType(CanType Ty) {
454-
return Ty;
445+
CanType remapASTType(CanType ty) {
446+
// Substitute local archetypes, if we have any.
447+
if (ty->hasLocalArchetype() && !LocalArchetypeSubs.empty()) {
448+
ty = ty.subst(
449+
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
450+
MakeAbstractConformanceForGenericType()
451+
)->getCanonicalType();
452+
}
453+
454+
return ty;
455455
}
456456

457457
ProtocolConformanceRef remapConformance(Type Ty, ProtocolConformanceRef C) {

include/swift/SIL/TypeSubstCloner.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,17 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
182182
}
183183

184184
CanType remapASTType(CanType ty) {
185-
auto substTy = ty.subst(SubsMap)->getCanonicalType();
185+
auto substTy = ty.subst(Functor, Functor)->getCanonicalType();
186+
187+
auto context = getBuilder().getTypeExpansionContext();
188+
186189
if (!substTy->hasOpaqueArchetype() ||
187-
!getBuilder().getTypeExpansionContext()
188-
.shouldLookThroughOpaqueTypeArchetypes())
190+
!context.shouldLookThroughOpaqueTypeArchetypes())
189191
return substTy;
192+
190193
// Remap types containing opaque result types in the current context.
191-
return substOpaqueTypesWithUnderlyingTypes(
192-
substTy,
193-
TypeExpansionContext(getBuilder().getFunction()),
194-
/*allowLoweredTypes=*/false);
194+
return substOpaqueTypesWithUnderlyingTypes(substTy, context,
195+
/*allowLoweredTypes=*/false);
195196
}
196197

197198
ProtocolConformanceRef remapConformance(Type ty,

lib/SILOptimizer/IPO/CrossModuleOptimization.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ class InstructionVisitor : public SILCloner<InstructionVisitor> {
138138
}
139139

140140
CanType remapASTType(CanType Ty) {
141+
if (Ty->hasLocalArchetype())
142+
Ty = Ty.subst(Functor, Functor)->getCanonicalType();
143+
141144
CMS.makeTypeUsableFromInline(Ty);
142145
return Ty;
143146
}

lib/SILOptimizer/UtilityPasses/SerializeSILPass.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ class MapOpaqueArchetypes : public SILCloner<MapOpaqueArchetypes> {
5252
}
5353

5454
CanType remapASTType(CanType ty) {
55+
// Substitute local archetypes, if we have any.
56+
if (ty->hasLocalArchetype())
57+
ty = ty.subst(Functor, Functor)->getCanonicalType();
58+
5559
if (!ty->hasOpaqueArchetype() ||
5660
!getBuilder()
5761
.getTypeExpansionContext()

0 commit comments

Comments
 (0)