Skip to content

Commit 27de569

Browse files
committed
Separate out the per-module and expression versions of LookupClangType (NFC)
1 parent 3584ad1 commit 27de569

File tree

2 files changed

+30
-25
lines changed

2 files changed

+30
-25
lines changed

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ GetMangledName(swift::Demangle::Demangler &dem,
190190
return mangleNode(global);
191191
}
192192

193-
/// Find a Clang type by name in the modules in \p module_holder.
194193
TypeSP TypeSystemSwiftTypeRef::LookupClangType(StringRef name_ref) {
195194
llvm::SmallVector<CompilerContext, 2> decl_context;
196195
// Make up a decl context for non-nested types.
@@ -199,40 +198,40 @@ TypeSP TypeSystemSwiftTypeRef::LookupClangType(StringRef name_ref) {
199198
return LookupClangType(name_ref, decl_context);
200199
}
201200

202-
/// Find a Clang type by name in the modules in \p module_holder.
203-
TypeSP TypeSystemSwiftTypeRef::LookupClangType(
204-
StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context) {
205-
201+
/// Look up one Clang type in a module.
202+
static TypeSP LookupClangType(Module &m,
203+
llvm::ArrayRef<CompilerContext> decl_context) {
206204
TypeQuery query(decl_context, TypeQueryOptions::e_find_one |
207205
TypeQueryOptions::e_module_search);
208206
query.SetLanguages(TypeSystemClang::GetSupportedLanguagesForTypes());
207+
TypeResults results;
208+
m.FindTypes(query, results);
209+
return results.GetFirstType();
210+
}
209211

210-
auto lookup = [&](Module &M) -> TypeSP {
211-
TypeResults results;
212-
M.FindTypes(query, results);
213-
return results.GetFirstType();
214-
};
212+
TypeSP TypeSystemSwiftTypeRef::LookupClangType(
213+
StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context) {
214+
Module *m = GetModule();
215+
if (!m)
216+
return {};
217+
return ::LookupClangType(const_cast<Module &>(*m), decl_context);
218+
}
215219

220+
TypeSP TypeSystemSwiftTypeRefForExpressions::LookupClangType(
221+
StringRef name_ref, llvm::ArrayRef<CompilerContext> decl_context) {
216222
// Check the cache first. Negative results are also cached.
217223
TypeSP result;
218224
ConstString name(name_ref);
219225
if (m_clang_type_cache.Lookup(name.AsCString(), result))
220226
return result;
221227

222-
if (auto *M = GetModule()) {
223-
TypeSP result = lookup(*M);
224-
// Cache it.
225-
m_clang_type_cache.Insert(name.AsCString(), result);
226-
return result;
227-
}
228-
229228
TargetSP target_sp = GetTargetWP().lock();
230229
if (!target_sp)
231230
return {};
232-
target_sp->GetImages().ForEach([&](const ModuleSP &module) -> bool {
231+
target_sp->GetImages().ForEach([&](const ModuleSP &m) -> bool {
233232
// Don't recursively call into LookupClangTypes() to avoid filling
234233
// hundreds of image caches with negative results.
235-
result = lookup(const_cast<Module &>(*module));
234+
result = ::LookupClangType(const_cast<Module &>(*m), decl_context);
236235
// Cache it in the expression context.
237236
if (result)
238237
m_clang_type_cache.Insert(name.AsCString(), result);

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,10 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
383383
lldb::TypeSP LookupClangType(llvm::StringRef name_ref);
384384

385385
/// Search the debug info for a Clang type with the specified name and decl
386-
/// context, and cache the result.
387-
lldb::TypeSP LookupClangType(llvm::StringRef name_ref,
388-
llvm::ArrayRef<CompilerContext> decl_context);
386+
/// context.
387+
virtual lldb::TypeSP
388+
LookupClangType(llvm::StringRef name_ref,
389+
llvm::ArrayRef<CompilerContext> decl_context);
389390

390391
/// Attempts to convert a Clang type into a Swift type.
391392
/// For example, int is converted to Int32.
@@ -491,8 +492,6 @@ class TypeSystemSwiftTypeRef : public TypeSystemSwift {
491492

492493
/// All lldb::Type pointers produced by DWARFASTParser Swift go here.
493494
ThreadSafeDenseMap<const char *, lldb::TypeSP> m_swift_type_map;
494-
/// Map ConstString Clang type identifiers to Clang types.
495-
ThreadSafeDenseMap<const char *, lldb::TypeSP> m_clang_type_cache;
496495
};
497496

498497
/// This one owns a SwiftASTContextForExpressions.
@@ -535,8 +534,13 @@ class TypeSystemSwiftTypeRefForExpressions : public TypeSystemSwiftTypeRef {
535534
/// Forwards to SwiftASTContext.
536535
PersistentExpressionState *GetPersistentExpressionState() override;
537536
Status PerformCompileUnitImports(const SymbolContext &sc);
538-
/// Returns how often ModulesDidLoad was called/
537+
/// Returns how often ModulesDidLoad was called.
539538
unsigned GetGeneration() const { return m_generation; }
539+
/// Performs a target-wide search.
540+
lldb::TypeSP
541+
LookupClangType(llvm::StringRef name_ref,
542+
llvm::ArrayRef<CompilerContext> decl_context) override;
543+
540544

541545
friend class SwiftASTContextForExpressions;
542546
protected:
@@ -553,6 +557,8 @@ class TypeSystemSwiftTypeRefForExpressions : public TypeSystemSwiftTypeRef {
553557
/// Perform all the implicit imports for the current frame.
554558
mutable std::unique_ptr<SymbolContext> m_initial_symbol_context_up;
555559
std::unique_ptr<SwiftPersistentExpressionState> m_persistent_state_up;
560+
/// Map ConstString Clang type identifiers to Clang types.
561+
ThreadSafeDenseMap<const char *, lldb::TypeSP> m_clang_type_cache;
556562
};
557563

558564
} // namespace lldb_private

0 commit comments

Comments
 (0)