Skip to content

Commit 5e7a91d

Browse files
committed
SIL: Generalize SILType::subst() to take SubstOptions
1 parent a158234 commit 5e7a91d

File tree

4 files changed

+16
-21
lines changed

4 files changed

+16
-21
lines changed

include/swift/SIL/SILType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -686,12 +686,12 @@ class SILType {
686686
SILType subst(Lowering::TypeConverter &tc, TypeSubstitutionFn subs,
687687
LookupConformanceFn conformances,
688688
CanGenericSignature genericSig = CanGenericSignature(),
689-
bool shouldSubstituteOpaqueArchetypes = false) const;
689+
SubstOptions options = None) const;
690690

691691
SILType subst(SILModule &M, TypeSubstitutionFn subs,
692692
LookupConformanceFn conformances,
693693
CanGenericSignature genericSig = CanGenericSignature(),
694-
bool shouldSubstituteOpaqueArchetypes = false) const;
694+
SubstOptions options = None) const;
695695

696696
SILType subst(Lowering::TypeConverter &tc,
697697
InFlightSubstitution &IFS,

lib/IRGen/MetadataRequest.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ SILType IRGenModule::substOpaqueTypesWithUnderlyingTypes(
539539
getSILModule().isWholeModule());
540540
auto underlyingTy =
541541
type.subst(getSILModule(), replacer, replacer, genericSig,
542-
/*substitute opaque*/ true);
542+
SubstFlags::SubstituteOpaqueArchetypes);
543543
return underlyingTy;
544544
}
545545

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4571,13 +4571,15 @@ static bool areABICompatibleParamsOrReturns(SILType a, SILType b,
45714571
inFunction->getModule().isWholeModule());
45724572
if (aa.getASTType()->hasOpaqueArchetype())
45734573
opaqueTypesSubstituted = aa.subst(inFunction->getModule(), replacer,
4574-
replacer, CanGenericSignature(), true);
4574+
replacer, CanGenericSignature(),
4575+
SubstFlags::SubstituteOpaqueArchetypes);
45754576

45764577
auto opaqueTypesSubstituted2 = bb;
45774578
if (bb.getASTType()->hasOpaqueArchetype())
45784579
opaqueTypesSubstituted2 =
45794580
bb.subst(inFunction->getModule(), replacer, replacer,
4580-
CanGenericSignature(), true);
4581+
CanGenericSignature(),
4582+
SubstFlags::SubstituteOpaqueArchetypes);
45814583
if (opaqueTypesSubstituted == opaqueTypesSubstituted2)
45824584
continue;
45834585
}

lib/SIL/IR/SILTypeSubstitution.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -465,35 +465,29 @@ class SILTypeSubstituter :
465465

466466
} // end anonymous namespace
467467

468-
static bool isSubstitutionInvariant(SILType ty,
469-
bool shouldSubstituteOpaqueArchetypes) {
468+
static bool isSubstitutionInvariant(SILType ty, SubstOptions options) {
470469
return (!ty.hasArchetype() &&
471470
!ty.hasTypeParameter() &&
472-
(!shouldSubstituteOpaqueArchetypes ||
471+
(!options.contains(SubstFlags::SubstituteOpaqueArchetypes) ||
473472
!ty.getRawASTType()->hasOpaqueArchetype()));
474473
}
475474

476475
SILType SILType::subst(TypeConverter &tc, TypeSubstitutionFn subs,
477476
LookupConformanceFn conformances,
478477
CanGenericSignature genericSig,
479-
bool shouldSubstituteOpaqueArchetypes) const {
480-
if (isSubstitutionInvariant(*this, shouldSubstituteOpaqueArchetypes))
478+
SubstOptions options) const {
479+
if (isSubstitutionInvariant(*this, options))
481480
return *this;
482481

483-
auto substOptions =
484-
(shouldSubstituteOpaqueArchetypes
485-
? SubstOptions(SubstFlags::SubstituteOpaqueArchetypes)
486-
: SubstOptions(None));
487-
InFlightSubstitution IFS(subs, conformances, substOptions);
488-
482+
InFlightSubstitution IFS(subs, conformances, options);
489483
SILTypeSubstituter STST(tc, TypeExpansionContext::minimal(), IFS,
490484
genericSig);
491485
return STST.subst(*this);
492486
}
493487

494488
SILType SILType::subst(TypeConverter &tc, InFlightSubstitution &IFS,
495489
CanGenericSignature genericSig) const {
496-
if (isSubstitutionInvariant(*this, IFS.shouldSubstituteOpaqueArchetypes()))
490+
if (isSubstitutionInvariant(*this, IFS.getOptions()))
497491
return *this;
498492

499493
SILTypeSubstituter STST(tc, TypeExpansionContext::minimal(), IFS,
@@ -504,9 +498,8 @@ SILType SILType::subst(TypeConverter &tc, InFlightSubstitution &IFS,
504498
SILType SILType::subst(SILModule &M, TypeSubstitutionFn subs,
505499
LookupConformanceFn conformances,
506500
CanGenericSignature genericSig,
507-
bool shouldSubstituteOpaqueArchetypes) const {
508-
return subst(M.Types, subs, conformances, genericSig,
509-
shouldSubstituteOpaqueArchetypes);
501+
SubstOptions options) const {
502+
return subst(M.Types, subs, conformances, genericSig, options);
510503
}
511504

512505
SILType SILType::subst(TypeConverter &tc, SubstitutionMap subs) const {
@@ -521,7 +514,7 @@ SILType SILType::subst(SILModule &M, SubstitutionMap subs) const{
521514

522515
SILType SILType::subst(SILModule &M, SubstitutionMap subs,
523516
TypeExpansionContext context) const {
524-
if (isSubstitutionInvariant(*this, false))
517+
if (isSubstitutionInvariant(*this, None))
525518
return *this;
526519

527520
InFlightSubstitutionViaSubMap IFS(subs, None);

0 commit comments

Comments
 (0)