Skip to content

Commit 2ce6867

Browse files
author
David Ungar
authored
Merge pull request #22578 from davidungar/A-2-12
[NameLookup ] UnqualifiedLookup refactoring
2 parents b36c77c + 82a842f commit 2ce6867

File tree

4 files changed

+1845
-625
lines changed

4 files changed

+1845
-625
lines changed

include/swift/AST/NameLookup.h

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,25 @@ class UnqualifiedLookup {
118118
/// That is, \c makeArrayRef(Results).take_front(IndexOfFirstOuterResults)
119119
/// will be Results from the innermost scope that had results, and the
120120
/// remaining elements of Results will be from parent scopes of this one.
121+
///
122+
/// Allows unqualified name lookup to return results from outer scopes.
123+
/// This is necessary for disambiguating calls to functions like `min` and
124+
/// `max`.
121125
size_t IndexOfFirstOuterResult;
122126

123127
/// Return true if anything was found by the name lookup.
124128
bool isSuccess() const { return !Results.empty(); }
125129

126130
/// Get the result as a single type, or a null type if that fails.
127-
TypeDecl *getSingleTypeResult();
131+
TypeDecl *getSingleTypeResult() const;
128132
};
129133

130134
inline UnqualifiedLookup::Options operator|(UnqualifiedLookup::Flags flag1,
131135
UnqualifiedLookup::Flags flag2) {
132136
return UnqualifiedLookup::Options(flag1) | flag2;
133137
}
134138

139+
135140
/// Describes the reason why a certain declaration is visible.
136141
enum class DeclVisibilityKind {
137142
/// Declaration is a local variable or type.
@@ -352,6 +357,29 @@ void lookupInModule(ModuleDecl *module, ModuleDecl::AccessPathTy accessPath,
352357
const DeclContext *moduleScopeContext,
353358
ArrayRef<ModuleDecl::ImportedModule> extraImports = {});
354359

360+
template <typename Fn>
361+
void forAllVisibleModules(const DeclContext *DC, const Fn &fn) {
362+
DeclContext *moduleScope = DC->getModuleScopeContext();
363+
if (auto file = dyn_cast<FileUnit>(moduleScope))
364+
file->forAllVisibleModules(fn);
365+
else
366+
cast<ModuleDecl>(moduleScope)
367+
->forAllVisibleModules(ModuleDecl::AccessPathTy(), fn);
368+
}
369+
370+
/// Only name lookup has gathered a set of results, perform any necessary
371+
/// steps to prune the result set before returning it to the caller.
372+
bool finishLookup(const DeclContext *dc, NLOptions options,
373+
SmallVectorImpl<ValueDecl *> &decls);
374+
375+
/// Do nothing if debugClient is null.
376+
template <typename Result>
377+
void filterForDiscriminator(SmallVectorImpl<Result> &results,
378+
DebuggerClient *debugClient);
379+
380+
void recordLookupOfTopLevelName(DeclContext *topLevelContext, DeclName name,
381+
bool isCascading);
382+
355383
} // end namespace namelookup
356384

357385
/// Retrieve the set of nominal type declarations that are directly

lib/AST/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ add_swift_host_library(swiftAST STATIC
9595
TypeRefinementContext.cpp
9696
TypeRepr.cpp
9797
TypeWalker.cpp
98+
UnqualifiedLookup.cpp
9899
USRGeneration.cpp
99100

100101
INTERFACE_LINK_LIBRARIES

0 commit comments

Comments
 (0)