mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Move access-path filtering into ModuleNameLookup (out of lookupValue) (#27097)
Removes duplicated logic from the implementations of FileUnit::lookupValue, and simplifies the interface to ModuleDecl::lookupValue, where everyone was passing an empty (non-filtering) access path anyway /except/ during actual lookup from source code. No functionality change.
This commit is contained in:
@@ -168,8 +168,8 @@ public:
|
||||
/// Throw away as much memory as possible.
|
||||
void invalidate();
|
||||
|
||||
void lookupValue(AccessPathTy AccessPath, DeclName Name,
|
||||
NLKind LookupKind, SmallVectorImpl<ValueDecl*> &Result);
|
||||
void lookupValue(DeclName Name, NLKind LookupKind,
|
||||
SmallVectorImpl<ValueDecl*> &Result);
|
||||
|
||||
void lookupVisibleDecls(AccessPathTy AccessPath,
|
||||
VisibleDeclConsumer &Consumer,
|
||||
@@ -284,14 +284,8 @@ SourceLookupCache::SourceLookupCache(const ModuleDecl &M) {
|
||||
}
|
||||
}
|
||||
|
||||
void SourceLookupCache::lookupValue(AccessPathTy AccessPath, DeclName Name,
|
||||
NLKind LookupKind,
|
||||
void SourceLookupCache::lookupValue(DeclName Name, NLKind LookupKind,
|
||||
SmallVectorImpl<ValueDecl*> &Result) {
|
||||
// If this import is specific to some named type or decl ("import Swift.int")
|
||||
// then filter out any lookups that don't match.
|
||||
if (!ModuleDecl::matchesAccessPath(AccessPath, Name))
|
||||
return;
|
||||
|
||||
auto I = TopLevelValues.find(Name);
|
||||
if (I == TopLevelValues.end()) return;
|
||||
|
||||
@@ -457,19 +451,18 @@ static bool isParsedModule(const ModuleDecl *mod) {
|
||||
cast<SourceFile>(files[0])->Kind != SourceFileKind::SIL);
|
||||
}
|
||||
|
||||
void ModuleDecl::lookupValue(AccessPathTy AccessPath, DeclName Name,
|
||||
NLKind LookupKind,
|
||||
void ModuleDecl::lookupValue(DeclName Name, NLKind LookupKind,
|
||||
SmallVectorImpl<ValueDecl*> &Result) const {
|
||||
auto *stats = getASTContext().Stats;
|
||||
if (stats)
|
||||
stats->getFrontendCounters().NumModuleLookupValue++;
|
||||
|
||||
if (isParsedModule(this)) {
|
||||
getSourceLookupCache().lookupValue(AccessPath, Name, LookupKind, Result);
|
||||
getSourceLookupCache().lookupValue(Name, LookupKind, Result);
|
||||
return;
|
||||
}
|
||||
|
||||
FORWARD(lookupValue, (AccessPath, Name, LookupKind, Result));
|
||||
FORWARD(lookupValue, (Name, LookupKind, Result));
|
||||
}
|
||||
|
||||
TypeDecl * ModuleDecl::lookupLocalType(StringRef MangledName) const {
|
||||
@@ -517,7 +510,7 @@ void ModuleDecl::lookupMember(SmallVectorImpl<ValueDecl*> &results,
|
||||
alreadyInPrivateContext = true;
|
||||
} else if (isa<ModuleDecl>(containerDecl)) {
|
||||
assert(container == this);
|
||||
this->lookupValue({}, name, NLKind::QualifiedLookup, results);
|
||||
this->lookupValue(name, NLKind::QualifiedLookup, results);
|
||||
} else if (!isa<GenericTypeDecl>(containerDecl)) {
|
||||
// If ExtensionDecl, then use ExtensionDecl::lookupDirect instead.
|
||||
llvm_unreachable("This context does not support lookup.");
|
||||
@@ -557,8 +550,7 @@ void ModuleDecl::lookupObjCMethods(
|
||||
FORWARD(lookupObjCMethods, (selector, results));
|
||||
}
|
||||
|
||||
void BuiltinUnit::lookupValue(ModuleDecl::AccessPathTy accessPath, DeclName name,
|
||||
NLKind lookupKind,
|
||||
void BuiltinUnit::lookupValue(DeclName name, NLKind lookupKind,
|
||||
SmallVectorImpl<ValueDecl*> &result) const {
|
||||
getCache().lookupValue(name.getBaseIdentifier(), lookupKind, *this, result);
|
||||
}
|
||||
@@ -569,10 +561,9 @@ void BuiltinUnit::lookupObjCMethods(
|
||||
// No @objc methods in the Builtin module.
|
||||
}
|
||||
|
||||
void SourceFile::lookupValue(ModuleDecl::AccessPathTy accessPath, DeclName name,
|
||||
NLKind lookupKind,
|
||||
void SourceFile::lookupValue(DeclName name, NLKind lookupKind,
|
||||
SmallVectorImpl<ValueDecl*> &result) const {
|
||||
getCache().lookupValue(accessPath, name, lookupKind, result);
|
||||
getCache().lookupValue(name, lookupKind, result);
|
||||
}
|
||||
|
||||
void ModuleDecl::lookupVisibleDecls(AccessPathTy AccessPath,
|
||||
|
||||
Reference in New Issue
Block a user