Skip to content

Commit 3dcadf8

Browse files
committed
AST: Add typeCheckFunctionBodies parameter to ReplaceOpaqueTypesWithUnderlyingTypes
1 parent 24ee8cf commit 3dcadf8

File tree

2 files changed

+19
-29
lines changed

2 files changed

+19
-29
lines changed

include/swift/AST/Types.h

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7081,15 +7081,20 @@ enum class OpaqueSubstitutionKind {
70817081
/// to their underlying types.
70827082
class ReplaceOpaqueTypesWithUnderlyingTypes {
70837083
private:
7084-
ResilienceExpansion contextExpansion;
7085-
llvm::PointerIntPair<const DeclContext *, 1, bool> inContextAndIsWholeModule;
7084+
const DeclContext *inContext;
7085+
unsigned contextExpansion : 1;
7086+
bool isWholeModule : 1;
7087+
bool typeCheckFunctionBodies : 1;
70867088

70877089
public:
70887090
ReplaceOpaqueTypesWithUnderlyingTypes(const DeclContext *inContext,
70897091
ResilienceExpansion contextExpansion,
7090-
bool isWholeModuleContext)
7091-
: contextExpansion(contextExpansion),
7092-
inContextAndIsWholeModule(inContext, isWholeModuleContext) {}
7092+
bool isWholeModule,
7093+
bool typeCheckFunctionBodies=true)
7094+
: inContext(inContext),
7095+
contextExpansion(unsigned(contextExpansion)),
7096+
isWholeModule(isWholeModule),
7097+
typeCheckFunctionBodies(typeCheckFunctionBodies) {}
70937098

70947099
/// TypeSubstitutionFn
70957100
Type operator()(SubstitutableType *maybeOpaqueType) const;
@@ -7105,13 +7110,6 @@ class ReplaceOpaqueTypesWithUnderlyingTypes {
71057110
static OpaqueSubstitutionKind
71067111
shouldPerformSubstitution(OpaqueTypeDecl *opaque, ModuleDecl *contextModule,
71077112
ResilienceExpansion contextExpansion);
7108-
7109-
private:
7110-
const DeclContext *getContext() const {
7111-
return inContextAndIsWholeModule.getPointer();
7112-
}
7113-
7114-
bool isWholeModule() const { return inContextAndIsWholeModule.getInt(); }
71157113
};
71167114

71177115
/// A function object that can be used as a \c TypeSubstitutionFn and

lib/AST/TypeSubstitution.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -903,10 +903,10 @@ Type TypeBase::adjustSuperclassMemberDeclType(const ValueDecl *baseDecl,
903903
OpaqueSubstitutionKind
904904
ReplaceOpaqueTypesWithUnderlyingTypes::shouldPerformSubstitution(
905905
OpaqueTypeDecl *opaque) const {
906-
const auto *inContext = getContext();
907906
auto inModule = inContext ? inContext->getParentModule()
908907
: opaque->getParentModule();
909-
return shouldPerformSubstitution(opaque, inModule, contextExpansion);
908+
return shouldPerformSubstitution(
909+
opaque, inModule, ResilienceExpansion(contextExpansion));
910910
}
911911
OpaqueSubstitutionKind
912912
ReplaceOpaqueTypesWithUnderlyingTypes::shouldPerformSubstitution(
@@ -1025,7 +1025,7 @@ operator()(SubstitutableType *maybeOpaqueType) const {
10251025
return maybeOpaqueType;
10261026
}
10271027

1028-
auto subs = decl->getUniqueUnderlyingTypeSubstitutions();
1028+
auto subs = decl->getUniqueUnderlyingTypeSubstitutions(typeCheckFunctionBodies);
10291029
// If the body of the opaque decl providing decl has not been type checked we
10301030
// don't have a underlying substitution.
10311031
if (!subs.has_value())
@@ -1038,16 +1038,12 @@ operator()(SubstitutableType *maybeOpaqueType) const {
10381038

10391039
// Check that we are allowed to substitute the underlying type into the
10401040
// context.
1041-
auto inContext = this->getContext();
1042-
auto isContextWholeModule = this->isWholeModule();
1043-
auto contextExpansion = this->contextExpansion;
10441041
if (inContext &&
10451042
partialSubstTy.findIf(
1046-
[inContext, substitutionKind, isContextWholeModule,
1047-
contextExpansion](Type t) -> bool {
1043+
[&](Type t) -> bool {
10481044
if (!canSubstituteTypeInto(t, inContext, substitutionKind,
1049-
contextExpansion,
1050-
isContextWholeModule))
1045+
ResilienceExpansion(contextExpansion),
1046+
isWholeModule))
10511047
return true;
10521048
return false;
10531049
}))
@@ -1154,16 +1150,12 @@ operator()(InFlightSubstitution &IFS, Type maybeOpaqueType,
11541150

11551151
// Check that we are allowed to substitute the underlying type into the
11561152
// context.
1157-
auto inContext = this->getContext();
1158-
auto isContextWholeModule = this->isWholeModule();
1159-
auto contextExpansion = this->contextExpansion;
11601153
if (inContext &&
11611154
partialSubstTy.findIf(
1162-
[inContext, substitutionKind, isContextWholeModule,
1163-
contextExpansion](Type t) -> bool {
1155+
[&](Type t) -> bool {
11641156
if (!canSubstituteTypeInto(t, inContext, substitutionKind,
1165-
contextExpansion,
1166-
isContextWholeModule))
1157+
ResilienceExpansion(contextExpansion),
1158+
isWholeModule))
11671159
return true;
11681160
return false;
11691161
})) {

0 commit comments

Comments
 (0)