@@ -1401,8 +1401,23 @@ namespace {
1401
1401
DebugClient->lookupOverrides (Name.getBaseName (), dcAndIsCascadingUse.first , Loc,
1402
1402
isOriginallyTypeLookup, Results))
1403
1403
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 );
1406
1421
}
1407
1422
1408
1423
private:
@@ -2017,25 +2032,30 @@ namespace {
2017
2032
2018
2033
return isFinishedWithLookupNowThatIsAboutToLookForOuterResults ();
2019
2034
}
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);
2024
2041
recordedName = Name;
2025
2042
recordedIsCascadingUse = isCascadingUse;
2026
-
2043
+ }
2044
+
2045
+ void addPrivateImports (DeclContext *const dc) {
2027
2046
// Add private imports to the extra search list.
2028
2047
SmallVector<ModuleDecl::ImportedModule, 8 > extraImports;
2029
2048
if (auto FU = dyn_cast<FileUnit>(dc))
2030
2049
FU->getImportedModules (extraImports, ModuleDecl::ImportFilter::Private);
2031
2050
2032
2051
using namespace namelookup ;
2033
2052
SmallVector<ValueDecl *, 8 > CurModuleResults;
2034
- auto resolutionKind = isOriginallyTypeLookup ? ResolutionKind::TypesOnly
2053
+ auto resolutionKind = isOriginallyTypeLookup
2054
+ ? ResolutionKind::TypesOnly
2035
2055
: ResolutionKind::Overloadable;
2036
2056
lookupInModule (&M, {}, Name, CurModuleResults, NLKind::UnqualifiedLookup,
2037
2057
resolutionKind, TypeResolver, dc, extraImports);
2038
-
2058
+
2039
2059
// Always perform name shadowing for type lookup.
2040
2060
if (options.contains (Flags::TypeLookup)) {
2041
2061
removeShadowedDecls (CurModuleResults, &M);
@@ -2046,36 +2066,37 @@ namespace {
2046
2066
2047
2067
if (DebugClient)
2048
2068
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) {
2051
2073
if (Name.isSimpleName () && DebugClient)
2052
2074
DebugClient->lookupAdditions (Name.getBaseName (), dc, Loc,
2053
2075
isOriginallyTypeLookup, Results);
2054
-
2055
- // If we've found something, we're done.
2056
- if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults (
2057
- /* noMoreOuterResults=*/ true ))
2058
- return ;
2059
2076
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 () {
2063
2084
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 ;
2068
2091
if (!Name.isSimpleName ())
2069
- return ;
2092
+ return true ;
2070
2093
2071
2094
// Look for a module with the given name.
2072
2095
if (Name.isSimpleName (M.getName ())) {
2073
2096
Results.push_back (LookupResultEntry (&M));
2074
- if (isFinishedWithLookupNowThatIsAboutToLookForOuterResults (
2075
- /* noMoreOuterResults=*/ true ))
2076
- return ;
2097
+ return isFinishedWithLookupNowThatIsAboutToLookForOuterResults (
2098
+ /* noMoreOuterResults=*/ true );
2077
2099
}
2078
-
2079
2100
ModuleDecl *desiredModule = Ctx.getLoadedModule (Name.getBaseIdentifier ());
2080
2101
if (!desiredModule && Name == Ctx.TheBuiltinModule ->getName ())
2081
2102
desiredModule = Ctx.TheBuiltinModule ;
@@ -2089,9 +2110,7 @@ namespace {
2089
2110
return true ;
2090
2111
});
2091
2112
}
2092
- // Make sure we've recorded the inner-result-boundary.
2093
- (void )isFinishedWithLookupNowThatIsAboutToLookForOuterResults (
2094
- /* noMoreOuterResults=*/ true );
2113
+ return false ;
2095
2114
}
2096
2115
};
2097
2116
} // namespace
0 commit comments