Skip to content

Commit da88512

Browse files
committed
[NFC] Take DeclNameRef in UnqualifiedLookup and lookupQualified()
1 parent 9a57554 commit da88512

25 files changed

+64
-68
lines changed

include/swift/AST/ASTScope.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ class ASTScopeImpl {
412412

413413
/// Entry point into ASTScopeImpl-land for lookups
414414
static llvm::SmallVector<const ASTScopeImpl *, 0>
415-
unqualifiedLookup(SourceFile *, DeclName, SourceLoc,
415+
unqualifiedLookup(SourceFile *, DeclNameRef, SourceLoc,
416416
const DeclContext *startingContext, DeclConsumer);
417417

418418
static Optional<bool>
@@ -422,7 +422,7 @@ class ASTScopeImpl {
422422
#pragma mark - - lookup- starting point
423423
private:
424424
static const ASTScopeImpl *findStartingScopeForLookup(SourceFile *,
425-
const DeclName name,
425+
const DeclNameRef name,
426426
const SourceLoc where,
427427
const DeclContext *ctx);
428428

include/swift/AST/DiagnosticsSema.def

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4210,24 +4210,24 @@ ERROR(dynamic_and_library_evolution_not_supported,none,
42104210
//------------------------------------------------------------------------------
42114211

42124212
ERROR(dynamic_replacement_accessor_type_mismatch, none,
4213-
"replaced accessor %0's type does not match", (DeclName))
4213+
"replaced accessor %0's type does not match", (DeclNameRef))
42144214
ERROR(dynamic_replacement_accessor_not_dynamic, none,
4215-
"replaced accessor for %0 is not marked dynamic", (DeclName))
4215+
"replaced accessor for %0 is not marked dynamic", (DeclNameRef))
42164216
ERROR(dynamic_replacement_accessor_not_explicit, none,
42174217
"replaced accessor %select{get|set|_read|_modify|willSet|didSet|unsafeAddress|addressWithOwner|addressWithNativeOwner|unsafeMutableAddress|mutableAddressWithOwner|}0 for %1 is not explicitly defined",
4218-
(unsigned, DeclName))
4218+
(unsigned, DeclNameRef))
42194219
ERROR(dynamic_replacement_function_not_dynamic, none,
42204220
"replaced function %0 is not marked dynamic", (DeclName))
42214221
ERROR(dynamic_replacement_function_not_found, none,
4222-
"replaced function %0 could not be found", (DeclName))
4222+
"replaced function %0 could not be found", (DeclNameRef))
42234223
ERROR(dynamic_replacement_accessor_not_found, none,
4224-
"replaced accessor for %0 could not be found", (DeclName))
4224+
"replaced accessor for %0 could not be found", (DeclNameRef))
42254225
ERROR(dynamic_replacement_accessor_ambiguous, none,
4226-
"replaced accessor for %0 occurs in multiple places", (DeclName))
4226+
"replaced accessor for %0 occurs in multiple places", (DeclNameRef))
42274227
NOTE(dynamic_replacement_accessor_ambiguous_candidate, none,
42284228
"candidate accessor found in module %0", (DeclName))
42294229
ERROR(dynamic_replacement_function_of_type_not_found, none,
4230-
"replaced function %0 of type %1 could not be found", (DeclName, Type))
4230+
"replaced function %0 of type %1 could not be found", (DeclNameRef, Type))
42314231
NOTE(dynamic_replacement_found_function_of_type, none,
42324232
"found function %0 of type %1", (DeclName, Type))
42334233
ERROR(dynamic_replacement_not_in_extension, none,

include/swift/AST/NameLookup.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -397,11 +397,11 @@ class VectorDeclConsumer : public VisibleDeclConsumer {
397397
class NamedDeclConsumer : public VisibleDeclConsumer {
398398
virtual void anchor() override;
399399
public:
400-
DeclName name;
400+
DeclNameRef name;
401401
SmallVectorImpl<LookupResultEntry> &results;
402402
bool isTypeLookup;
403403

404-
NamedDeclConsumer(DeclName name,
404+
NamedDeclConsumer(DeclNameRef name,
405405
SmallVectorImpl<LookupResultEntry> &results,
406406
bool isTypeLookup)
407407
: name(name), results(results), isTypeLookup(isTypeLookup) {}
@@ -412,7 +412,7 @@ class NamedDeclConsumer : public VisibleDeclConsumer {
412412
// to avoid circular validation.
413413
if (isTypeLookup && !isa<TypeDecl>(VD))
414414
return;
415-
if (VD->getFullName().matchesRef(name))
415+
if (VD->getFullName().matchesRef(name.getFullName()))
416416
results.push_back(LookupResultEntry(VD));
417417
}
418418
};
@@ -666,7 +666,7 @@ class ASTScope {
666666

667667
/// \return the scopes traversed
668668
static llvm::SmallVector<const ast_scope::ASTScopeImpl *, 0>
669-
unqualifiedLookup(SourceFile *, DeclName, SourceLoc,
669+
unqualifiedLookup(SourceFile *, DeclNameRef, SourceLoc,
670670
const DeclContext *startingContext,
671671
namelookup::AbstractASTScopeDeclConsumer &);
672672

include/swift/AST/NameLookupRequests.h

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace swift {
2727
class ClassDecl;
2828
class DeclContext;
2929
class DeclName;
30+
class DeclNameRef;
3031
class DestructorDecl;
3132
class GenericContext;
3233
class GenericParamList;
@@ -316,24 +317,15 @@ class UnqualifiedLookupDescriptor {
316317
using LookupOptions = OptionSet<UnqualifiedLookupFlags>;
317318

318319
public:
319-
DeclName Name;
320+
DeclNameRef Name;
320321
DeclContext *DC;
321322
SourceLoc Loc;
322323
LookupOptions Options;
323324

324-
/// Transitional entry point.
325-
[[deprecated]] UnqualifiedLookupDescriptor(DeclName name, DeclContext *dc,
326-
SourceLoc loc = SourceLoc(),
327-
LookupOptions options = {})
328-
: Name(name), DC(dc), Loc(loc), Options(options) {}
329-
330-
#pragma clang diagnostic push
331-
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
332325
UnqualifiedLookupDescriptor(DeclNameRef name, DeclContext *dc,
333326
SourceLoc loc = SourceLoc(),
334327
LookupOptions options = {})
335-
: UnqualifiedLookupDescriptor(name.getFullName(), dc, loc, options) { }
336-
#pragma clang diagnostic pop
328+
: Name(name), DC(dc), Loc(loc), Options(options) { }
337329

338330
friend llvm::hash_code hash_value(const UnqualifiedLookupDescriptor &desc) {
339331
return llvm::hash_combine(desc.Name, desc.DC, desc.Loc,

lib/AST/ASTContext.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,8 @@ DECLTYPE *ASTContext::get##NAME##Decl() const { \
833833
/* Note: lookupQualified() will search both the Swift overlay \
834834
* and the Clang module it imports. */ \
835835
SmallVector<ValueDecl *, 1> decls; \
836-
M->lookupQualified(M, getIdentifier(#NAME), NL_OnlyTypes, decls); \
836+
M->lookupQualified(M, DeclNameRef_(getIdentifier(#NAME)), NL_OnlyTypes, \
837+
decls); \
837838
if (decls.size() == 1 && isa<DECLTYPE>(decls[0])) { \
838839
auto decl = cast<DECLTYPE>(decls[0]); \
839840
if (isa<ProtocolDecl>(decl) || decl->getGenericParams() == nullptr) { \

lib/AST/ASTScope.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ using namespace ast_scope;
3939
#pragma mark ASTScope
4040

4141
llvm::SmallVector<const ASTScopeImpl *, 0> ASTScope::unqualifiedLookup(
42-
SourceFile *SF, DeclName name, SourceLoc loc,
42+
SourceFile *SF, DeclNameRef name, SourceLoc loc,
4343
const DeclContext *startingContext,
4444
namelookup::AbstractASTScopeDeclConsumer &consumer) {
4545
if (auto *s = SF->getASTContext().Stats)

lib/AST/ASTScopeLookup.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ using namespace ast_scope;
3939
static bool isLocWithinAnInactiveClause(const SourceLoc loc, SourceFile *SF);
4040

4141
llvm::SmallVector<const ASTScopeImpl *, 0> ASTScopeImpl::unqualifiedLookup(
42-
SourceFile *sourceFile, const DeclName name, const SourceLoc loc,
42+
SourceFile *sourceFile, const DeclNameRef name, const SourceLoc loc,
4343
const DeclContext *const startingContext, DeclConsumer consumer) {
4444
SmallVector<const ASTScopeImpl *, 0> history;
4545
const auto *start =
@@ -50,7 +50,7 @@ llvm::SmallVector<const ASTScopeImpl *, 0> ASTScopeImpl::unqualifiedLookup(
5050
}
5151

5252
const ASTScopeImpl *ASTScopeImpl::findStartingScopeForLookup(
53-
SourceFile *sourceFile, const DeclName name, const SourceLoc loc,
53+
SourceFile *sourceFile, const DeclNameRef name, const SourceLoc loc,
5454
const DeclContext *const startingContext) {
5555
// At present, use legacy code in unqualifiedLookup.cpp to handle module-level
5656
// lookups

lib/AST/DocComment.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ const ValueDecl *findDefaultProvidedDeclWithDocComment(const ValueDecl *VD) {
414414

415415
SmallVector<ValueDecl *, 2> members;
416416
protocol->lookupQualified(const_cast<ProtocolDecl *>(protocol),
417-
VD->getFullName(), NLOptions::NL_ProtocolMembers,
417+
DeclNameRef_(VD->getFullName()),
418+
NLOptions::NL_ProtocolMembers,
418419
members);
419420

420421
for (auto *member : members) {

lib/AST/UnqualifiedLookup.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ namespace {
131131

132132
public:
133133
/// Do the lookups and add matches to results.
134-
void findResults(const DeclName &Name, bool isCascadingUse,
134+
void findResults(const DeclNameRef &Name, bool isCascadingUse,
135135
NLOptions baseNLOptions, DeclContext *contextForLookup,
136136
SmallVectorImpl<LookupResultEntry> &results) const;
137137
};
@@ -147,7 +147,7 @@ namespace {
147147

148148
public:
149149
InstrumentedNamedDeclConsumer(UnqualifiedLookupFactory *factory,
150-
DeclName name,
150+
DeclNameRef name,
151151
SmallVectorImpl<LookupResultEntry> &results,
152152
bool isTypeLookup)
153153
: NamedDeclConsumer(name, results, isTypeLookup), factory(factory) {}
@@ -163,7 +163,7 @@ namespace {
163163
};
164164
#endif
165165
// Inputs
166-
const DeclName Name;
166+
const DeclNameRef Name;
167167
DeclContext *const DC;
168168
ModuleDecl &M;
169169
const ASTContext &Ctx;
@@ -199,7 +199,7 @@ namespace {
199199

200200
public:
201201
// clang-format off
202-
UnqualifiedLookupFactory(DeclName Name,
202+
UnqualifiedLookupFactory(DeclNameRef Name,
203203
DeclContext *const DC,
204204
SourceLoc Loc,
205205
Options options,
@@ -320,7 +320,7 @@ namespace {
320320
void setAsideUnavailableResults(size_t firstPossiblyUnavailableResult);
321321

322322
void recordDependencyOnTopLevelName(DeclContext *topLevelContext,
323-
DeclName name, bool isCascadingUse);
323+
DeclNameRef name, bool isCascadingUse);
324324

325325
void addImportedResults(DeclContext *const dc);
326326

@@ -424,7 +424,7 @@ class ASTScopeDeclConsumerForUnqualifiedLookup
424424

425425
// clang-format off
426426
UnqualifiedLookupFactory::UnqualifiedLookupFactory(
427-
DeclName Name,
427+
DeclNameRef Name,
428428
DeclContext *const DC,
429429
SourceLoc Loc,
430430
Options options,
@@ -906,7 +906,7 @@ void UnqualifiedLookupFactory::addGenericParametersForFunction(
906906
}
907907

908908
void UnqualifiedLookupFactory::ResultFinderForTypeContext::findResults(
909-
const DeclName &Name, bool isCascadingUse, NLOptions baseNLOptions,
909+
const DeclNameRef &Name, bool isCascadingUse, NLOptions baseNLOptions,
910910
DeclContext *contextForLookup,
911911
SmallVectorImpl<LookupResultEntry> &results) const {
912912
// An optimization:
@@ -960,8 +960,8 @@ void UnqualifiedLookupFactory::setAsideUnavailableResults(
960960

961961

962962
void UnqualifiedLookupFactory::recordDependencyOnTopLevelName(
963-
DeclContext *topLevelContext, DeclName name, bool isCascadingUse) {
964-
recordLookupOfTopLevelName(topLevelContext, Name, isCascadingUse);
963+
DeclContext *topLevelContext, DeclNameRef name, bool isCascadingUse) {
964+
recordLookupOfTopLevelName(topLevelContext, Name.getFullName(), isCascadingUse);
965965
recordedSF = dyn_cast<SourceFile>(topLevelContext);
966966
recordedIsCascadingUse = isCascadingUse;
967967
}
@@ -971,7 +971,7 @@ void UnqualifiedLookupFactory::addImportedResults(DeclContext *const dc) {
971971
SmallVector<ValueDecl *, 8> CurModuleResults;
972972
auto resolutionKind = isOriginallyTypeLookup ? ResolutionKind::TypesOnly
973973
: ResolutionKind::Overloadable;
974-
lookupInModule(dc, Name, CurModuleResults, NLKind::UnqualifiedLookup,
974+
lookupInModule(dc, Name.getFullName(), CurModuleResults, NLKind::UnqualifiedLookup,
975975
resolutionKind, dc);
976976

977977
// Always perform name shadowing for type lookup.
@@ -1014,7 +1014,7 @@ void UnqualifiedLookupFactory::lookForAModuleWithTheGivenName(
10141014
return;
10151015
}
10161016
ModuleDecl *desiredModule = Ctx.getLoadedModule(Name.getBaseIdentifier());
1017-
if (!desiredModule && Name == Ctx.TheBuiltinModule->getName())
1017+
if (!desiredModule && Name.getFullName() == Ctx.TheBuiltinModule->getName())
10181018
desiredModule = Ctx.TheBuiltinModule;
10191019
if (desiredModule) {
10201020
// Make sure the desired module is actually visible from the current
@@ -1135,7 +1135,7 @@ bool ASTScopeDeclConsumerForUnqualifiedLookup::consume(
11351135
for (auto *value: values) {
11361136
if (factory.isOriginallyTypeLookup && !isa<TypeDecl>(value))
11371137
continue;
1138-
if (!value->getFullName().matchesRef(factory.Name))
1138+
if (!value->getFullName().matchesRef(factory.Name.getFullName()))
11391139
continue;
11401140

11411141
// In order to preserve the behavior of the existing context-based lookup,

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5017,7 +5017,7 @@ namespace {
50175017

50185018
if (lookupContext) {
50195019
SmallVector<ValueDecl *, 2> lookup;
5020-
dc->lookupQualified(lookupContext, name,
5020+
dc->lookupQualified(lookupContext, DeclNameRef_(name),
50215021
NL_QualifiedDefault | NL_KnownNoDependency,
50225022
lookup);
50235023
bool foundMethod = false;
@@ -6396,7 +6396,7 @@ void SwiftDeclConverter::recordObjCOverride(AbstractFunctionDecl *decl) {
63966396
return;
63976397
// Dig out the Objective-C superclass.
63986398
SmallVector<ValueDecl *, 4> results;
6399-
superDecl->lookupQualified(superDecl, decl->getFullName(),
6399+
superDecl->lookupQualified(superDecl, DeclNameRef_(decl->getFullName()),
64006400
NL_QualifiedDefault | NL_KnownNoDependency,
64016401
results);
64026402
for (auto member : results) {
@@ -6469,7 +6469,7 @@ void SwiftDeclConverter::recordObjCOverride(SubscriptDecl *subscript) {
64696469
// operation.
64706470
SmallVector<ValueDecl *, 2> lookup;
64716471
subscript->getModuleContext()->lookupQualified(
6472-
superDecl, subscript->getFullName(),
6472+
superDecl, DeclNameRef_(subscript->getFullName()),
64736473
NL_QualifiedDefault | NL_KnownNoDependency, lookup);
64746474

64756475
for (auto result : lookup) {

0 commit comments

Comments
 (0)