Skip to content

[NameLookup ] UnqualifiedLookup refactoring #22578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 70 commits into from
Mar 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
04ef0da
Add ExpUnqualifiedLookup, cross-check
davidungar Feb 12, 2019
e9298a1
Renamed shouldReturnBasedOnResults to isFinishedWithLookupNowThatIsAb…
davidungar Feb 16, 2019
3b7131c
Factor each variant into a separate function. Facter out Decl dispatch.
davidungar Feb 16, 2019
8ece214
Push GenericParamList check into function case.
davidungar Feb 16, 2019
ebd8b38
Factor GenericParameterCheck
davidungar Feb 16, 2019
ee40bfb
Note factoring possibility
davidungar Feb 16, 2019
dbb998f
better names
davidungar Feb 16, 2019
65ed915
Factor lookupDecl handing
davidungar Feb 16, 2019
ee3c2ee
Don’t use DC
davidungar Feb 17, 2019
79906de
Factor isOutsideBodyOfFunction
davidungar Feb 17, 2019
3c295f8
Group lookupDecls etc into PlacesToSearch
davidungar Feb 17, 2019
977b0db
Nonfmt cut down on DC
davidungar Feb 17, 2019
b02b682
Eliminating mutable DC
davidungar Feb 17, 2019
2fd4e2d
Format
davidungar Feb 17, 2019
92faaae
constification
davidungar Feb 17, 2019
ca025ab
First cut no mutable isCascadingUse
davidungar Feb 17, 2019
97602a9
Broke up finishLookup
davidungar Feb 17, 2019
6596717
Move factory method bodies out.
davidungar Feb 18, 2019
13176ff
Format
davidungar Feb 18, 2019
7631ae9
Manual format correction and added TODOs
davidungar Feb 18, 2019
b52b85b
Factor isCascadingUse resolution.
davidungar Feb 18, 2019
272df9f
Minor return cleanup.
davidungar Feb 18, 2019
0aee0db
1st cut finish redo, unfmt
davidungar Feb 18, 2019
65f8f73
Todo editing
davidungar Feb 19, 2019
ef9f99e
Rename ExpUnqalifiedLookup to UnqualifiedLookup, UnqualifiedLookup to…
davidungar Feb 19, 2019
edaec2a
Move searchPlacesToSearch into PlacesToSearch
davidungar Feb 19, 2019
d776cf5
Some reordering
davidungar Feb 19, 2019
8e7ff01
WIP
davidungar Feb 19, 2019
1ce86b9
Minor fixes
davidungar Feb 20, 2019
e927746
Unify two cases
davidungar Feb 20, 2019
80a234a
Use a struct instead of a pair
davidungar Feb 20, 2019
1595efe
Split the file, unfmt
davidungar Feb 20, 2019
cd48cd6
Format
davidungar Feb 20, 2019
5d49b3b
Minor cleanumps
davidungar Feb 20, 2019
fdf8326
rm unused enum
davidungar Feb 20, 2019
306cfd8
Constification
davidungar Feb 20, 2019
c9576ca
Move LegacyUnqualifiedLookup out of header
davidungar Feb 20, 2019
3a744d1
Rm LookupInOneDeclContextResult::isDone
davidungar Feb 20, 2019
64ff790
Factor isFinishedWithLookupNowThatIsAboutToLookForOuterResults
davidungar Feb 21, 2019
6635f39
Break up confusing compound.
davidungar Feb 21, 2019
d45ab0b
Regularize nextDC, priorDC
davidungar Feb 21, 2019
19b7801
Minor rearrangement.
davidungar Feb 21, 2019
7648ece
Rm unneeded instvar
davidungar Feb 21, 2019
1391c3f
Rm a flag.
davidungar Feb 21, 2019
12d6038
isafication
davidungar Feb 21, 2019
2f09918
Tighten up the code.
davidungar Feb 21, 2019
6982e66
Refactor filterForDiscriminator and call of addLocalVariableResults.
davidungar Feb 22, 2019
6093a7f
Rename setIndexOfFIrstOuterResultIfNotSetAlready to recordCompilation…
davidungar Feb 23, 2019
c6044bf
RecordDependendcyOnTopLeveName BEFORE debugger client.
davidungar Feb 23, 2019
68be308
Renaming
davidungar Feb 23, 2019
2e0bfb7
Factor out lookInModuleScope
davidungar Feb 23, 2019
3a16af0
Revise ASTScope-bsed lookup
davidungar Feb 24, 2019
26247b4
Recursify ASTScope-based lookup
davidungar Feb 24, 2019
e3e597d
Recursify operator lookup.
davidungar Feb 24, 2019
6393c8d
Partial recurisivication of decl-based name lookup.
davidungar Feb 24, 2019
4c36440
More recursification
davidungar Feb 24, 2019
bd5bff6
Renaming
davidungar Feb 24, 2019
0a817a9
Pass flag for addGenericParameters
davidungar Feb 25, 2019
3641e35
Pass individual arguments.
davidungar Feb 25, 2019
66a9cac
void return from addGeneric…
davidungar Feb 25, 2019
7c003aa
Simply retuirn of put asside
davidungar Feb 25, 2019
ee6acae
Remove bool returns
davidungar Feb 25, 2019
1f914fb
Pull out top-level recording.
davidungar Feb 25, 2019
81c0299
Incorperate Doug’s comments & factor a bit more.
Feb 27, 2019
3c32a41
Introduce runIfNotDoneYet
Feb 27, 2019
d5983da
Minor prettying.
Feb 28, 2019
8f67ef6
Add comment and renamed lookUpTopLevelNames…
Feb 28, 2019
85d6012
Renamed “DCAnd” to “ContextAnd”
Feb 28, 2019
543c826
Rename ResultFinderForSelfsConformances
Feb 28, 2019
82a842f
Rename addPrivateImports
Feb 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion include/swift/AST/NameLookup.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,25 @@ class UnqualifiedLookup {
/// That is, \c makeArrayRef(Results).take_front(IndexOfFirstOuterResults)
/// will be Results from the innermost scope that had results, and the
/// remaining elements of Results will be from parent scopes of this one.
///
/// Allows unqualified name lookup to return results from outer scopes.
/// This is necessary for disambiguating calls to functions like `min` and
/// `max`.
size_t IndexOfFirstOuterResult;

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

/// Get the result as a single type, or a null type if that fails.
TypeDecl *getSingleTypeResult();
TypeDecl *getSingleTypeResult() const;
};

inline UnqualifiedLookup::Options operator|(UnqualifiedLookup::Flags flag1,
UnqualifiedLookup::Flags flag2) {
return UnqualifiedLookup::Options(flag1) | flag2;
}


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

template <typename Fn>
void forAllVisibleModules(const DeclContext *DC, const Fn &fn) {
DeclContext *moduleScope = DC->getModuleScopeContext();
if (auto file = dyn_cast<FileUnit>(moduleScope))
file->forAllVisibleModules(fn);
else
cast<ModuleDecl>(moduleScope)
->forAllVisibleModules(ModuleDecl::AccessPathTy(), fn);
}

/// Only name lookup has gathered a set of results, perform any necessary
/// steps to prune the result set before returning it to the caller.
bool finishLookup(const DeclContext *dc, NLOptions options,
SmallVectorImpl<ValueDecl *> &decls);

/// Do nothing if debugClient is null.
template <typename Result>
void filterForDiscriminator(SmallVectorImpl<Result> &results,
DebuggerClient *debugClient);

void recordLookupOfTopLevelName(DeclContext *topLevelContext, DeclName name,
bool isCascading);

} // end namespace namelookup

/// Retrieve the set of nominal type declarations that are directly
Expand Down
1 change: 1 addition & 0 deletions lib/AST/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ add_swift_host_library(swiftAST STATIC
TypeRefinementContext.cpp
TypeRepr.cpp
TypeWalker.cpp
UnqualifiedLookup.cpp
USRGeneration.cpp

LINK_LIBRARIES
Expand Down
Loading