@@ -187,6 +187,7 @@ using namespace lldb;
187
187
using namespace lldb_private ;
188
188
189
189
char SwiftASTContext::ID;
190
+ char SwiftASTContextForModule::ID;
190
191
char SwiftASTContextForExpressions::ID;
191
192
192
193
CompilerType lldb_private::ToCompilerType (swift::Type qual_type) {
@@ -200,7 +201,7 @@ TypePayloadSwift::TypePayloadSwift(bool is_fixed_value_buffer) {
200
201
}
201
202
202
203
CompilerType SwiftASTContext::GetCompilerType (ConstString mangled_name) {
203
- return m_typeref_typesystem .GetTypeFromMangledTypename (mangled_name);
204
+ return GetTypeSystemSwiftTypeRef () .GetTypeFromMangledTypename (mangled_name);
204
205
}
205
206
206
207
CompilerType SwiftASTContext::GetCompilerType (swift::TypeBase *swift_type) {
@@ -216,7 +217,9 @@ swift::Type TypeSystemSwiftTypeRef::GetSwiftType(CompilerType compiler_type) {
216
217
// FIXME: Suboptimal performance, because the ConstString is looked up again.
217
218
ConstString mangled_name (
218
219
reinterpret_cast <const char *>(compiler_type.GetOpaqueQualType ()));
219
- return ts->m_swift_ast_context ->ReconstructType (mangled_name);
220
+ if (auto *swift_ast_context = ts->GetSwiftASTContext ())
221
+ return swift_ast_context->ReconstructType (mangled_name);
222
+ return {};
220
223
}
221
224
222
225
swift::Type SwiftASTContext::GetSwiftType (CompilerType compiler_type) {
@@ -899,14 +902,14 @@ static std::string GetClangModulesCacheProperty() {
899
902
}
900
903
901
904
#ifndef NDEBUG
902
- SwiftASTContext::SwiftASTContext () : m_typeref_typesystem( this ) {
905
+ SwiftASTContext::SwiftASTContext () {
903
906
llvm::dbgs () << " Initialized mock SwiftASTContext\n " ;
904
907
}
905
908
#endif
906
909
907
910
SwiftASTContext::SwiftASTContext (std::string description, llvm::Triple triple,
908
911
Target *target)
909
- : TypeSystemSwift(), m_typeref_typesystem( this ),
912
+ : TypeSystemSwift(),
910
913
m_compiler_invocation_ap(new swift::CompilerInvocation()) {
911
914
m_description = description;
912
915
@@ -1613,10 +1616,11 @@ static bool IsDWARFImported(swift::ModuleDecl &module) {
1613
1616
});
1614
1617
}
1615
1618
1616
- lldb::TypeSystemSP SwiftASTContext::CreateInstance (lldb::LanguageType language,
1617
- Module &module ,
1618
- Target *target,
1619
- bool fallback) {
1619
+ lldb::TypeSystemSP
1620
+ SwiftASTContext::CreateInstance (lldb::LanguageType language, Module &module ,
1621
+ TypeSystemSwiftTypeRef *typeref_typesystem,
1622
+ Target *target, bool fallback) {
1623
+ assert (((bool )fallback && (bool )target) != (bool )typeref_typesystem);
1620
1624
if (!SwiftASTContextSupportsLanguage (language))
1621
1625
return lldb::TypeSystemSP ();
1622
1626
@@ -1626,6 +1630,8 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1626
1630
ss << " SwiftASTContext" ;
1627
1631
if (fallback)
1628
1632
ss << " ForExpressions" ;
1633
+ else
1634
+ ss << " ForModule" ;
1629
1635
ss << ' (' << ' "' ;
1630
1636
module .GetDescription (ss, eDescriptionLevelBrief);
1631
1637
ss << ' "' << ' )' ;
@@ -1688,9 +1694,10 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
1688
1694
// If there is a target this may be a fallback scratch context.
1689
1695
assert ((!fallback || target) && " fallback context must specify a target" );
1690
1696
std::shared_ptr<SwiftASTContext> swift_ast_sp (
1691
- fallback ? (new SwiftASTContextForExpressions (m_description, *target))
1692
- : (new SwiftASTContext (
1693
- m_description,
1697
+ fallback ? static_cast <SwiftASTContext *>(
1698
+ new SwiftASTContextForExpressions (m_description, *target))
1699
+ : static_cast <SwiftASTContext *>(new SwiftASTContextForModule (
1700
+ *typeref_typesystem, m_description,
1694
1701
target ? target->GetArchitecture ().GetTriple () : triple,
1695
1702
target)));
1696
1703
bool suppress_config_log = false ;
@@ -1922,6 +1929,19 @@ static lldb::ModuleSP GetUnitTestModule(lldb_private::ModuleList &modules) {
1922
1929
return ModuleSP ();
1923
1930
}
1924
1931
1932
+ static SwiftASTContext *GetModuleSwiftASTContext (Module &module ) {
1933
+ auto type_system_or_err =
1934
+ module .GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
1935
+ if (!type_system_or_err) {
1936
+ llvm::consumeError (type_system_or_err.takeError ());
1937
+ return {};
1938
+ }
1939
+ auto *ts = static_cast <TypeSystemSwift *>(&*type_system_or_err);
1940
+ if (!ts)
1941
+ return {};
1942
+ return ts->GetSwiftASTContext ();
1943
+ }
1944
+
1925
1945
// / Scan a newly added lldb::Module for Swift modules and report any errors in
1926
1946
// / its module SwiftASTContext to Target.
1927
1947
static void
@@ -2002,16 +2022,7 @@ ProcessModule(ModuleSP module_sp, std::string m_description,
2002
2022
if (!HasSwiftModules (*module_sp))
2003
2023
return ;
2004
2024
2005
- auto type_system_or_err =
2006
- module_sp->GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
2007
- if (!type_system_or_err) {
2008
- llvm::consumeError (type_system_or_err.takeError ());
2009
- return ;
2010
- }
2011
-
2012
- SwiftASTContext *ast_context =
2013
- llvm::dyn_cast_or_null<SwiftASTContext>(&*type_system_or_err);
2014
-
2025
+ SwiftASTContext *ast_context = GetModuleSwiftASTContext (*module_sp);
2015
2026
if (!ast_context || ast_context->HasFatalErrors () ||
2016
2027
!ast_context->GetClangImporter ()) {
2017
2028
// Make sure we warn about this module load failure, the one
@@ -2163,11 +2174,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
2163
2174
for (size_t mi = 0 ; mi != num_images; ++mi) {
2164
2175
auto module_sp = target.GetImages ().GetModuleAtIndex (mi);
2165
2176
pool.async ([=] {
2166
- auto val_or_err =
2167
- module_sp->GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
2168
- if (!val_or_err) {
2169
- llvm::consumeError (val_or_err.takeError ());
2170
- }
2177
+ GetModuleSwiftASTContext (*module_sp);
2171
2178
});
2172
2179
}
2173
2180
pool.wait ();
@@ -2181,15 +2188,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
2181
2188
if (!HasSwiftModules (*module_sp))
2182
2189
continue ;
2183
2190
2184
- auto type_system_or_err =
2185
- module_sp->GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
2186
- if (!type_system_or_err) {
2187
- llvm::consumeError (type_system_or_err.takeError ());
2188
- continue ;
2189
- }
2190
-
2191
- auto *module_swift_ast =
2192
- llvm::dyn_cast_or_null<SwiftASTContext>(&*type_system_or_err);
2191
+ SwiftASTContext *module_swift_ast = GetModuleSwiftASTContext (*module_sp);
2193
2192
if (!module_swift_ast || module_swift_ast->HasFatalErrors () ||
2194
2193
!module_swift_ast->GetClangImporter ())
2195
2194
continue ;
@@ -2222,14 +2221,7 @@ lldb::TypeSystemSP SwiftASTContext::CreateInstance(lldb::LanguageType language,
2222
2221
auto get_executable_triple = [&]() -> llvm::Triple {
2223
2222
if (!exe_module_sp)
2224
2223
return {};
2225
- auto type_system_or_err =
2226
- exe_module_sp->GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
2227
- if (!type_system_or_err) {
2228
- llvm::consumeError (type_system_or_err.takeError ());
2229
- return {};
2230
- }
2231
- auto *exe_ast_ctx =
2232
- llvm::dyn_cast_or_null<SwiftASTContext>(&type_system_or_err.get ());
2224
+ auto *exe_ast_ctx = GetModuleSwiftASTContext (*exe_module_sp);
2233
2225
if (!exe_ast_ctx)
2234
2226
return {};
2235
2227
return exe_ast_ctx->GetLanguageOptions ().Target ;
@@ -3271,7 +3263,7 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
3271
3263
TypeSystemClang::GetSupportedLanguagesForTypes (),
3272
3264
searched_symbol_files, clang_types);
3273
3265
};
3274
- if (Module *module = m_swift_ast_ctx.GetModule ())
3266
+ if (Module *module = m_swift_ast_ctx.GetTypeSystemSwiftTypeRef (). GetModule ())
3275
3267
search (*module );
3276
3268
else if (TargetSP target_sp = m_swift_ast_ctx.GetTarget ().lock ()) {
3277
3269
// In a scratch context, check the module's DWARFImporterDelegates first.
@@ -3282,12 +3274,7 @@ class SwiftDWARFImporterDelegate : public swift::DWARFImporterDelegate {
3282
3274
auto images = target_sp->GetImages ();
3283
3275
for (size_t i = 0 ; i != images.GetSize (); ++i) {
3284
3276
auto module_sp = images.GetModuleAtIndex (i);
3285
- auto ts = module_sp->GetTypeSystemForLanguage (lldb::eLanguageTypeSwift);
3286
- if (!ts) {
3287
- llvm::consumeError (ts.takeError ());
3288
- continue ;
3289
- }
3290
- auto *swift_ast_ctx = static_cast <SwiftASTContext *>(&*ts);
3277
+ auto *swift_ast_ctx = GetModuleSwiftASTContext (*module_sp);
3291
3278
auto *dwarf_imp = static_cast <SwiftDWARFImporterDelegate *>(
3292
3279
swift_ast_ctx->GetDWARFImporterDelegate ());
3293
3280
if (!dwarf_imp || dwarf_imp == this )
@@ -4346,7 +4333,7 @@ CompilerType SwiftASTContext::GetAsClangType(ConstString mangled_name) {
4346
4333
// that look like they might be come from Objective-C (or C) as
4347
4334
// Clang types. LLDB's Objective-C part is very robust against
4348
4335
// malformed object pointers, so this isn't very risky.
4349
- Module *module = GetModule ();
4336
+ Module *module = GetTypeSystemSwiftTypeRef (). GetModule ();
4350
4337
if (!module )
4351
4338
return {};
4352
4339
auto type_system_or_err =
@@ -4811,7 +4798,7 @@ CompilerType SwiftASTContext::ImportType(CompilerType &type, Status &error) {
4811
4798
if (!mangled_name)
4812
4799
return {};
4813
4800
if (llvm::isa<TypeSystemSwiftTypeRef>(ts))
4814
- return m_typeref_typesystem .GetTypeFromMangledTypename (mangled_name);
4801
+ return GetTypeSystemSwiftTypeRef () .GetTypeFromMangledTypename (mangled_name);
4815
4802
swift::TypeBase *our_type_base =
4816
4803
m_mangled_name_to_type_map.lookup (mangled_name.GetCString ());
4817
4804
if (our_type_base)
@@ -5100,7 +5087,7 @@ void SwiftASTContext::PrintDiagnostics(DiagnosticManager &diagnostic_manager,
5100
5087
}
5101
5088
}
5102
5089
5103
- void SwiftASTContext ::ModulesDidLoad (ModuleList &module_list) {
5090
+ void SwiftASTContextForExpressions ::ModulesDidLoad (ModuleList &module_list) {
5104
5091
ClearModuleDependentCaches ();
5105
5092
5106
5093
// Scan the new modules for Swift contents and try to import it if
@@ -5562,7 +5549,7 @@ SwiftASTContext::GetAllocationStrategy(opaque_compiler_type_t type) {
5562
5549
5563
5550
CompilerType
5564
5551
SwiftASTContext::GetTypeRefType (lldb::opaque_compiler_type_t type) {
5565
- return m_typeref_typesystem .GetTypeFromMangledTypename (
5552
+ return GetTypeSystemSwiftTypeRef () .GetTypeFromMangledTypename (
5566
5553
GetMangledTypeName (type));
5567
5554
}
5568
5555
@@ -8335,6 +8322,7 @@ SwiftASTContextForExpressions::SwiftASTContextForExpressions(
8335
8322
std::string description, Target &target)
8336
8323
: SwiftASTContext(std::move(description),
8337
8324
target.GetArchitecture().GetTriple(), &target),
8325
+ m_typeref_typesystem(*this ),
8338
8326
m_persistent_state_up(new SwiftPersistentExpressionState) {}
8339
8327
8340
8328
UserExpression *SwiftASTContextForExpressions::GetUserExpression (
0 commit comments