Skip to content

Commit ddc2fa4

Browse files
committed
[AST] NFC: introduce ASTContext::isAccessControlDisabled
1 parent 5426e0d commit ddc2fa4

File tree

11 files changed

+25
-26
lines changed

11 files changed

+25
-26
lines changed

include/swift/AST/ASTContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,12 @@ class ASTContext final {
936936
return LangOpts.isSwiftVersionAtLeast(major, minor);
937937
}
938938

939+
/// Check whether it's important to respect access control restrictions
940+
/// in current context.
941+
bool isAccessControlDisabled() const {
942+
return !LangOpts.EnableAccessControl;
943+
}
944+
939945
private:
940946
friend Decl;
941947
Optional<RawComment> getRawComment(const Decl *D);

lib/AST/Decl.cpp

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2750,12 +2750,6 @@ ValueDecl::getFormalAccessScope(const DeclContext *useDC,
27502750
treatUsableFromInlineAsPublic);
27512751
}
27522752

2753-
/// Check whether it's important to respect access control restrictions
2754-
/// in current context.
2755-
static bool isAccessControlDisabled(const ASTContext &ctx) {
2756-
return !ctx.LangOpts.EnableAccessControl;
2757-
}
2758-
27592753
/// Checks if \p VD may be used from \p useDC, taking \@testable imports into
27602754
/// account.
27612755
///
@@ -2766,7 +2760,7 @@ static bool isAccessControlDisabled(const ASTContext &ctx) {
27662760
static bool checkAccessUsingAccessScopes(const DeclContext *useDC,
27672761
const ValueDecl *VD,
27682762
AccessLevel access) {
2769-
if (isAccessControlDisabled(VD->getASTContext()))
2763+
if (VD->getASTContext().isAccessControlDisabled())
27702764
return true;
27712765

27722766
AccessScope accessScope =
@@ -2788,7 +2782,7 @@ static bool checkAccessUsingAccessScopes(const DeclContext *useDC,
27882782
/// See ValueDecl::isAccessibleFrom for a description of \p forConformance.
27892783
static bool checkAccess(const DeclContext *useDC, const ValueDecl *VD,
27902784
AccessLevel access, bool forConformance) {
2791-
if (isAccessControlDisabled(VD->getASTContext()))
2785+
if (VD->getASTContext().isAccessControlDisabled())
27922786
return true;
27932787

27942788
auto *sourceDC = VD->getDeclContext();

lib/AST/ModuleNameLookup.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,8 @@ void namelookup::lookupInModule(ModuleDecl *startModule,
258258
ArrayRef<ModuleDecl::ImportedModule> extraImports) {
259259
assert(moduleScopeContext && moduleScopeContext->isModuleScopeContext());
260260
ModuleLookupCache cache;
261-
bool respectAccessControl = startModule->getASTContext().LangOpts
262-
.EnableAccessControl;
261+
bool respectAccessControl =
262+
!startModule->getASTContext().isAccessControlDisabled();
263263
::lookupInModule<CanTypeSet>(startModule, topAccessPath, decls,
264264
resolutionKind, /*canReturnEarly=*/true,
265265
typeResolver, cache, moduleScopeContext,
@@ -282,7 +282,7 @@ void namelookup::lookupVisibleDeclsInModule(
282282
ArrayRef<ModuleDecl::ImportedModule> extraImports) {
283283
assert(moduleScopeContext && moduleScopeContext->isModuleScopeContext());
284284
ModuleLookupCache cache;
285-
bool respectAccessControl = M->getASTContext().LangOpts.EnableAccessControl;
285+
bool respectAccessControl = !M->getASTContext().isAccessControlDisabled();
286286
::lookupInModule<NamedCanTypeSet>(M, accessPath, decls,
287287
resolutionKind, /*canReturnEarly=*/false,
288288
typeResolver, cache, moduleScopeContext,

lib/AST/NameLookup.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@ void DebuggerClient::anchor() {}
6565

6666
void AccessFilteringDeclConsumer::foundDecl(ValueDecl *D,
6767
DeclVisibilityKind reason) {
68-
if (D->getASTContext().LangOpts.EnableAccessControl) {
69-
if (D->isInvalid())
70-
return;
71-
if (!D->isAccessibleFrom(DC))
72-
return;
73-
}
68+
if (D->isInvalid())
69+
return;
70+
if (!D->isAccessibleFrom(DC))
71+
return;
72+
7473
ChainedConsumer.foundDecl(D, reason);
7574
}
7675

@@ -1843,7 +1842,7 @@ static void configureLookup(const DeclContext *dc,
18431842
ReferencedNameTracker *&tracker,
18441843
bool &isLookupCascading) {
18451844
auto &ctx = dc->getASTContext();
1846-
if (!ctx.LangOpts.EnableAccessControl)
1845+
if (ctx.isAccessControlDisabled())
18471846
options |= NL_IgnoreAccessControl;
18481847

18491848
// Find the dependency tracker we'll need for this lookup.

lib/PrintAsObjC/PrintAsObjC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1122,7 +1122,7 @@ class ObjCPrinter : private DeclVisitor<ObjCPrinter>,
11221122

11231123
ASTContext &ctx = M.getASTContext();
11241124
bool isSettable = VD->isSettable(nullptr);
1125-
if (isSettable && ctx.LangOpts.EnableAccessControl)
1125+
if (isSettable && !ctx.isAccessControlDisabled())
11261126
isSettable = (VD->getSetterFormalAccess() >= minRequiredAccess);
11271127
if (!isSettable)
11281128
os << ", readonly";

lib/Sema/TypeCheckAccess.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ void AccessControlCheckerBase::checkTypeAccessImpl(
160160
Type type, TypeRepr *typeRepr, AccessScope contextAccessScope,
161161
const DeclContext *useDC, bool mayBeInferred,
162162
llvm::function_ref<CheckTypeAccessCallback> diagnose) {
163-
if (!TC.getLangOpts().EnableAccessControl)
163+
if (TC.Context.isAccessControlDisabled())
164164
return;
165165
if (!type)
166166
return;

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2775,7 +2775,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
27752775
}
27762776
}
27772777

2778-
if (TC.getLangOpts().EnableAccessControl) {
2778+
if (!TC.Context.isAccessControlDisabled()) {
27792779
// Require the superclass to be open if this is outside its
27802780
// defining module. But don't emit another diagnostic if we
27812781
// already complained about the class being inherently

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ SmallVector<OverrideMatch, 2> OverrideMatcher::match(
761761

762762
static void checkOverrideAccessControl(ValueDecl *baseDecl, ValueDecl *decl,
763763
ASTContext &ctx) {
764-
if (!ctx.LangOpts.EnableAccessControl)
764+
if (ctx.isAccessControlDisabled())
765765
return;
766766

767767
auto &diags = ctx.Diags;
@@ -1479,7 +1479,7 @@ static bool checkSingleOverride(ValueDecl *override, ValueDecl *base) {
14791479
// read-only. Observing properties look at change, read-only properties
14801480
// have nothing to observe!
14811481
bool baseIsSettable = baseASD->isSettable(baseASD->getDeclContext());
1482-
if (baseIsSettable && ctx.LangOpts.EnableAccessControl) {
1482+
if (baseIsSettable) {
14831483
baseIsSettable =
14841484
baseASD->isSetterAccessibleFrom(overrideASD->getDeclContext());
14851485
}

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ namespace {
9090
bool isMemberLookup)
9191
: Result(result), DC(dc), Options(options),
9292
IsMemberLookup(isMemberLookup) {
93-
if (!dc->getASTContext().LangOpts.EnableAccessControl)
93+
if (dc->getASTContext().isAccessControlDisabled())
9494
Options |= NameLookupFlags::IgnoreAccessControl;
9595
}
9696

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1274,7 +1274,7 @@ bool WitnessChecker::checkWitnessAccess(ValueDecl *requirement,
12741274
ValueDecl *witness,
12751275
bool *isSetter) {
12761276
*isSetter = false;
1277-
if (!TC.getLangOpts().EnableAccessControl)
1277+
if (TC.Context.isAccessControlDisabled())
12781278
return false;
12791279

12801280
AccessScope actualScopeToCheck = getRequiredAccessScope();

lib/Sema/TypeCheckProtocol.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ class WitnessChecker {
497497
AccessScope getRequiredAccessScope();
498498

499499
bool isUsableFromInlineRequired() {
500-
if (!TC.getLangOpts().EnableAccessControl)
500+
if (TC.Context.isAccessControlDisabled())
501501
return false;
502502

503503
assert(RequiredAccessScopeAndUsableFromInline.hasValue() &&

0 commit comments

Comments
 (0)