Skip to content

Sema: Remove dead code from access level computation rework #17817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions include/swift/AST/LazyResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,6 @@ class LazyResolver {
virtual void resolveWitness(const NormalProtocolConformance *conformance,
ValueDecl *requirement) = 0;

/// Resolve the access of a value.
///
/// It does no type-checking.
virtual void resolveAccessControl(ValueDecl *VD) = 0;

/// Resolve the type and declaration attributes of a value.
///
/// This can be called when the type or signature of a value is needed.
Expand Down
7 changes: 3 additions & 4 deletions include/swift/AST/NameLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -267,12 +267,11 @@ class NamedDeclConsumer : public VisibleDeclConsumer {
class AccessFilteringDeclConsumer final : public VisibleDeclConsumer {
const DeclContext *DC;
VisibleDeclConsumer &ChainedConsumer;
LazyResolver *TypeResolver;

public:
AccessFilteringDeclConsumer(const DeclContext *DC,
VisibleDeclConsumer &consumer,
LazyResolver *typeResolver)
: DC(DC), ChainedConsumer(consumer), TypeResolver(typeResolver) {}
VisibleDeclConsumer &consumer)
: DC(DC), ChainedConsumer(consumer) {}

void foundDecl(ValueDecl *D, DeclVisibilityKind reason) override;
};
Expand Down
5 changes: 1 addition & 4 deletions lib/AST/LookupVisibleDecls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ static bool isDeclVisibleInLookupMode(ValueDecl *Member, LookupState LS,

if (TypeResolver) {
TypeResolver->resolveDeclSignature(Member);
TypeResolver->resolveAccessControl(Member);
}

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

if (TypeResolver) {
TypeResolver->resolveDeclSignature(VD);
TypeResolver->resolveAccessControl(VD);
}

if (VD->isInvalid()) {
Expand Down
5 changes: 0 additions & 5 deletions lib/AST/ModuleNameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,6 @@ static void lookupInModule(ModuleDecl *module, ModuleDecl::AccessPathTy accessPa
if (respectAccessControl) {
auto newEndIter = std::remove_if(localDecls.begin(), localDecls.end(),
[=](ValueDecl *VD) {
if (typeResolver) {
typeResolver->resolveAccessControl(VD);
}
if (!VD->hasAccess())
return false;
return !VD->isAccessibleFrom(moduleScopeContext);
});
localDecls.erase(newEndIter, localDecls.end());
Expand Down
7 changes: 1 addition & 6 deletions lib/AST/NameLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ void DebuggerClient::anchor() {}
void AccessFilteringDeclConsumer::foundDecl(ValueDecl *D,
DeclVisibilityKind reason) {
if (D->getASTContext().LangOpts.EnableAccessControl) {
if (TypeResolver)
TypeResolver->resolveAccessControl(D);
if (D->isInvalid() && !D->hasAccess())
if (D->isInvalid())
return;
if (!D->isAccessibleFrom(DC))
return;
Expand Down Expand Up @@ -1779,9 +1777,6 @@ bool DeclContext::lookupQualified(Type type,

// Check access.
if (!(options & NL_IgnoreAccessControl)) {
if (typeResolver)
typeResolver->resolveAccessControl(decl);

return decl->isAccessibleFrom(this);
}

Expand Down
6 changes: 2 additions & 4 deletions lib/IDE/CodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4143,8 +4143,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
: LookupKind::ValueInDeclContext;
NeedLeadingDot = false;
ModuleDecl *M = CurrDeclContext->getParentModule();
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this,
TypeResolver.get());
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this);
M->lookupVisibleDecls({}, FilteringConsumer, NLKind::UnqualifiedLookup);
}

Expand All @@ -4159,8 +4158,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
LookupAccessPath.push_back(
std::make_pair(Ctx.getIdentifier(Piece), SourceLoc()));
}
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this,
TypeResolver.get());
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this);
TheModule->lookupVisibleDecls(LookupAccessPath, FilteringConsumer,
NLKind::UnqualifiedLookup);
}
Expand Down
16 changes: 5 additions & 11 deletions lib/Sema/TypeCheckDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3689,7 +3689,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
if (hasEnabledForbiddenTypecheckPrefix())
checkForForbiddenPrefix(D);

validateAccessControl(D);
(void) D->getFormalAccess();

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

validateAccessControl(aliasDecl);
(void) aliasDecl->getFormalAccess();

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

checkDeclAttributesEarly(EED);
validateAccessControl(EED);

validateAttributes(*this, EED);

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

validateAccessControl(proto);
(void) proto->getFormalAccess();

// Record inherited protocols.
resolveInheritedProtocols(proto);
Expand Down Expand Up @@ -4712,7 +4710,7 @@ void TypeChecker::validateDeclForNameLookup(ValueDecl *D) {
if (assocType->hasInterfaceType())
return;
assocType->computeType();
validateAccessControl(assocType);
(void) assocType->getFormalAccess();
break;
}
case DeclKind::TypeAlias: {
Expand All @@ -4728,7 +4726,7 @@ void TypeChecker::validateDeclForNameLookup(ValueDecl *D) {
typealias->setIsBeingValidated();
SWIFT_DEFER { typealias->setIsBeingValidated(false); };

validateAccessControl(typealias);
(void) typealias->getFormalAccess();

ProtocolRequirementTypeResolver resolver;
TypeResolutionOptions options =
Expand Down Expand Up @@ -4899,10 +4897,6 @@ void TypeChecker::finalizeDecl(ValueDecl *decl) {
}
}

void TypeChecker::validateAccessControl(ValueDecl *D) {
(void) D->getFormalAccess();
}

bool swift::isPassThroughTypealias(TypeAliasDecl *typealias) {
// Pass-through only makes sense when the typealias refers to a nominal
// type.
Expand Down
7 changes: 0 additions & 7 deletions lib/Sema/TypeChecker.h
Original file line number Diff line number Diff line change
Expand Up @@ -1004,9 +1004,6 @@ class TypeChecker final : public LazyResolver {
/// Perform just enough validation for looking up names using the Decl.
void validateDeclForNameLookup(ValueDecl *D);

/// Resolves the access control of the given declaration.
void validateAccessControl(ValueDecl *D);

/// Validate the given extension declaration, ensuring that it
/// properly extends the nominal type it names.
void validateExtension(ExtensionDecl *ext);
Expand Down Expand Up @@ -1238,10 +1235,6 @@ class TypeChecker final : public LazyResolver {
/// Check the default arguments that occur within this value decl.
void checkDefaultArguments(ArrayRef<ParameterList *> params, ValueDecl *VD);

virtual void resolveAccessControl(ValueDecl *VD) override {
validateAccessControl(VD);
}

virtual void resolveDeclSignature(ValueDecl *VD) override {
validateDeclForNameLookup(VD);
}
Expand Down
3 changes: 0 additions & 3 deletions test/decl/class/circular_inheritance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,10 @@ class Outer3
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Left@
// CHECK-NEXT: `--{{.*}}AccessLevelRequest
// CHECK-NEXT: `--{{.*}}AccessLevelRequest
// CHECK-NEXT: `--{{.*}}AccessLevelRequest
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Right@
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest{{.*(cyclic dependency)}}

// CHECK-DOT: digraph Dependencies
Expand Down