Skip to content

Commit a356b10

Browse files
committed
SIL: Sink local archetype substitution into remapType()
1 parent 0a0b17a commit a356b10

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

include/swift/SIL/SILCloner.h

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,6 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
225225
}
226226

227227
SILType getOpType(SILType Ty) {
228-
// Substitute local archetypes, if we have any.
229-
if (Ty.hasLocalArchetype() && !LocalArchetypeSubs.empty()) {
230-
Ty = Ty.subst(
231-
Builder.getModule(),
232-
QueryTypeSubstitutionMapOrIdentity{LocalArchetypeSubs},
233-
MakeAbstractConformanceForGenericType(),
234-
CanGenericSignature());
235-
}
236-
237228
return asImpl().remapType(Ty);
238229
}
239230

@@ -439,17 +430,19 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
439430
SILLocation remapLocation(SILLocation Loc) { return Loc; }
440431
const SILDebugScope *remapScope(const SILDebugScope *DS) { return DS; }
441432
SILType remapType(SILType Ty) {
442-
return Ty;
433+
// Substitute local archetypes, if we have any.
434+
if (Ty.hasLocalArchetype()) {
435+
Ty = Ty.subst(Builder.getModule(), Functor, Functor,
436+
CanGenericSignature());
437+
}
438+
439+
return Ty;
443440
}
444441

445442
CanType remapASTType(CanType ty) {
446443
// 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-
}
444+
if (ty->hasLocalArchetype())
445+
ty = ty.subst(Functor, Functor)->getCanonicalType();
453446

454447
return ty;
455448
}

include/swift/SIL/TypeSubstCloner.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,16 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
168168
SILType remapType(SILType Ty) {
169169
SILType &Sty = TypeCache[Ty];
170170
if (!Sty) {
171-
Sty = Ty.subst(Original.getModule(), SubsMap);
172-
if (!Sty.getASTType()->hasOpaqueArchetype() ||
173-
!getBuilder()
174-
.getTypeExpansionContext()
175-
.shouldLookThroughOpaqueTypeArchetypes())
171+
Sty = Ty;
172+
173+
Sty = Sty.subst(getBuilder().getModule(), Functor, Functor);
174+
175+
auto context = getBuilder().getTypeExpansionContext();
176+
177+
if (!Sty.hasOpaqueArchetype() ||
178+
!context.shouldLookThroughOpaqueTypeArchetypes())
176179
return Sty;
180+
177181
// Remap types containing opaque result types in the current context.
178182
Sty = getBuilder().getTypeLowering(Sty).getLoweredType().getCategoryType(
179183
Sty.getCategory());

lib/IRGen/LoadableByAddress.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,6 +2983,7 @@ namespace {
29832983
}
29842984

29852985
SILType remapType(SILType ty) {
2986+
ty = ty.subst(getBuilder().getModule(), Functor, Functor);
29862987
if (auto fnType = ty.getAs<SILFunctionType>()) {
29872988
GenericEnvironment *genEnv = getSubstGenericEnvironment(fnType);
29882989
return SILType::getPrimitiveObjectType(

lib/SILOptimizer/IPO/CrossModuleOptimization.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ class InstructionVisitor : public SILCloner<InstructionVisitor> {
133133
}
134134

135135
SILType remapType(SILType Ty) {
136+
if (Ty.hasLocalArchetype()) {
137+
Ty = Ty.subst(getBuilder().getModule(), Functor, Functor,
138+
CanGenericSignature());
139+
}
140+
136141
CMS.makeTypeUsableFromInline(Ty.getASTType());
137142
return Ty;
138143
}

lib/SILOptimizer/UtilityPasses/SerializeSILPass.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ class MapOpaqueArchetypes : public SILCloner<MapOpaqueArchetypes> {
4141
}
4242

4343
SILType remapType(SILType Ty) {
44-
if (!Ty.getASTType()->hasOpaqueArchetype() ||
44+
// Substitute local archetypes, if we have any.
45+
if (Ty.hasLocalArchetype()) {
46+
Ty = Ty.subst(getBuilder().getModule(), Functor, Functor,
47+
CanGenericSignature());
48+
}
49+
50+
if (!Ty.hasOpaqueArchetype() ||
4551
!getBuilder()
4652
.getTypeExpansionContext()
4753
.shouldLookThroughOpaqueTypeArchetypes())

0 commit comments

Comments
 (0)