Skip to content

Commit bbd79a2

Browse files
committed
ASTScope: unqualifiedLookup() entry point does not need the name
If we're searching for a declaration with a given name, the name should be entirely encapsulated inside the DeclConsumer. Otherwise, there might not be a specific name at all, if we're performing code completion for example (once LookupVisibleDecls starts to use ASTScope, anyway).
1 parent 360afd6 commit bbd79a2

File tree

5 files changed

+11
-16
lines changed

5 files changed

+11
-16
lines changed

include/swift/AST/ASTScope.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ class ASTScopeImpl {
354354

355355
/// Entry point into ASTScopeImpl-land for lookups
356356
static void
357-
unqualifiedLookup(SourceFile *, DeclNameRef, SourceLoc, DeclConsumer);
357+
unqualifiedLookup(SourceFile *, SourceLoc, DeclConsumer);
358358

359359
/// Entry point into ASTScopeImpl-land for labeled statement lookups.
360360
static llvm::SmallVector<LabeledStmt *, 4>
@@ -366,7 +366,6 @@ class ASTScopeImpl {
366366
#pragma mark - - lookup- starting point
367367
private:
368368
static const ASTScopeImpl *findStartingScopeForLookup(SourceFile *,
369-
const DeclNameRef name,
370369
const SourceLoc where);
371370

372371
protected:

include/swift/AST/NameLookup.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ class ASTScope {
681681
/// Flesh out the tree for dumping
682682
void buildFullyExpandedTree();
683683

684-
static void unqualifiedLookup(SourceFile *, DeclNameRef, SourceLoc,
684+
static void unqualifiedLookup(SourceFile *, SourceLoc,
685685
namelookup::AbstractASTScopeDeclConsumer &);
686686

687687
/// Entry point to record the visible statement labels from the given

lib/AST/ASTScope.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ using namespace ast_scope;
3939
#pragma mark ASTScope
4040

4141
void ASTScope::unqualifiedLookup(
42-
SourceFile *SF, DeclNameRef name, SourceLoc loc,
42+
SourceFile *SF, SourceLoc loc,
4343
namelookup::AbstractASTScopeDeclConsumer &consumer) {
4444
if (auto *s = SF->getASTContext().Stats)
4545
++s->getFrontendCounters().NumASTScopeLookups;
46-
ASTScopeImpl::unqualifiedLookup(SF, name, loc, consumer);
46+
ASTScopeImpl::unqualifiedLookup(SF, loc, consumer);
4747
}
4848

4949
llvm::SmallVector<LabeledStmt *, 4> ASTScope::lookupLabeledStmts(

lib/AST/ASTScopeLookup.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,16 @@ using namespace namelookup;
3636
using namespace ast_scope;
3737

3838
void ASTScopeImpl::unqualifiedLookup(
39-
SourceFile *sourceFile, const DeclNameRef name, const SourceLoc loc,
40-
DeclConsumer consumer) {
39+
SourceFile *sourceFile, const SourceLoc loc, DeclConsumer consumer) {
4140
const auto *start =
42-
findStartingScopeForLookup(sourceFile, name, loc);
41+
findStartingScopeForLookup(sourceFile, loc);
4342
if (start)
4443
start->lookup(nullptr, nullptr, consumer);
4544
}
4645

4746
const ASTScopeImpl *ASTScopeImpl::findStartingScopeForLookup(
48-
SourceFile *sourceFile, const DeclNameRef name, const SourceLoc loc) {
47+
SourceFile *sourceFile, const SourceLoc loc) {
4948
auto *const fileScope = sourceFile->getScope().impl;
50-
// Parser may have added decls to source file, since previous lookup
51-
if (name.isOperator())
52-
return fileScope; // operators always at file scope
53-
5449
const auto *innermost = fileScope->findInnermostEnclosingScope(loc, nullptr);
5550
ASTScopeAssert(innermost->getWasExpanded(),
5651
"If looking in a scope, it must have been expanded.");

lib/AST/UnqualifiedLookup.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ void UnqualifiedLookupFactory::performUnqualifiedLookup() {
303303
DC->getParentSourceFile());
304304

305305
if (Loc.isValid()) {
306-
lookInASTScopes();
306+
// Operator lookup is always global, for the time being.
307+
if (!Name.isOperator())
308+
lookInASTScopes();
307309
} else {
308310
assert(DC->isModuleScopeContext() &&
309311
"Unqualified lookup without a source location must start from "
@@ -543,8 +545,7 @@ void UnqualifiedLookupFactory::lookInASTScopes() {
543545
stopForDebuggingIfStartingTargetLookup(true);
544546
#endif
545547

546-
ASTScope::unqualifiedLookup(DC->getParentSourceFile(),
547-
Name, Loc, consumer);
548+
ASTScope::unqualifiedLookup(DC->getParentSourceFile(), Loc, consumer);
548549
}
549550

550551
void ASTScopeDeclConsumerForUnqualifiedLookup::maybeUpdateSelfDC(

0 commit comments

Comments
 (0)