@@ -195,6 +195,7 @@ using namespace lldb;
195
195
using namespace lldb_private ;
196
196
197
197
char SwiftASTContext::ID;
198
+ char SwiftASTContextForModule::ID;
198
199
char SwiftASTContextForExpressions::ID;
199
200
200
201
CompilerType lldb_private::ToCompilerType (swift::Type qual_type) {
@@ -208,7 +209,7 @@ TypePayloadSwift::TypePayloadSwift(bool is_fixed_value_buffer) {
208
209
}
209
210
210
211
CompilerType SwiftASTContext::GetCompilerType (ConstString mangled_name) {
211
- return m_typeref_typesystem .GetTypeFromMangledTypename (mangled_name);
212
+ return GetTypeSystemSwiftTypeRef () .GetTypeFromMangledTypename (mangled_name);
212
213
}
213
214
214
215
CompilerType SwiftASTContext::GetCompilerType (swift::TypeBase *swift_type) {
@@ -224,7 +225,9 @@ swift::Type TypeSystemSwiftTypeRef::GetSwiftType(CompilerType compiler_type) {
224
225
// FIXME: Suboptimal performance, because the ConstString is looked up again.
225
226
ConstString mangled_name (
226
227
reinterpret_cast <const char *>(compiler_type.GetOpaqueQualType ()));
227
- return ts->m_swift_ast_context ->ReconstructType (mangled_name);
228
+ if (auto *swift_ast_context = ts->GetSwiftASTContext ())
229
+ return swift_ast_context->ReconstructType (mangled_name);
230
+ return {};
228
231
}
229
232
230
233
swift::Type SwiftASTContext::GetSwiftType (CompilerType compiler_type) {
@@ -907,14 +910,14 @@ static std::string GetClangModulesCacheProperty() {
907
910
}
908
911
909
912
#ifndef NDEBUG
910
- SwiftASTContext::SwiftASTContext () : m_typeref_typesystem( this ) {
913
+ SwiftASTContext::SwiftASTContext () {
911
914
llvm::dbgs () << " Initialized mock SwiftASTContext\n " ;
912
915
}
913
916
#endif
914
917
915
918
SwiftASTContext::SwiftASTContext (std::string description, llvm::Triple triple,
916
919
Target *target)
917
- : TypeSystemSwift(), m_typeref_typesystem( this ),
920
+ : TypeSystemSwift(),
918
921
m_compiler_invocation_ap(new swift::CompilerInvocation()) {
919
922
m_description = description;
920
923
@@ -1633,10 +1636,11 @@ static bool IsDWARFImported(swift::ModuleDecl &module) {
1633
1636
});
1634
1637
}
1635
1638
1636
- lldb::TypeSystemSP SwiftASTContext::CreateInstance (lldb::LanguageType language,
1637
- Module &module ,
1638
- Target *target,
1639
- bool fallback) {
1639
+ lldb::TypeSystemSP
1640
+ SwiftASTContext::CreateInstance (lldb::LanguageType language, Module &module ,
1641
+ TypeSystemSwiftTypeRef *typeref_typesystem,
1642
+ Target *target, bool fallback) {
1643
+ assert (((bool )fallback && (bool )target) != (bool )typeref_typesystem);
1640
1644
if (!SwiftASTContextSupportsLanguage (language))
1641
1645
return lldb::TypeSystemSP ();
1642
1646
@@ -1646,6 +1650,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1646
1650
ss << " SwiftASTContext" ;
1647
1651
if (fallback)
1648
1652
ss << " ForExpressions" ;
1653
+ else
1654
+ ss << " ForModule" ;
1649
1655
ss << ' (' << ' "' ;
1650
1656
module .GetDescription (ss, eDescriptionLevelBrief);
1651
1657
ss << ' "' << ' )' ;
@@ -1708,9 +1714,10 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1708
1714
// If there is a target this may be a fallback scratch context.
1709
1715
assert ((!fallback || target) && " fallback context must specify a target" );
1710
1716
std::shared_ptr<SwiftASTContext> swift_ast_sp (
1711
- fallback ? (new SwiftASTContextForExpressions (m_description, *target))
1712
- : (new SwiftASTContext (
1713
- m_description,
1717
+ fallback ? static_cast <SwiftASTContext *>(
1718
+ new SwiftASTContextForExpressions (m_description, *target))
1719
+ : static_cast <SwiftASTContext *>(new SwiftASTContextForModule (
1720
+ *typeref_typesystem, m_description,
1714
1721
target ? target->GetArchitecture ().GetTriple () : triple,
1715
1722
target)));
1716
1723
bool suppress_config_log = false ;
@@ -1942,6 +1949,19 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
1942
1949
return ModuleSP ();
1943
1950
}
1944
1951
1952
+ static SwiftASTContext *GetModuleSwiftASTContext (Module &module ) {
1953
+ auto type_system_or_err =
1954
+ module .GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
1955
+ if (!type_system_or_err) {
1956
+ llvm::consumeError (type_system_or_err.takeError ());
1957
+ return {};
1958
+ }
1959
+ auto *ts = static_cast <TypeSystemSwift *>(&*type_system_or_err);
1960
+ if (!ts)
1961
+ return {};
1962
+ return ts->GetSwiftASTContext ();
1963
+ }
1964
+
1945
1965
// / Scan a newly added lldb::Module for Swift modules and report any errors in
1946
1966
// / its module SwiftASTContext to Target.
1947
1967
static void
@@ -2022,16 +2042,7 @@ ProcessModule(ModuleSP module_sp, std::string m_description,
2022
2042
if (!HasSwiftModules (*module_sp))
2023
2043
return ;
2024
2044
2025
- auto type_system_or_err =
2026
- module_sp->GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
2027
- if (!type_system_or_err) {
2028
- llvm::consumeError (type_system_or_err.takeError ());
2029
- return ;
2030
- }
2031
-
2032
- SwiftASTContext *ast_context =
2033
- llvm::dyn_cast_or_null<SwiftASTContext>(&*type_system_or_err);
2034
-
2045
+ SwiftASTContext *ast_context = GetModuleSwiftASTContext (*module_sp);
2035
2046
if (!ast_context || ast_context->HasFatalErrors () ||
2036
2047
!ast_context->GetClangImporter ()) {
2037
2048
// Make sure we warn about this module load failure, the one
@@ -2183,11 +2194,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
2183
2194
for (size_t mi = 0 ; mi != num_images; ++mi) {
2184
2195
auto module_sp = target.GetImages ().GetModuleAtIndex (mi);
2185
2196
pool.async ([=] {
2186
- auto val_or_err =
2187
- module_sp->GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
2188
- if (!val_or_err) {
2189
- llvm::consumeError (val_or_err.takeError ());
2190
- }
2197
+ GetModuleSwiftASTContext (*module_sp);
2191
2198
});
2192
2199
}
2193
2200
pool.wait ();
@@ -2201,15 +2208,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
2201
2208
if (!HasSwiftModules (*module_sp))
2202
2209
continue ;
2203
2210
2204
- auto type_system_or_err =
2205
- module_sp->GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
2206
- if (!type_system_or_err) {
2207
- llvm::consumeError (type_system_or_err.takeError ());
2208
- continue ;
2209
- }
2210
-
2211
- auto *module_swift_ast =
2212
- llvm::dyn_cast_or_null<SwiftASTContext>(&*type_system_or_err);
2211
+ SwiftASTContext *module_swift_ast = GetModuleSwiftASTContext (*module_sp);
2213
2212
if (!module_swift_ast || module_swift_ast->HasFatalErrors () ||
2214
2213
!module_swift_ast->GetClangImporter ())
2215
2214
continue ;
@@ -2242,14 +2241,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
2242
2241
auto get_executable_triple = [&]() -> llvm::Triple {
2243
2242
if (!exe_module_sp)
2244
2243
return {};
2245
- auto type_system_or_err =
2246
- exe_module_sp->GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
2247
- if (!type_system_or_err) {
2248
- llvm::consumeError (type_system_or_err.takeError ());
2249
- return {};
2250
- }
2251
- auto *exe_ast_ctx =
2252
- llvm::dyn_cast_or_null<SwiftASTContext>(&type_system_or_err.get ());
2244
+ auto *exe_ast_ctx = GetModuleSwiftASTContext (*exe_module_sp);
2253
2245
if (!exe_ast_ctx)
2254
2246
return {};
2255
2247
return exe_ast_ctx->GetLanguageOptions ().Target ;
@@ -3293,7 +3285,7 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
3293
3285
TypeSystemClang::GetSupportedLanguagesForTypes (),
3294
3286
searched_symbol_files, clang_types);
3295
3287
};
3296
- if (Module *module = m_swift_ast_ctx.GetModule ())
3288
+ if (Module *module = m_swift_ast_ctx.GetTypeSystemSwiftTypeRef (). GetModule ())
3297
3289
search (*module );
3298
3290
else if (TargetSP target_sp = m_swift_ast_ctx.GetTarget ().lock ()) {
3299
3291
// In a scratch context, check the module's DWARFImporterDelegates first.
@@ -3304,12 +3296,7 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
3304
3296
auto images = target_sp->GetImages ();
3305
3297
for (size_t i = 0 ; i != images.GetSize (); ++i) {
3306
3298
auto module_sp = images.GetModuleAtIndex (i);
3307
- auto ts = module_sp->GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
3308
- if (!ts) {
3309
- llvm::consumeError (ts.takeError ());
3310
- continue ;
3311
- }
3312
- auto *swift_ast_ctx = static_cast <SwiftASTContext *>(&*ts);
3299
+ auto *swift_ast_ctx = GetModuleSwiftASTContext (*module_sp);
3313
3300
auto *dwarf_imp = static_cast <SwiftDWARFImporterDelegate *>(
3314
3301
swift_ast_ctx->GetDWARFImporterDelegate ());
3315
3302
if (!dwarf_imp || dwarf_imp == this )
@@ -4368,7 +4355,7 @@ CompilerType SwiftASTContext::GetAsClangType(ConstString mangled_name) {
4368
4355
// that look like they might be come from Objective-C (or C) as
4369
4356
// Clang types. LLDB's Objective-C part is very robust against
4370
4357
// malformed object pointers, so this isn't very risky.
4371
- Module *module = GetModule ();
4358
+ Module *module = GetTypeSystemSwiftTypeRef (). GetModule ();
4372
4359
if (!module )
4373
4360
return {};
4374
4361
auto type_system_or_err =
@@ -4833,7 +4820,7 @@ CompilerType SwiftASTContext::ImportType(CompilerType &type, Status &error) {
4833
4820
if (!mangled_name)
4834
4821
return {};
4835
4822
if (llvm::isa<TypeSystemSwiftTypeRef>(ts))
4836
- return m_typeref_typesystem .GetTypeFromMangledTypename (mangled_name);
4823
+ return GetTypeSystemSwiftTypeRef () .GetTypeFromMangledTypename (mangled_name);
4837
4824
swift::TypeBase *our_type_base =
4838
4825
m_mangled_name_to_type_map.lookup (mangled_name.GetCString ());
4839
4826
if (our_type_base)
@@ -5122,7 +5109,7 @@ void SwiftASTContext::PrintDiagnostics(DiagnosticManager &diagnostic_manager,
5122
5109
}
5123
5110
}
5124
5111
5125
- void SwiftASTContext ::ModulesDidLoad (ModuleList &module_list) {
5112
+ void SwiftASTContextForExpressions ::ModulesDidLoad (ModuleList &module_list) {
5126
5113
ClearModuleDependentCaches ();
5127
5114
5128
5115
// Scan the new modules for Swift contents and try to import it if
@@ -5581,7 +5568,7 @@ SwiftASTContext::GetAllocationStrategy(opaque_compiler_type_t type) {
5581
5568
5582
5569
CompilerType
5583
5570
SwiftASTContext::GetTypeRefType (lldb::opaque_compiler_type_t type) {
5584
- return m_typeref_typesystem .GetTypeFromMangledTypename (
5571
+ return GetTypeSystemSwiftTypeRef () .GetTypeFromMangledTypename (
5585
5572
GetMangledTypeName (type));
5586
5573
}
5587
5574
@@ -8372,6 +8359,7 @@ SwiftASTContextForExpressions::SwiftASTContextForExpressions(
8372
8359
std::string description, Target &target)
8373
8360
: SwiftASTContext(std::move(description),
8374
8361
target.GetArchitecture().GetTriple(), &target),
8362
+ m_typeref_typesystem(*this ),
8375
8363
m_persistent_state_up(new SwiftPersistentExpressionState) {}
8376
8364
8377
8365
UserExpression *SwiftASTContextForExpressions::GetUserExpression (
0 commit comments