mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Sema: Remove dead code from access level computation rework
This commit is contained in:
@@ -53,11 +53,6 @@ public:
|
|||||||
virtual void resolveWitness(const NormalProtocolConformance *conformance,
|
virtual void resolveWitness(const NormalProtocolConformance *conformance,
|
||||||
ValueDecl *requirement) = 0;
|
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.
|
/// Resolve the type and declaration attributes of a value.
|
||||||
///
|
///
|
||||||
/// This can be called when the type or signature of a value is needed.
|
/// This can be called when the type or signature of a value is needed.
|
||||||
|
|||||||
@@ -267,12 +267,11 @@ public:
|
|||||||
class AccessFilteringDeclConsumer final : public VisibleDeclConsumer {
|
class AccessFilteringDeclConsumer final : public VisibleDeclConsumer {
|
||||||
const DeclContext *DC;
|
const DeclContext *DC;
|
||||||
VisibleDeclConsumer &ChainedConsumer;
|
VisibleDeclConsumer &ChainedConsumer;
|
||||||
LazyResolver *TypeResolver;
|
|
||||||
public:
|
public:
|
||||||
AccessFilteringDeclConsumer(const DeclContext *DC,
|
AccessFilteringDeclConsumer(const DeclContext *DC,
|
||||||
VisibleDeclConsumer &consumer,
|
VisibleDeclConsumer &consumer)
|
||||||
LazyResolver *typeResolver)
|
: DC(DC), ChainedConsumer(consumer) {}
|
||||||
: DC(DC), ChainedConsumer(consumer), TypeResolver(typeResolver) {}
|
|
||||||
|
|
||||||
void foundDecl(ValueDecl *D, DeclVisibilityKind reason) override;
|
void foundDecl(ValueDecl *D, DeclVisibilityKind reason) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -130,7 +130,6 @@ static bool isDeclVisibleInLookupMode(ValueDecl *Member, LookupState LS,
|
|||||||
|
|
||||||
if (TypeResolver) {
|
if (TypeResolver) {
|
||||||
TypeResolver->resolveDeclSignature(Member);
|
TypeResolver->resolveDeclSignature(Member);
|
||||||
TypeResolver->resolveAccessControl(Member);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check access when relevant.
|
// Check access when relevant.
|
||||||
@@ -615,8 +614,7 @@ static void lookupVisibleMemberDeclsImpl(
|
|||||||
// Lookup module references, as on some_module.some_member. These are
|
// Lookup module references, as on some_module.some_member. These are
|
||||||
// special and can't have extensions.
|
// special and can't have extensions.
|
||||||
if (ModuleType *MT = BaseTy->getAs<ModuleType>()) {
|
if (ModuleType *MT = BaseTy->getAs<ModuleType>()) {
|
||||||
AccessFilteringDeclConsumer FilteringConsumer(CurrDC, Consumer,
|
AccessFilteringDeclConsumer FilteringConsumer(CurrDC, Consumer);
|
||||||
TypeResolver);
|
|
||||||
MT->getModule()->lookupVisibleDecls(ModuleDecl::AccessPathTy(),
|
MT->getModule()->lookupVisibleDecls(ModuleDecl::AccessPathTy(),
|
||||||
FilteringConsumer,
|
FilteringConsumer,
|
||||||
NLKind::QualifiedLookup);
|
NLKind::QualifiedLookup);
|
||||||
@@ -816,7 +814,6 @@ public:
|
|||||||
|
|
||||||
if (TypeResolver) {
|
if (TypeResolver) {
|
||||||
TypeResolver->resolveDeclSignature(VD);
|
TypeResolver->resolveDeclSignature(VD);
|
||||||
TypeResolver->resolveAccessControl(VD);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VD->isInvalid()) {
|
if (VD->isInvalid()) {
|
||||||
|
|||||||
@@ -171,11 +171,6 @@ static void lookupInModule(ModuleDecl *module, ModuleDecl::AccessPathTy accessPa
|
|||||||
if (respectAccessControl) {
|
if (respectAccessControl) {
|
||||||
auto newEndIter = std::remove_if(localDecls.begin(), localDecls.end(),
|
auto newEndIter = std::remove_if(localDecls.begin(), localDecls.end(),
|
||||||
[=](ValueDecl *VD) {
|
[=](ValueDecl *VD) {
|
||||||
if (typeResolver) {
|
|
||||||
typeResolver->resolveAccessControl(VD);
|
|
||||||
}
|
|
||||||
if (!VD->hasAccess())
|
|
||||||
return false;
|
|
||||||
return !VD->isAccessibleFrom(moduleScopeContext);
|
return !VD->isAccessibleFrom(moduleScopeContext);
|
||||||
});
|
});
|
||||||
localDecls.erase(newEndIter, localDecls.end());
|
localDecls.erase(newEndIter, localDecls.end());
|
||||||
|
|||||||
@@ -60,9 +60,7 @@ void DebuggerClient::anchor() {}
|
|||||||
void AccessFilteringDeclConsumer::foundDecl(ValueDecl *D,
|
void AccessFilteringDeclConsumer::foundDecl(ValueDecl *D,
|
||||||
DeclVisibilityKind reason) {
|
DeclVisibilityKind reason) {
|
||||||
if (D->getASTContext().LangOpts.EnableAccessControl) {
|
if (D->getASTContext().LangOpts.EnableAccessControl) {
|
||||||
if (TypeResolver)
|
if (D->isInvalid())
|
||||||
TypeResolver->resolveAccessControl(D);
|
|
||||||
if (D->isInvalid() && !D->hasAccess())
|
|
||||||
return;
|
return;
|
||||||
if (!D->isAccessibleFrom(DC))
|
if (!D->isAccessibleFrom(DC))
|
||||||
return;
|
return;
|
||||||
@@ -1779,9 +1777,6 @@ bool DeclContext::lookupQualified(Type type,
|
|||||||
|
|
||||||
// Check access.
|
// Check access.
|
||||||
if (!(options & NL_IgnoreAccessControl)) {
|
if (!(options & NL_IgnoreAccessControl)) {
|
||||||
if (typeResolver)
|
|
||||||
typeResolver->resolveAccessControl(decl);
|
|
||||||
|
|
||||||
return decl->isAccessibleFrom(this);
|
return decl->isAccessibleFrom(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4143,8 +4143,7 @@ public:
|
|||||||
: LookupKind::ValueInDeclContext;
|
: LookupKind::ValueInDeclContext;
|
||||||
NeedLeadingDot = false;
|
NeedLeadingDot = false;
|
||||||
ModuleDecl *M = CurrDeclContext->getParentModule();
|
ModuleDecl *M = CurrDeclContext->getParentModule();
|
||||||
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this,
|
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this);
|
||||||
TypeResolver.get());
|
|
||||||
M->lookupVisibleDecls({}, FilteringConsumer, NLKind::UnqualifiedLookup);
|
M->lookupVisibleDecls({}, FilteringConsumer, NLKind::UnqualifiedLookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4159,8 +4158,7 @@ public:
|
|||||||
LookupAccessPath.push_back(
|
LookupAccessPath.push_back(
|
||||||
std::make_pair(Ctx.getIdentifier(Piece), SourceLoc()));
|
std::make_pair(Ctx.getIdentifier(Piece), SourceLoc()));
|
||||||
}
|
}
|
||||||
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this,
|
AccessFilteringDeclConsumer FilteringConsumer(CurrDeclContext, *this);
|
||||||
TypeResolver.get());
|
|
||||||
TheModule->lookupVisibleDecls(LookupAccessPath, FilteringConsumer,
|
TheModule->lookupVisibleDecls(LookupAccessPath, FilteringConsumer,
|
||||||
NLKind::UnqualifiedLookup);
|
NLKind::UnqualifiedLookup);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3689,7 +3689,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
|
|||||||
if (hasEnabledForbiddenTypecheckPrefix())
|
if (hasEnabledForbiddenTypecheckPrefix())
|
||||||
checkForForbiddenPrefix(D);
|
checkForForbiddenPrefix(D);
|
||||||
|
|
||||||
validateAccessControl(D);
|
(void) D->getFormalAccess();
|
||||||
|
|
||||||
// Validate the context.
|
// Validate the context.
|
||||||
auto dc = D->getDeclContext();
|
auto dc = D->getDeclContext();
|
||||||
@@ -3850,7 +3850,7 @@ void TypeChecker::validateDecl(ValueDecl *D) {
|
|||||||
aliasDecl->getUnderlyingTypeLoc().setType(Type());
|
aliasDecl->getUnderlyingTypeLoc().setType(Type());
|
||||||
aliasDecl->setInterfaceType(Type());
|
aliasDecl->setInterfaceType(Type());
|
||||||
|
|
||||||
validateAccessControl(aliasDecl);
|
(void) aliasDecl->getFormalAccess();
|
||||||
|
|
||||||
// Check generic parameters, if needed.
|
// Check generic parameters, if needed.
|
||||||
bool validated = aliasDecl->hasValidationStarted();
|
bool validated = aliasDecl->hasValidationStarted();
|
||||||
@@ -4596,8 +4596,6 @@ void TypeChecker::validateDecl(ValueDecl *D) {
|
|||||||
auto *EED = cast<EnumElementDecl>(D);
|
auto *EED = cast<EnumElementDecl>(D);
|
||||||
|
|
||||||
checkDeclAttributesEarly(EED);
|
checkDeclAttributesEarly(EED);
|
||||||
validateAccessControl(EED);
|
|
||||||
|
|
||||||
validateAttributes(*this, EED);
|
validateAttributes(*this, EED);
|
||||||
|
|
||||||
EED->setIsBeingValidated(true);
|
EED->setIsBeingValidated(true);
|
||||||
@@ -4684,7 +4682,7 @@ void TypeChecker::validateDeclForNameLookup(ValueDecl *D) {
|
|||||||
for (auto paramDecl : *gp)
|
for (auto paramDecl : *gp)
|
||||||
paramDecl->setDepth(depth);
|
paramDecl->setDepth(depth);
|
||||||
|
|
||||||
validateAccessControl(proto);
|
(void) proto->getFormalAccess();
|
||||||
|
|
||||||
// Record inherited protocols.
|
// Record inherited protocols.
|
||||||
resolveInheritedProtocols(proto);
|
resolveInheritedProtocols(proto);
|
||||||
@@ -4712,7 +4710,7 @@ void TypeChecker::validateDeclForNameLookup(ValueDecl *D) {
|
|||||||
if (assocType->hasInterfaceType())
|
if (assocType->hasInterfaceType())
|
||||||
return;
|
return;
|
||||||
assocType->computeType();
|
assocType->computeType();
|
||||||
validateAccessControl(assocType);
|
(void) assocType->getFormalAccess();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DeclKind::TypeAlias: {
|
case DeclKind::TypeAlias: {
|
||||||
@@ -4728,7 +4726,7 @@ void TypeChecker::validateDeclForNameLookup(ValueDecl *D) {
|
|||||||
typealias->setIsBeingValidated();
|
typealias->setIsBeingValidated();
|
||||||
SWIFT_DEFER { typealias->setIsBeingValidated(false); };
|
SWIFT_DEFER { typealias->setIsBeingValidated(false); };
|
||||||
|
|
||||||
validateAccessControl(typealias);
|
(void) typealias->getFormalAccess();
|
||||||
|
|
||||||
ProtocolRequirementTypeResolver resolver;
|
ProtocolRequirementTypeResolver resolver;
|
||||||
TypeResolutionOptions options =
|
TypeResolutionOptions options =
|
||||||
@@ -4899,10 +4897,6 @@ void TypeChecker::finalizeDecl(ValueDecl *decl) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TypeChecker::validateAccessControl(ValueDecl *D) {
|
|
||||||
(void) D->getFormalAccess();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool swift::isPassThroughTypealias(TypeAliasDecl *typealias) {
|
bool swift::isPassThroughTypealias(TypeAliasDecl *typealias) {
|
||||||
// Pass-through only makes sense when the typealias refers to a nominal
|
// Pass-through only makes sense when the typealias refers to a nominal
|
||||||
// type.
|
// type.
|
||||||
|
|||||||
@@ -1004,9 +1004,6 @@ public:
|
|||||||
/// Perform just enough validation for looking up names using the Decl.
|
/// Perform just enough validation for looking up names using the Decl.
|
||||||
void validateDeclForNameLookup(ValueDecl *D);
|
void validateDeclForNameLookup(ValueDecl *D);
|
||||||
|
|
||||||
/// Resolves the access control of the given declaration.
|
|
||||||
void validateAccessControl(ValueDecl *D);
|
|
||||||
|
|
||||||
/// Validate the given extension declaration, ensuring that it
|
/// Validate the given extension declaration, ensuring that it
|
||||||
/// properly extends the nominal type it names.
|
/// properly extends the nominal type it names.
|
||||||
void validateExtension(ExtensionDecl *ext);
|
void validateExtension(ExtensionDecl *ext);
|
||||||
@@ -1238,10 +1235,6 @@ public:
|
|||||||
/// Check the default arguments that occur within this value decl.
|
/// Check the default arguments that occur within this value decl.
|
||||||
void checkDefaultArguments(ArrayRef<ParameterList *> params, ValueDecl *VD);
|
void checkDefaultArguments(ArrayRef<ParameterList *> params, ValueDecl *VD);
|
||||||
|
|
||||||
virtual void resolveAccessControl(ValueDecl *VD) override {
|
|
||||||
validateAccessControl(VD);
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void resolveDeclSignature(ValueDecl *VD) override {
|
virtual void resolveDeclSignature(ValueDecl *VD) override {
|
||||||
validateDeclForNameLookup(VD);
|
validateDeclForNameLookup(VD);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,13 +51,10 @@ class Outer3
|
|||||||
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Left@
|
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Left@
|
||||||
// CHECK-NEXT: `--{{.*}}AccessLevelRequest
|
// CHECK-NEXT: `--{{.*}}AccessLevelRequest
|
||||||
// CHECK-NEXT: `--{{.*}}AccessLevelRequest
|
// CHECK-NEXT: `--{{.*}}AccessLevelRequest
|
||||||
// CHECK-NEXT: `--{{.*}}AccessLevelRequest
|
|
||||||
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest
|
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest
|
||||||
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Right@
|
// CHECK-NEXT: `--{{.*}}InheritedTypeRequest(circular_inheritance.(file).Right@
|
||||||
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
|
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
|
||||||
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
|
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
|
||||||
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
|
|
||||||
// CHECK-NEXT: `--{{.*}}AccessLevelRequest{{.*}}
|
|
||||||
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest{{.*(cyclic dependency)}}
|
// CHECK-NEXT: `--{{.*}}SuperclassTypeRequest{{.*(cyclic dependency)}}
|
||||||
|
|
||||||
// CHECK-DOT: digraph Dependencies
|
// CHECK-DOT: digraph Dependencies
|
||||||
|
|||||||
Reference in New Issue
Block a user