Skip to content

Commit 793dbed

Browse files
Merge pull request #26707 from adrian-prantl/filter
DWARFImporter: Allow filtering type lookups by containing module.
2 parents e066ab3 + d7c63da commit 793dbed

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

include/swift/ClangImporter/ClangImporter.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ class DWARFImporterDelegate {
8787
virtual ~DWARFImporterDelegate() = default;
8888
/// Perform a qualified lookup of a Clang type with this name.
8989
/// \param kind Only return results with this type kind.
90+
/// \param inModule only return results from this module.
9091
virtual void lookupValue(StringRef name, llvm::Optional<ClangTypeKind> kind,
92+
StringRef inModule,
9193
SmallVectorImpl<clang::Decl *> &results) {}
9294
/// vtable anchor.
9395
virtual void anchor();

lib/ClangImporter/DWARFImporter.cpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ void DWARFImporterDelegate::anchor() {}
2121
/// loading of types is done on demand, this class is effectively empty.
2222
class DWARFModuleUnit final : public LoadedFile {
2323
~DWARFModuleUnit() = default;
24-
ClangImporter::Implementation &owner;
24+
ClangImporter::Implementation &Owner;
2525

2626
public:
2727
DWARFModuleUnit(ModuleDecl &M, ClangImporter::Implementation &owner)
28-
: LoadedFile(FileUnitKind::DWARFModule, M), owner(owner) {}
28+
: LoadedFile(FileUnitKind::DWARFModule, M), Owner(owner) {}
2929

3030
virtual bool isSystemModule() const override { return false; }
3131

@@ -35,7 +35,8 @@ class DWARFModuleUnit final : public LoadedFile {
3535
lookupValue(ModuleDecl::AccessPathTy accessPath, DeclName name,
3636
NLKind lookupKind,
3737
SmallVectorImpl<ValueDecl *> &results) const override {
38-
owner.lookupValueDWARF(accessPath, name, lookupKind, results);
38+
Owner.lookupValueDWARF(accessPath, name, lookupKind,
39+
getParentModule()->getName(), results);
3940
}
4041

4142
virtual TypeDecl *
@@ -110,7 +111,7 @@ ModuleDecl *ClangImporter::Implementation::loadModuleDWARF(
110111
auto *decl = ModuleDecl::create(name, SwiftContext);
111112
decl->setIsNonSwiftModule();
112113
decl->setHasResolvedImports();
113-
auto wrapperUnit = new (SwiftContext) DWARFModuleUnit(*decl, *this);
114+
auto *wrapperUnit = new (SwiftContext) DWARFModuleUnit(*decl, *this);
114115
DWARFModuleUnits.insert({name, wrapperUnit});
115116
decl->addFile(*wrapperUnit);
116117

@@ -127,7 +128,7 @@ ModuleDecl *ClangImporter::Implementation::loadModuleDWARF(
127128

128129
void ClangImporter::Implementation::lookupValueDWARF(
129130
ModuleDecl::AccessPathTy accessPath, DeclName name, NLKind lookupKind,
130-
SmallVectorImpl<ValueDecl *> &results) {
131+
Identifier inModule, SmallVectorImpl<ValueDecl *> &results) {
131132
if (!swift::ModuleDecl::matchesAccessPath(accessPath, name))
132133
return;
133134

@@ -138,7 +139,8 @@ void ClangImporter::Implementation::lookupValueDWARF(
138139
return;
139140

140141
SmallVector<clang::Decl *, 4> decls;
141-
DWARFImporter->lookupValue(name.getBaseIdentifier().str(), None, decls);
142+
DWARFImporter->lookupValue(name.getBaseIdentifier().str(), None,
143+
inModule.str(), decls);
142144
for (auto *clangDecl : decls) {
143145
auto *namedDecl = dyn_cast<clang::NamedDecl>(clangDecl);
144146
if (!namedDecl)
@@ -160,8 +162,9 @@ void ClangImporter::Implementation::lookupTypeDeclDWARF(
160162
if (!DWARFImporter)
161163
return;
162164

165+
/// This function is invoked by ASTDemangler, which doesn't filter by module.
163166
SmallVector<clang::Decl *, 1> decls;
164-
DWARFImporter->lookupValue(rawName, kind, decls);
167+
DWARFImporter->lookupValue(rawName, kind, {}, decls);
165168
for (auto *clangDecl : decls) {
166169
if (!isa<clang::TypeDecl>(clangDecl) &&
167170
!isa<clang::ObjCContainerDecl>(clangDecl) &&

lib/ClangImporter/ImporterImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1324,8 +1324,9 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
13241324

13251325
/// Look for namespace-scope values with the given name using the
13261326
/// DWARFImporterDelegate.
1327+
/// \param inModule only return results from this module.
13271328
void lookupValueDWARF(ModuleDecl::AccessPathTy accessPath, DeclName name,
1328-
NLKind lookupKind,
1329+
NLKind lookupKind, Identifier inModule,
13291330
SmallVectorImpl<ValueDecl *> &results);
13301331

13311332
/// Look for top-level scope types with a name and kind using the

0 commit comments

Comments
 (0)