Skip to content

Commit

Permalink
Remove DeclContext::isCascadingContextForLookup
Browse files Browse the repository at this point in the history
  • Loading branch information
CodaFi committed Sep 21, 2020
1 parent 7bee5ff commit 934f994
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 83 deletions.
8 changes: 0 additions & 8 deletions include/swift/AST/DeclContext.h
Expand Up @@ -508,14 +508,6 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
/// FIXME: do this for Protocols, too someday
bool canBeParentOfExtension() const;

/// Returns true if lookups within this context could affect downstream files.
///
/// \param functionsAreNonCascading If true, functions are considered non-
/// cascading contexts. If false, functions are considered non-cascading only
/// if implicitly or explicitly marked private. When concerned only with a
/// function's body, pass true.
bool isCascadingContextForLookup(bool functionsAreNonCascading) const;

/// Look for the set of declarations with the given name within a type,
/// its extensions and, optionally, its supertypes.
///
Expand Down
9 changes: 2 additions & 7 deletions lib/AST/ASTScopeLookup.cpp
Expand Up @@ -525,13 +525,9 @@ NullablePtr<const ASTScopeImpl> ASTScopeImpl::ancestorWithDeclSatisfying(

#pragma mark ifUnknownIsCascadingUseAccordingTo

static bool isCascadingUseAccordingTo(const DeclContext *const dc) {
return dc->isCascadingContextForLookup(false);
}

static bool ifUnknownIsCascadingUseAccordingTo(Optional<bool> isCascadingUse,
const DeclContext *const dc) {
return isCascadingUse.getValueOr(isCascadingUseAccordingTo(dc));
return isCascadingUse.getValueOr(false);
}

#pragma mark resolveIsCascadingUseForThisScope
Expand All @@ -550,8 +546,7 @@ Optional<bool> GenericParamScope::resolveIsCascadingUseForThisScope(

Optional<bool> AbstractFunctionDeclScope::resolveIsCascadingUseForThisScope(
Optional<bool> isCascadingUse) const {
return decl->isCascadingContextForLookup(false) &&
isCascadingUse.getValueOr(true);
return false;
}

Optional<bool> AbstractFunctionBodyScope::resolveIsCascadingUseForThisScope(
Expand Down
46 changes: 0 additions & 46 deletions lib/AST/DeclContext.cpp
Expand Up @@ -445,52 +445,6 @@ bool DeclContext::isInnermostContextGeneric() const {
return false;
}

bool
DeclContext::isCascadingContextForLookup(bool functionsAreNonCascading) const {
// FIXME: This is explicitly checking for attributes in some cases because
// it can be called before access control is computed.
switch (getContextKind()) {
case DeclContextKind::AbstractClosureExpr:
break;

case DeclContextKind::SerializedLocal:
llvm_unreachable("should not perform lookups in deserialized contexts");

case DeclContextKind::Initializer:
// Default arguments still require a type.
if (isa<DefaultArgumentInitializer>(this))
return false;
break;

case DeclContextKind::TopLevelCodeDecl:
// FIXME: Pattern initializers at top-level scope end up here.
return true;

case DeclContextKind::AbstractFunctionDecl:
if (functionsAreNonCascading)
return false;
break;

case DeclContextKind::SubscriptDecl:
break;

case DeclContextKind::EnumElementDecl:
break;

case DeclContextKind::Module:
case DeclContextKind::FileUnit:
return true;

case DeclContextKind::GenericTypeDecl:
break;

case DeclContextKind::ExtensionDecl:
return true;
}

return getParent()->isCascadingContextForLookup(true);
}

unsigned DeclContext::getSyntacticDepth() const {
// Module scope == depth 0.
if (isModuleScopeContext())
Expand Down
24 changes: 2 additions & 22 deletions lib/AST/NameLookupRequests.cpp
Expand Up @@ -371,18 +371,7 @@ swift::extractNearestSourceLoc(const LookupConformanceDescriptor &desc) {
evaluator::DependencySource ModuleQualifiedLookupRequest::readDependencySource(
const evaluator::DependencyRecorder &eval) const {
auto *DC = std::get<0>(getStorage());
auto options = std::get<3>(getStorage());

// FIXME(Evaluator Incremental Dependencies): This is an artifact of the
// current scheme and should be removed. There are very few callers that are
// accurately passing the right known dependencies mask.
const bool fromPrivateDC =
DC->isCascadingContextForLookup(/*functionsAreNonCascading=*/false);

auto scope = evaluator::DependencyScope::Cascading;
if (fromPrivateDC)
scope = evaluator::DependencyScope::Private;
return { DC->getParentSourceFile(), scope };
return { DC->getParentSourceFile(), evaluator::DependencyScope::Private };
}

void ModuleQualifiedLookupRequest::writeDependencySink(
Expand Down Expand Up @@ -453,18 +442,9 @@ void UnqualifiedLookupRequest::writeDependencySink(
evaluator::DependencySource QualifiedLookupRequest::readDependencySource(
const evaluator::DependencyRecorder &) const {
auto *dc = std::get<0>(getStorage());
auto opts = std::get<3>(getStorage());
// FIXME(Evaluator Incremental Dependencies): This is an artifact of the
// current scheme and should be removed. There are very few callers that are
// accurately passing the right known dependencies mask.
const bool cascades =
dc->isCascadingContextForLookup(/*functionsAreNonCascading*/ false);
auto scope = evaluator::DependencyScope::Cascading;
if (!cascades)
scope = evaluator::DependencyScope::Private;
return {
dyn_cast<SourceFile>(dc->getModuleScopeContext()),
scope
evaluator::DependencyScope::Private
};
}

Expand Down

0 comments on commit 934f994

Please sign in to comment.