Skip to content

Commit 9a57554

Browse files
committed
[NFC] DeclNameRef-ify qualified and unqualified lookup
1 parent 4b9a219 commit 9a57554

File tree

6 files changed

+41
-26
lines changed

6 files changed

+41
-26
lines changed

include/swift/AST/DeclContext.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
505505
/// lookup.
506506
///
507507
/// \returns true if anything was found.
508-
bool lookupQualified(Type type, DeclName member, NLOptions options,
508+
bool lookupQualified(Type type, DeclNameRef member, NLOptions options,
509509
SmallVectorImpl<ValueDecl *> &decls) const;
510510

511511
/// Look for the set of declarations with the given name within the
@@ -522,12 +522,13 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
522522
/// lookup.
523523
///
524524
/// \returns true if anything was found.
525-
bool lookupQualified(ArrayRef<NominalTypeDecl *> types, DeclName member,
525+
bool lookupQualified(ArrayRef<NominalTypeDecl *> types, DeclNameRef member,
526526
NLOptions options,
527527
SmallVectorImpl<ValueDecl *> &decls) const;
528528

529529
/// Perform qualified lookup for the given member in the given module.
530-
bool lookupQualified(ModuleDecl *module, DeclName member, NLOptions options,
530+
bool lookupQualified(ModuleDecl *module, DeclNameRef member,
531+
NLOptions options,
531532
SmallVectorImpl<ValueDecl *> &decls) const;
532533

533534
/// Look up all Objective-C methods with the given selector visible

include/swift/AST/NameLookupRequests.h

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,20 @@ class UnqualifiedLookupDescriptor {
321321
SourceLoc Loc;
322322
LookupOptions Options;
323323

324-
UnqualifiedLookupDescriptor(DeclName name, DeclContext *dc,
324+
/// Transitional entry point.
325+
[[deprecated]] UnqualifiedLookupDescriptor(DeclName name, DeclContext *dc,
325326
SourceLoc loc = SourceLoc(),
326327
LookupOptions options = {})
327328
: Name(name), DC(dc), Loc(loc), Options(options) {}
328329

330+
#pragma clang diagnostic push
331+
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
332+
UnqualifiedLookupDescriptor(DeclNameRef name, DeclContext *dc,
333+
SourceLoc loc = SourceLoc(),
334+
LookupOptions options = {})
335+
: UnqualifiedLookupDescriptor(name.getFullName(), dc, loc, options) { }
336+
#pragma clang diagnostic pop
337+
329338
friend llvm::hash_code hash_value(const UnqualifiedLookupDescriptor &desc) {
330339
return llvm::hash_combine(desc.Name, desc.DC, desc.Loc,
331340
desc.Options.toRaw());
@@ -389,8 +398,8 @@ class LookupInModuleRequest
389398
/// Perform \c AnyObject lookup for a given member.
390399
class AnyObjectLookupRequest
391400
: public SimpleRequest<AnyObjectLookupRequest,
392-
QualifiedLookupResult(const DeclContext *, DeclName,
393-
NLOptions),
401+
QualifiedLookupResult(const DeclContext *,
402+
DeclNameRef, NLOptions),
394403
CacheKind::Uncached> {
395404
public:
396405
using SimpleRequest::SimpleRequest;
@@ -400,7 +409,7 @@ class AnyObjectLookupRequest
400409

401410
llvm::Expected<QualifiedLookupResult> evaluate(Evaluator &evaluator,
402411
const DeclContext *dc,
403-
DeclName name,
412+
DeclNameRef name,
404413
NLOptions options) const;
405414
};
406415

lib/AST/NameLookup.cpp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ static void extractDirectlyReferencedNominalTypes(
15591559
}
15601560

15611561
bool DeclContext::lookupQualified(Type type,
1562-
DeclName member,
1562+
DeclNameRef member,
15631563
NLOptions options,
15641564
SmallVectorImpl<ValueDecl *> &decls) const {
15651565
using namespace namelookup;
@@ -1584,7 +1584,7 @@ bool DeclContext::lookupQualified(Type type,
15841584
}
15851585

15861586
bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,
1587-
DeclName member,
1587+
DeclNameRef member,
15881588
NLOptions options,
15891589
SmallVectorImpl<ValueDecl *> &decls) const {
15901590
using namespace namelookup;
@@ -1639,7 +1639,7 @@ bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,
16391639
auto flags = OptionSet<NominalTypeDecl::LookupDirectFlags>();
16401640
if (options & NL_IncludeAttributeImplements)
16411641
flags |= NominalTypeDecl::LookupDirectFlags::IncludeAttrImplements;
1642-
for (auto decl : current->lookupDirect(member, flags)) {
1642+
for (auto decl : current->lookupDirect(member.getFullName(), flags)) {
16431643
// If we're performing a type lookup, don't even attempt to validate
16441644
// the decl if its not a type.
16451645
if ((options & NL_OnlyTypes) && !isa<TypeDecl>(decl))
@@ -1708,14 +1708,14 @@ bool DeclContext::lookupQualified(ArrayRef<NominalTypeDecl *> typeDecls,
17081708

17091709
pruneLookupResultSet(this, options, decls);
17101710
if (auto *debugClient = this->getParentModule()->getDebugClient()) {
1711-
debugClient->finishLookupInNominals(this, typeDecls, member, options,
1712-
decls);
1711+
debugClient->finishLookupInNominals(this, typeDecls, member.getFullName(),
1712+
options, decls);
17131713
}
17141714
// We're done. Report success/failure.
17151715
return !decls.empty();
17161716
}
17171717

1718-
bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member,
1718+
bool DeclContext::lookupQualified(ModuleDecl *module, DeclNameRef member,
17191719
NLOptions options,
17201720
SmallVectorImpl<ValueDecl *> &decls) const {
17211721
using namespace namelookup;
@@ -1736,9 +1736,10 @@ bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member,
17361736
auto topLevelScope = getModuleScopeContext();
17371737
if (module == topLevelScope->getParentModule()) {
17381738
if (tracker) {
1739-
recordLookupOfTopLevelName(topLevelScope, member, isLookupCascading);
1739+
recordLookupOfTopLevelName(topLevelScope, member.getFullName(),
1740+
isLookupCascading);
17401741
}
1741-
lookupInModule(module, member, decls,
1742+
lookupInModule(module, member.getFullName(), decls,
17421743
NLKind::QualifiedLookup, kind, topLevelScope);
17431744
} else {
17441745
// Note: This is a lookup into another module. Unless we're compiling
@@ -1751,25 +1752,27 @@ bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member,
17511752
module, topLevelScope);
17521753
if (llvm::any_of(accessPaths,
17531754
[&](ModuleDecl::AccessPathTy accessPath) {
1754-
return ModuleDecl::matchesAccessPath(accessPath, member);
1755+
return ModuleDecl::matchesAccessPath(accessPath,
1756+
member.getFullName());
17551757
})) {
1756-
lookupInModule(module, member, decls,
1758+
lookupInModule(module, member.getFullName(), decls,
17571759
NLKind::QualifiedLookup, kind, topLevelScope);
17581760
}
17591761
}
17601762

17611763
pruneLookupResultSet(this, options, decls);
17621764

17631765
if (auto *debugClient = this->getParentModule()->getDebugClient()) {
1764-
debugClient->finishLookupInModule(this, module, member, options, decls);
1766+
debugClient->finishLookupInModule(this, module, member.getFullName(),
1767+
options, decls);
17651768
}
17661769
// We're done. Report success/failure.
17671770
return !decls.empty();
17681771
}
17691772

17701773
llvm::Expected<QualifiedLookupResult>
17711774
AnyObjectLookupRequest::evaluate(Evaluator &evaluator, const DeclContext *dc,
1772-
DeclName member, NLOptions options) const {
1775+
DeclNameRef member, NLOptions options) const {
17731776
using namespace namelookup;
17741777
QualifiedLookupResult decls;
17751778

@@ -1789,7 +1792,8 @@ AnyObjectLookupRequest::evaluate(Evaluator &evaluator, const DeclContext *dc,
17891792
// Collect all of the visible declarations.
17901793
SmallVector<ValueDecl *, 4> allDecls;
17911794
for (auto import : namelookup::getAllImports(dc)) {
1792-
import.second->lookupClassMember(import.first, member, allDecls);
1795+
import.second->lookupClassMember(import.first, member.getFullName(),
1796+
allDecls);
17931797
}
17941798

17951799
// For each declaration whose context is not something we've
@@ -1820,7 +1824,8 @@ AnyObjectLookupRequest::evaluate(Evaluator &evaluator, const DeclContext *dc,
18201824

18211825
pruneLookupResultSet(dc, options, decls);
18221826
if (auto *debugClient = dc->getParentModule()->getDebugClient()) {
1823-
debugClient->finishLookupInAnyObject(dc, member, options, decls);
1827+
debugClient->finishLookupInAnyObject(dc, member.getFullName(), options,
1828+
decls);
18241829
}
18251830
return decls;
18261831
}
@@ -1934,7 +1939,7 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
19341939

19351940
/// Perform unqualified name lookup for types at the given location.
19361941
static DirectlyReferencedTypeDecls
1937-
directReferencesForUnqualifiedTypeLookup(DeclName name,
1942+
directReferencesForUnqualifiedTypeLookup(DeclNameRef name,
19381943
SourceLoc loc, DeclContext *dc,
19391944
LookupOuterResults lookupOuter) {
19401945
DirectlyReferencedTypeDecls results;
@@ -1961,7 +1966,7 @@ static DirectlyReferencedTypeDecls
19611966
directReferencesForQualifiedTypeLookup(Evaluator &evaluator,
19621967
ASTContext &ctx,
19631968
ArrayRef<TypeDecl *> baseTypes,
1964-
DeclName name,
1969+
DeclNameRef name,
19651970
DeclContext *dc) {
19661971
DirectlyReferencedTypeDecls result;
19671972
auto addResults = [&result](ArrayRef<ValueDecl *> found){

lib/Immediate/REPL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1092,7 +1092,7 @@ class REPLEnvironment {
10921092
ASTContext &ctx = CI.getASTContext();
10931093
SourceFile &SF =
10941094
MostRecentModule->getMainSourceFile(SourceFileKind::REPL);
1095-
auto name = ctx.getIdentifier(Tok.getText());
1095+
DeclName name = ctx.getIdentifier(Tok.getText());
10961096
auto descriptor = UnqualifiedLookupDescriptor(name, &SF);
10971097
auto lookup = evaluateOrDefault(
10981098
ctx.evaluator, UnqualifiedLookupRequest{descriptor}, {});

lib/ParseSIL/ParseSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@ lookupTopDecl(Parser &P, DeclBaseName Name, bool typeLookup) {
11871187
options |= UnqualifiedLookupFlags::TypeLookup;
11881188

11891189
auto &ctx = P.SF.getASTContext();
1190-
auto descriptor = UnqualifiedLookupDescriptor(Name, &P.SF);
1190+
auto descriptor = UnqualifiedLookupDescriptor(DeclName(Name), &P.SF);
11911191
auto lookup = evaluateOrDefault(ctx.evaluator,
11921192
UnqualifiedLookupRequest{descriptor}, {});
11931193
assert(lookup.size() == 1);

lib/Sema/MiscDiagnostics.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ static void diagSyntacticUseRestrictions(const Expr *E, const DeclContext *DC,
533533

534534
DeclContext *topLevelContext = DC->getModuleScopeContext();
535535
auto descriptor = UnqualifiedLookupDescriptor(
536-
VD->getBaseName(), topLevelContext, SourceLoc(),
536+
DeclName(VD->getBaseName()), topLevelContext, SourceLoc(),
537537
UnqualifiedLookupFlags::KnownPrivate);
538538
auto lookup = evaluateOrDefault(Ctx.evaluator,
539539
UnqualifiedLookupRequest{descriptor}, {});

0 commit comments

Comments
 (0)