Skip to content

Commit 97602a9

Browse files
committed
Broke up finishLookup
1 parent ca025ab commit 97602a9

File tree

1 file changed

+50
-31
lines changed

1 file changed

+50
-31
lines changed

lib/AST/NameLookup.cpp

Lines changed: 50 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,8 +1401,23 @@ namespace {
14011401
DebugClient->lookupOverrides(Name.getBaseName(), dcAndIsCascadingUse.first, Loc,
14021402
isOriginallyTypeLookup, Results))
14031403
return;
1404-
1405-
finishLookupRENAME(dcAndIsCascadingUse.first, dcAndIsCascadingUse.second);
1404+
1405+
recordDependencyOnTopLevelName(dcAndIsCascadingUse.first,
1406+
Name,
1407+
dcAndIsCascadingUse.second);
1408+
addPrivateImports(dcAndIsCascadingUse.first);
1409+
if (addNamesKnownToDebugClient(dcAndIsCascadingUse.first))
1410+
return;
1411+
// If we still haven't found anything, but we do have some
1412+
// declarations that are "unavailable in the current Swift", drop
1413+
// those in.
1414+
if (addUnavailableInnerResults())
1415+
return;
1416+
if (lookForAModuleWithTheGivenName(dcAndIsCascadingUse.first))
1417+
return;
1418+
// Make sure we've recorded the inner-result-boundary.
1419+
(void)isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
1420+
/*noMoreOuterResults=*/true);
14061421
}
14071422

14081423
private:
@@ -2017,25 +2032,30 @@ namespace {
20172032

20182033
return isFinishedWithLookupNowThatIsAboutToLookForOuterResults();
20192034
}
2020-
2021-
void finishLookupRENAME(DeclContext *const dc, const bool isCascadingUse) {
2022-
recordLookupOfTopLevelName(dc, Name, isCascadingUse);
2023-
recordedSF = dyn_cast<SourceFile>(dc);
2035+
2036+
void recordDependencyOnTopLevelName(DeclContext *topLevelContext,
2037+
DeclName name,
2038+
bool isCascadingUse) {
2039+
recordLookupOfTopLevelName(topLevelContext, Name, isCascadingUse);
2040+
recordedSF = dyn_cast<SourceFile>(topLevelContext);
20242041
recordedName = Name;
20252042
recordedIsCascadingUse = isCascadingUse;
2026-
2043+
}
2044+
2045+
void addPrivateImports(DeclContext *const dc) {
20272046
// Add private imports to the extra search list.
20282047
SmallVector<ModuleDecl::ImportedModule, 8> extraImports;
20292048
if (auto FU = dyn_cast<FileUnit>(dc))
20302049
FU->getImportedModules(extraImports, ModuleDecl::ImportFilter::Private);
20312050

20322051
using namespace namelookup;
20332052
SmallVector<ValueDecl *, 8> CurModuleResults;
2034-
auto resolutionKind = isOriginallyTypeLookup ? ResolutionKind::TypesOnly
2053+
auto resolutionKind = isOriginallyTypeLookup
2054+
? ResolutionKind::TypesOnly
20352055
: ResolutionKind::Overloadable;
20362056
lookupInModule(&M, {}, Name, CurModuleResults, NLKind::UnqualifiedLookup,
20372057
resolutionKind, TypeResolver, dc, extraImports);
2038-
2058+
20392059
// Always perform name shadowing for type lookup.
20402060
if (options.contains(Flags::TypeLookup)) {
20412061
removeShadowedDecls(CurModuleResults, &M);
@@ -2046,36 +2066,37 @@ namespace {
20462066

20472067
if (DebugClient)
20482068
filterForDiscriminator(Results, DebugClient);
2049-
2050-
// Now add any names the DebugClient knows about to the lookup.
2069+
}
2070+
2071+
// Return true if done
2072+
bool addNamesKnownToDebugClient(DeclContext *dc) {
20512073
if (Name.isSimpleName() && DebugClient)
20522074
DebugClient->lookupAdditions(Name.getBaseName(), dc, Loc,
20532075
isOriginallyTypeLookup, Results);
2054-
2055-
// If we've found something, we're done.
2056-
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
2057-
/*noMoreOuterResults=*/true))
2058-
return;
20592076

2060-
// If we still haven't found anything, but we do have some
2061-
// declarations that are "unavailable in the current Swift", drop
2062-
// those in.
2077+
// If we've found something, we're done.
2078+
return isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
2079+
/*noMoreOuterResults=*/true);
2080+
}
2081+
2082+
/// Return true if done
2083+
bool addUnavailableInnerResults() {
20632084
Results = std::move(UnavailableInnerResults);
2064-
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
2065-
/*noMoreOuterResults=*/true))
2066-
return;
2067-
2085+
return isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
2086+
/*noMoreOuterResults=*/true);
2087+
}
2088+
2089+
bool lookForAModuleWithTheGivenName(DeclContext *const dc) {
2090+
using namespace namelookup;
20682091
if (!Name.isSimpleName())
2069-
return;
2092+
return true;
20702093

20712094
// Look for a module with the given name.
20722095
if (Name.isSimpleName(M.getName())) {
20732096
Results.push_back(LookupResultEntry(&M));
2074-
if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
2075-
/*noMoreOuterResults=*/true))
2076-
return;
2097+
return isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
2098+
/*noMoreOuterResults=*/true);
20772099
}
2078-
20792100
ModuleDecl *desiredModule = Ctx.getLoadedModule(Name.getBaseIdentifier());
20802101
if (!desiredModule && Name == Ctx.TheBuiltinModule->getName())
20812102
desiredModule = Ctx.TheBuiltinModule;
@@ -2089,9 +2110,7 @@ namespace {
20892110
return true;
20902111
});
20912112
}
2092-
// Make sure we've recorded the inner-result-boundary.
2093-
(void)isFinishedWithLookupNowThatIsAboutToLookForOuterResults(
2094-
/*noMoreOuterResults=*/true);
2113+
return false;
20952114
}
20962115
};
20972116
} // namespace

0 commit comments

Comments
 (0)