Skip to content

Commit 2fa49b0

Browse files
committed
AST: SubstitutionMap overload of substOpaqueTypesWithUnderlyingTypes()
This replaces the oddly-named mapIntoTypeExpansionContext() method on SubstitutionMap itself in favor of a global function, just like the ones that take Type and ProtocolConformanceRef.
1 parent 0b961c6 commit 2fa49b0

File tree

6 files changed

+19
-19
lines changed

6 files changed

+19
-19
lines changed

include/swift/AST/SubstitutionMap.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,6 @@ class SubstitutionMap {
181181
/// subsystem.
182182
SubstitutionMap subst(InFlightSubstitution &subs) const;
183183

184-
/// Apply type expansion lowering to all types in the substitution map. Opaque
185-
/// archetypes will be lowered to their underlying types if the type expansion
186-
/// context allows.
187-
SubstitutionMap mapIntoTypeExpansionContext(
188-
TypeExpansionContext context) const;
189-
190184
/// Create a substitution map for a protocol conformance.
191185
static SubstitutionMap
192186
getProtocolSubstitutions(ProtocolConformanceRef conformance);

include/swift/AST/Types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5032,9 +5032,15 @@ Type substOpaqueTypesWithUnderlyingTypes(Type type,
50325032

50335033
CanType substOpaqueTypesWithUnderlyingTypes(CanType type,
50345034
TypeExpansionContext context);
5035+
50355036
ProtocolConformanceRef
50365037
substOpaqueTypesWithUnderlyingTypes(ProtocolConformanceRef ref,
50375038
TypeExpansionContext context);
5039+
5040+
SubstitutionMap
5041+
substOpaqueTypesWithUnderlyingTypes(SubstitutionMap subs,
5042+
TypeExpansionContext context);
5043+
50385044
namespace Lowering {
50395045
class TypeConverter;
50405046
}

include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
590590
!context.shouldLookThroughOpaqueTypeArchetypes())
591591
return Subs;
592592

593-
return Subs.mapIntoTypeExpansionContext(context);
593+
return substOpaqueTypesWithUnderlyingTypes(Subs, context);
594594
}
595595

596596
return Subs;

lib/AST/SubstitutionMap.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -651,14 +651,14 @@ bool SubstitutionMap::isIdentity() const {
651651
return !hasNonIdentityReplacement;
652652
}
653653

654-
SubstitutionMap SubstitutionMap::mapIntoTypeExpansionContext(
655-
TypeExpansionContext context) const {
654+
SubstitutionMap swift::substOpaqueTypesWithUnderlyingTypes(
655+
SubstitutionMap subs, TypeExpansionContext context) {
656656
ReplaceOpaqueTypesWithUnderlyingTypes replacer(
657657
context.getContext(), context.getResilienceExpansion(),
658658
context.isWholeModuleContext());
659-
return this->subst(replacer, replacer,
660-
SubstFlags::SubstituteOpaqueArchetypes |
661-
SubstFlags::PreservePackExpansionLevel);
659+
return subs.subst(replacer, replacer,
660+
SubstFlags::SubstituteOpaqueArchetypes |
661+
SubstFlags::PreservePackExpansionLevel);
662662
}
663663

664664
bool OuterSubstitutions::isUnsubstitutedTypeParameter(Type type) const {

lib/SIL/IR/SILTypeSubstitution.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class SILTypeSubstituter :
6868
if (!typeExpansionContext.shouldLookThroughOpaqueTypeArchetypes())
6969
return subs;
7070

71-
return subs.mapIntoTypeExpansionContext(typeExpansionContext);
71+
return substOpaqueTypesWithUnderlyingTypes(subs, typeExpansionContext);
7272
}
7373

7474
// Substitute a function type.

lib/SILGen/SILGenApply.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ class Callee {
452452
auto &ci = SGF.getConstantInfo(SGF.getTypeExpansionContext(), c);
453453
return Callee(
454454
SGF, c, ci.FormalPattern, ci.FormalType,
455-
subs.mapIntoTypeExpansionContext(SGF.getTypeExpansionContext()),
455+
substOpaqueTypesWithUnderlyingTypes(subs, SGF.getTypeExpansionContext()),
456456
subs,
457457
l,
458458
callPreviousDynamicReplaceableImpl);
@@ -465,15 +465,15 @@ class Callee {
465465
auto &ci = SGF.getConstantInfo(SGF.getTypeExpansionContext(), c);
466466
return Callee(
467467
Kind::EnumElement, SGF, c, ci.FormalPattern, ci.FormalType,
468-
subs.mapIntoTypeExpansionContext(SGF.getTypeExpansionContext()), l);
468+
substOpaqueTypesWithUnderlyingTypes(subs, SGF.getTypeExpansionContext()), l);
469469
}
470470
static Callee forClassMethod(SILGenFunction &SGF,
471471
SILDeclRef c, SubstitutionMap subs,
472472
SILLocation l) {
473473
auto base = c.getOverriddenVTableEntry();
474474
auto &baseCI = SGF.getConstantInfo(SGF.getTypeExpansionContext(), base);
475475
auto &derivedCI = SGF.getConstantInfo(SGF.getTypeExpansionContext(), c);
476-
subs = subs.mapIntoTypeExpansionContext(SGF.getTypeExpansionContext());
476+
subs = substOpaqueTypesWithUnderlyingTypes(subs, SGF.getTypeExpansionContext());
477477

478478
// We use an orig function type based on the overridden vtable entry, but
479479
// the substitutions we have are for the current function. To get subs
@@ -497,7 +497,7 @@ class Callee {
497497
SILDeclRef c, SubstitutionMap subs,
498498
SILLocation l) {
499499
auto &ci = SGF.getConstantInfo(SGF.getTypeExpansionContext(), c);
500-
subs = subs.mapIntoTypeExpansionContext(SGF.getTypeExpansionContext());
500+
subs = substOpaqueTypesWithUnderlyingTypes(subs, SGF.getTypeExpansionContext());
501501
auto origFunctionType = ci.FormalPattern.withSubstitutions(subs);
502502
return Callee(
503503
Kind::SuperMethod, SGF, c, origFunctionType, ci.FormalType, subs, l);
@@ -524,7 +524,7 @@ class Callee {
524524
auto &ci = SGF.getConstantInfo(SGF.getTypeExpansionContext(), c);
525525
return Callee(
526526
Kind::WitnessMethod, SGF, c, ci.FormalPattern, ci.FormalType,
527-
subs.mapIntoTypeExpansionContext(SGF.getTypeExpansionContext()), l);
527+
substOpaqueTypesWithUnderlyingTypes(subs, SGF.getTypeExpansionContext()), l);
528528
}
529529
static Callee forDynamic(SILGenFunction &SGF,
530530
SILDeclRef c, SubstitutionMap constantSubs,
@@ -550,7 +550,7 @@ class Callee {
550550

551551
return Callee(
552552
Kind::DynamicMethod, SGF, c, origFormalType, substFormalType,
553-
subs.mapIntoTypeExpansionContext(SGF.getTypeExpansionContext()), l);
553+
substOpaqueTypesWithUnderlyingTypes(subs, SGF.getTypeExpansionContext()), l);
554554
}
555555

556556
static Callee formCallee(SILGenFunction &SGF, AbstractFunctionDecl *decl,

0 commit comments

Comments
 (0)