Skip to content

Commit 536ca5c

Browse files
authored
Merge pull request #17817 from slavapestov/access-level-r-e-cleanup
Sema: Remove dead code from access level computation rework
2 parents 622a140 + 19de53f commit 536ca5c

File tree

9 files changed

+12
-49
lines changed

9 files changed

+12
-49
lines changed

include/swift/AST/LazyResolver.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@ class LazyResolver {
5353
virtual void resolveWitness(const NormalProtocolConformance *conformance,
5454
ValueDecl *requirement) = 0;
5555

56-
/// Resolve the access of a value.
57-
///
58-
/// It does no type-checking.
59-
virtual void resolveAccessControl(ValueDecl *VD) = 0;
60-
6156
/// Resolve the type and declaration attributes of a value.
6257
///
6358
/// This can be called when the type or signature of a value is needed.

include/swift/AST/NameLookup.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,12 +267,11 @@ class NamedDeclConsumer : public VisibleDeclConsumer {
267267
class AccessFilteringDeclConsumer final : public VisibleDeclConsumer {
268268
const DeclContext *DC;
269269
VisibleDeclConsumer &ChainedConsumer;
270-
LazyResolver *TypeResolver;
270+
271271
public:
272272
AccessFilteringDeclConsumer(const DeclContext *DC,
273-
VisibleDeclConsumer &consumer,
274-
LazyResolver *typeResolver)
275-
: DC(DC), ChainedConsumer(consumer), TypeResolver(typeResolver) {}
273+
VisibleDeclConsumer &consumer)
274+
: DC(DC), ChainedConsumer(consumer) {}
276275

277276
void foundDecl(ValueDecl *D, DeclVisibilityKind reason) override;
278277
};

lib/AST/LookupVisibleDecls.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ static bool isDeclVisibleInLookupMode(ValueDecl *Member, LookupState LS,
130130

131131
if (TypeResolver) {
132132
TypeResolver->resolveDeclSignature(Member);
133-
TypeResolver->resolveAccessControl(Member);
134133
}
135134

136135
// Check access when relevant.
@@ -615,8 +614,7 @@ static void lookupVisibleMemberDeclsImpl(
615614
// Lookup module references, as on some_module.some_member. These are
616615
// special and can't have extensions.
617616
if (ModuleType *MT = BaseTy->getAs<ModuleType>()) {
618-
AccessFilteringDeclConsumer FilteringConsumer(CurrDC, Consumer,
619-
TypeResolver);
617+
AccessFilteringDeclConsumer FilteringConsumer(CurrDC, Consumer);
620618
MT->getModule()->lookupVisibleDecls(ModuleDecl::AccessPathTy(),
621619
FilteringConsumer,
622620
NLKind::QualifiedLookup);
@@ -816,7 +814,6 @@ class OverrideFilteringConsumer : public VisibleDeclConsumer {
816814

817815
if (TypeResolver) {
818816
TypeResolver->resolveDeclSignature(VD);
819-
TypeResolver->resolveAccessControl(VD);
820817
}
821818

822819
if (VD->isInvalid()) {

lib/AST/ModuleNameLookup.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,6 @@ static void lookupInModule(ModuleDecl *module, ModuleDecl::AccessPathTy accessPa
171171
if (respectAccessControl) {
172172
auto newEndIter = std::remove_if(localDecls.begin(), localDecls.end(),
173173
[=](ValueDecl *VD) {
174-
if (typeResolver) {
175-
typeResolver->resolveAccessControl(VD);
176-
}
177-
if (!VD->hasAccess())
178-
return false;
179174
return !VD->isAccessibleFrom(moduleScopeContext);
180175
});
181176
localDecls.erase(newEndIter, localDecls.end());

lib/AST/NameLookup.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ void DebuggerClient::anchor() {}
6060
void AccessFilteringDeclConsumer::foundDecl(ValueDecl *D,
6161
DeclVisibilityKind reason) {
6262
if (D->getASTContext().LangOpts.EnableAccessControl) {
63-
if (TypeResolver)
64-
TypeResolver->resolveAccessControl(D);
65-
if (D->isInvalid() && !D->hasAccess())
63+
if (D->isInvalid())
6664
return;
6765
if (!D->isAccessibleFrom(DC))
6866
return;
@@ -1779,9 +1777,6 @@ bool DeclContext::lookupQualified(Type type,
17791777

17801778
// Check access.
17811779
if (!(options & NL_IgnoreAccessControl)) {
1782-
if (typeResolver)
1783-
typeResolver->resolveAccessControl(decl);
1784-
17851780
return decl->isAccessibleFrom(this);
17861781
}
17871782

lib/IDE/CodeCompletion.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4143,8 +4143,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
41434143
: LookupKind::ValueInDeclContext;
41444144
NeedLeadingDot = false;
41454145
ModuleDecl *M = CurrDeclContext->getParentModule();
4146-
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this,
4147-
TypeResolver.get());
4146+
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this);
41484147
M->lookupVisibleDecls({}, FilteringConsumer, NLKind::UnqualifiedLookup);
41494148
}
41504149

@@ -4159,8 +4158,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
41594158
LookupAccessPath.push_back(
41604159
std::make_pair(Ctx.getIdentifier(Piece), SourceLoc()));
41614160
}
4162-
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this,
4163-
TypeResolver.get());
4161+
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this);
41644162
TheModule->lookupVisibleDecls(LookupAccessPath, FilteringConsumer,
41654163
NLKind::UnqualifiedLookup);
41664164
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3689,7 +3689,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
36893689
if (hasEnabledForbiddenTypecheckPrefix())
36903690
checkForForbiddenPrefix(D);
36913691

3692-
validateAccessControl(D);
3692+
(void) D->getFormalAccess();
36933693

36943694
// Validate the context.
36953695
auto dc = D->getDeclContext();
@@ -3850,7 +3850,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
38503850
aliasDecl->getUnderlyingTypeLoc().setType(Type());
38513851
aliasDecl->setInterfaceType(Type());
38523852

3853-
validateAccessControl(aliasDecl);
3853+
(void) aliasDecl->getFormalAccess();
38543854

38553855
// Check generic parameters, if needed.
38563856
bool validated = aliasDecl->hasValidationStarted();
@@ -4596,8 +4596,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
45964596
auto *EED = cast<EnumElementDecl>(D);
45974597

45984598
checkDeclAttributesEarly(EED);
4599-
validateAccessControl(EED);
4600-
46014599
validateAttributes(*this, EED);
46024600

46034601
EED->setIsBeingValidated(true);
@@ -4684,7 +4682,7 @@ void TypeChecker::validateDeclForNameLookup(ValueDecl *D) {
46844682
for (auto paramDecl : *gp)
46854683
paramDecl->setDepth(depth);
46864684

4687-
validateAccessControl(proto);
4685+
(void) proto->getFormalAccess();
46884686

46894687
// Record inherited protocols.
46904688
resolveInheritedProtocols(proto);
@@ -4712,7 +4710,7 @@ void TypeChecker::validateDeclForNameLookup(ValueDecl *D) {
47124710
if (assocType->hasInterfaceType())
47134711
return;
47144712
assocType->computeType();
4715-
validateAccessControl(assocType);
4713+
(void) assocType->getFormalAccess();
47164714
break;
47174715
}
47184716
case DeclKind::TypeAlias: {
@@ -4728,7 +4726,7 @@ void TypeChecker::validateDeclForNameLookup(ValueDecl *D) {
47284726
typealias->setIsBeingValidated();
47294727
SWIFT_DEFER { typealias->setIsBeingValidated(false); };
47304728

4731-
validateAccessControl(typealias);
4729+
(void) typealias->getFormalAccess();
47324730

47334731
ProtocolRequirementTypeResolver resolver;
47344732
TypeResolutionOptions options =
@@ -4899,10 +4897,6 @@ void TypeChecker::finalizeDecl(ValueDecl *decl) {
48994897
}
49004898
}
49014899

4902-
void TypeChecker::validateAccessControl(ValueDecl *D) {
4903-
(void) D->getFormalAccess();
4904-
}
4905-
49064900
bool swift::isPassThroughTypealias(TypeAliasDecl *typealias) {
49074901
// Pass-through only makes sense when the typealias refers to a nominal
49084902
// type.

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,6 @@ class TypeChecker final : public LazyResolver {
10041004
/// Perform just enough validation for looking up names using the Decl.
10051005
void validateDeclForNameLookup(ValueDecl *D);
10061006

1007-
/// Resolves the access control of the given declaration.
1008-
void validateAccessControl(ValueDecl *D);
1009-
10101007
/// Validate the given extension declaration, ensuring that it
10111008
/// properly extends the nominal type it names.
10121009
void validateExtension(ExtensionDecl *ext);
@@ -1238,10 +1235,6 @@ class TypeChecker final : public LazyResolver {
12381235
/// Check the default arguments that occur within this value decl.
12391236
void checkDefaultArguments(ArrayRef<ParameterList *> params, ValueDecl *VD);
12401237

1241-
virtual void resolveAccessControl(ValueDecl *VD) override {
1242-
validateAccessControl(VD);
1243-
}
1244-
12451238
virtual void resolveDeclSignature(ValueDecl *VD) override {
12461239
validateDeclForNameLookup(VD);
12471240
}

test/decl/class/circular_inheritance.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,10 @@ class Outer3
5151
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Left@
5252
// CHECK-NEXT: `--{{.*}}AccessLevelRequest
5353
// CHECK-NEXT: `--{{.*}}AccessLevelRequest
54-
// CHECK-NEXT: `--{{.*}}AccessLevelRequest
5554
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest
5655
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Right@
5756
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
5857
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
59-
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
60-
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
6158
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest{{.*(cyclic dependency)}}
6259

6360
// CHECK-DOT: digraph Dependencies

0 commit comments

Comments
 (0)