Sema: Remove dead code from access level computation rework

This commit is contained in:
Slava Pestov
2018-07-06 22:42:11 -07:00
parent 238aa2d3a5
commit 19de53f6cf
9 changed files with 12 additions and 49 deletions

View File

@@ -53,11 +53,6 @@ public:
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.

View File

@@ -267,12 +267,11 @@ public:
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;
};

View File

@@ -130,7 +130,6 @@ static bool isDeclVisibleInLookupMode(ValueDecl *Member, LookupState LS,
if (TypeResolver) {
TypeResolver->resolveDeclSignature(Member);
TypeResolver->resolveAccessControl(Member);
}
// Check access when relevant.
@@ -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);
@@ -816,7 +814,6 @@ public:
if (TypeResolver) {
TypeResolver->resolveDeclSignature(VD);
TypeResolver->resolveAccessControl(VD);
}
if (VD->isInvalid()) {

View File

@@ -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());

View File

@@ -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;
@@ -1779,9 +1777,6 @@ bool DeclContext::lookupQualified(Type type,
// Check access.
if (!(options & NL_IgnoreAccessControl)) {
if (typeResolver)
typeResolver->resolveAccessControl(decl);
return decl->isAccessibleFrom(this);
}

View File

@@ -4143,8 +4143,7 @@ public:
: LookupKind::ValueInDeclContext;
NeedLeadingDot = false;
ModuleDecl *M = CurrDeclContext->getParentModule();
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this,
TypeResolver.get());
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this);
M->lookupVisibleDecls({}, FilteringConsumer, NLKind::UnqualifiedLookup);
}
@@ -4159,8 +4158,7 @@ public:
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);
}

View File

@@ -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();
@@ -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();
@@ -4596,8 +4596,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
auto *EED = cast<EnumElementDecl>(D);
checkDeclAttributesEarly(EED);
validateAccessControl(EED);
validateAttributes(*this, EED);
EED->setIsBeingValidated(true);
@@ -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);
@@ -4712,7 +4710,7 @@ void TypeChecker::validateDeclForNameLookup(ValueDecl *D) {
if (assocType->hasInterfaceType())
return;
assocType->computeType();
validateAccessControl(assocType);
(void) assocType->getFormalAccess();
break;
}
case DeclKind::TypeAlias: {
@@ -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 =
@@ -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.

View File

@@ -1004,9 +1004,6 @@ public:
/// 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);
@@ -1238,10 +1235,6 @@ public:
/// 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);
}

View File

@@ -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