Skip to content

Commit 12ce32e

Browse files
committed
AST: Early return from substOpaqueTypesWithUnderlyingTypes() overloads if nothing to do
1 parent 866737e commit 12ce32e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/AST/SubstitutionMap.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,18 @@ bool SubstitutionMap::isIdentity() const {
620620

621621
SubstitutionMap swift::substOpaqueTypesWithUnderlyingTypes(
622622
SubstitutionMap subs, TypeExpansionContext context) {
623+
if (!context.shouldLookThroughOpaqueTypeArchetypes())
624+
return subs;
625+
626+
if (!subs.getRecursiveProperties().hasOpaqueArchetype() &&
627+
!llvm::any_of(subs.getConformances(),
628+
[&](ProtocolConformanceRef ref) {
629+
return (!ref.isInvalid() &&
630+
ref.getType()->hasOpaqueArchetype());
631+
})) {
632+
return subs;
633+
}
634+
623635
ReplaceOpaqueTypesWithUnderlyingTypes replacer(
624636
context.getContext(), context.getResilienceExpansion(),
625637
context.isWholeModuleContext());

lib/AST/TypeSubstitution.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,6 +1089,13 @@ swift::substOpaqueTypesWithUnderlyingTypes(CanType ty,
10891089

10901090
ProtocolConformanceRef swift::substOpaqueTypesWithUnderlyingTypes(
10911091
ProtocolConformanceRef ref, TypeExpansionContext context) {
1092+
if (ref.isInvalid())
1093+
return ref;
1094+
1095+
if (!context.shouldLookThroughOpaqueTypeArchetypes() ||
1096+
!ref.getType()->hasOpaqueArchetype())
1097+
return ref;
1098+
10921099
ReplaceOpaqueTypesWithUnderlyingTypes replacer(
10931100
context.getContext(), context.getResilienceExpansion(),
10941101
context.isWholeModuleContext());

0 commit comments

Comments
 (0)