@@ -1752,17 +1752,16 @@ ConstString TypeSystemSwiftTypeRef::GetSwiftModuleFor(const SymbolContext &sc) {
1752
1752
return {};
1753
1753
}
1754
1754
1755
- SwiftASTContext * TypeSystemSwiftTypeRef::GetSwiftASTContextFromExecutionScope (
1755
+ SymbolContext TypeSystemSwiftTypeRef::GetSymbolContext (
1756
1756
ExecutionContextScope *exe_scope) const {
1757
- if (exe_scope) {
1758
- ExecutionContext exe_ctx;
1759
- exe_scope->CalculateExecutionContext (exe_ctx);
1760
- return GetSwiftASTContextFromExecutionContext (&exe_ctx);
1761
- }
1762
- return GetSwiftASTContextFromExecutionContext (nullptr );
1757
+ if (!exe_scope)
1758
+ return {};
1759
+ ExecutionContext exe_ctx;
1760
+ exe_scope->CalculateExecutionContext (exe_ctx);
1761
+ return GetSymbolContext (&exe_ctx);
1763
1762
}
1764
1763
1765
- SwiftASTContext * TypeSystemSwiftTypeRef::GetSwiftASTContextFromExecutionContext (
1764
+ SymbolContext TypeSystemSwiftTypeRef::GetSymbolContext (
1766
1765
const ExecutionContext *exe_ctx) const {
1767
1766
SymbolContext sc;
1768
1767
if (exe_ctx) {
@@ -1776,16 +1775,17 @@ SwiftASTContext *TypeSystemSwiftTypeRef::GetSwiftASTContextFromExecutionContext(
1776
1775
if (auto target_sp = GetTargetWP ().lock ())
1777
1776
sc = SymbolContext (target_sp, target_sp->GetExecutableModule ());
1778
1777
1778
+ return sc;
1779
+ }
1780
+
1781
+ SwiftASTContext *
1782
+ TypeSystemSwiftTypeRef::GetSwiftASTContext (const SymbolContext &sc) const {
1779
1783
if (!sc.module_sp ) {
1780
- LLDB_LOGF (GetLog (LLDBLog::Types),
1784
+ LLDB_LOGV (GetLog (LLDBLog::Types),
1781
1785
" Cannot create a SwiftASTContext without an execution context" );
1782
1786
return nullptr ;
1783
1787
}
1784
- return GetSwiftASTContext (sc);
1785
- }
1786
1788
1787
- SwiftASTContext *
1788
- TypeSystemSwiftTypeRef::GetSwiftASTContext (const SymbolContext &sc) const {
1789
1789
std::lock_guard<std::mutex> guard (m_swift_ast_context_lock);
1790
1790
// There is only one per-module context.
1791
1791
const char *key = nullptr ;
@@ -1810,6 +1810,12 @@ TypeSystemSwiftTypeRef::GetSwiftASTContext(const SymbolContext &sc) const {
1810
1810
1811
1811
SwiftASTContext *TypeSystemSwiftTypeRefForExpressions::GetSwiftASTContext (
1812
1812
const SymbolContext &sc) const {
1813
+ if (!sc.module_sp ) {
1814
+ LLDB_LOGV (GetLog (LLDBLog::Types),
1815
+ " Cannot create a SwiftASTContext without an execution context" );
1816
+ return nullptr ;
1817
+ }
1818
+
1813
1819
// Compute the cache key.
1814
1820
const char *key = nullptr ;
1815
1821
ConstString module = GetSwiftModuleFor (sc);
@@ -1951,7 +1957,7 @@ TypeSystemSwiftTypeRef::GetMangledTypeName(opaque_compiler_type_t type) {
1951
1957
1952
1958
void *TypeSystemSwiftTypeRef::ReconstructType (opaque_compiler_type_t type,
1953
1959
const ExecutionContext *exe_ctx) {
1954
- if (auto *swift_ast_context = GetSwiftASTContextFromExecutionContext ( exe_ctx))
1960
+ if (auto *swift_ast_context = GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
1955
1961
return llvm::expectedToStdOptional (
1956
1962
swift_ast_context->ReconstructType (GetMangledTypeName (type)))
1957
1963
.value_or (nullptr );
@@ -1970,7 +1976,7 @@ CompilerType
1970
1976
TypeSystemSwiftTypeRef::ReconstructType (CompilerType type,
1971
1977
const ExecutionContext *exe_ctx) {
1972
1978
assert (type.GetTypeSystem ().dyn_cast_or_null <TypeSystemSwiftTypeRef>());
1973
- if (auto *swift_ast_context = GetSwiftASTContextFromExecutionContext ( exe_ctx))
1979
+ if (auto *swift_ast_context = GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
1974
1980
return {swift_ast_context->weak_from_this (),
1975
1981
ReconstructType (type.GetOpaqueQualType (), exe_ctx)};
1976
1982
return {};
@@ -2362,7 +2368,7 @@ constexpr ExecutionContextScope *g_no_exe_ctx = nullptr;
2362
2368
.GetSwiftValidateTypeSystem ()) \
2363
2369
return result; \
2364
2370
ExecutionContext _exe_ctx (EXE_CTX); \
2365
- if (!GetSwiftASTContextFromExecutionContext ( &_exe_ctx)) \
2371
+ if (!GetSwiftASTContext ( GetSymbolContext ( &_exe_ctx))) \
2366
2372
return result; \
2367
2373
if (ShouldSkipValidation (TYPE)) \
2368
2374
return result; \
@@ -2377,8 +2383,9 @@ constexpr ExecutionContextScope *g_no_exe_ctx = nullptr;
2377
2383
_exe_ctx == ExecutionContext () ? nullptr : &_exe_ctx); \
2378
2384
bool equivalent = \
2379
2385
!ReconstructType (TYPE) /* missing .swiftmodule */ || \
2380
- (Equivalent (result, GetSwiftASTContextFromExecutionContext (&_exe_ctx) \
2381
- ->REFERENCE ARGS)); \
2386
+ (Equivalent ( \
2387
+ result, \
2388
+ GetSwiftASTContext (GetSymbolContext (&_exe_ctx))->REFERENCE ARGS)); \
2382
2389
if (!equivalent) \
2383
2390
llvm::dbgs () << " failing type was " << (const char *)TYPE << " \n " ; \
2384
2391
assert (equivalent && \
@@ -2393,7 +2400,7 @@ constexpr ExecutionContextScope *g_no_exe_ctx = nullptr;
2393
2400
.GetSwiftValidateTypeSystem ()) \
2394
2401
return result; \
2395
2402
ExecutionContext _exe_ctx (EXE_CTX); \
2396
- if (!GetSwiftASTContextFromExecutionContext ( &_exe_ctx)) \
2403
+ if (!GetSwiftASTContext ( GetSymbolContext ( &_exe_ctx))) \
2397
2404
return result; \
2398
2405
if (ShouldSkipValidation (TYPE)) \
2399
2406
return result; \
@@ -2411,7 +2418,7 @@ constexpr ExecutionContextScope *g_no_exe_ctx = nullptr;
2411
2418
equivalent = \
2412
2419
(Equivalent (llvm::expectedToStdOptional (std::move (result)), \
2413
2420
llvm::expectedToStdOptional ( \
2414
- GetSwiftASTContextFromExecutionContext ( &_exe_ctx) \
2421
+ GetSwiftASTContext ( GetSymbolContext ( &_exe_ctx)) \
2415
2422
->REFERENCE ARGS))); \
2416
2423
} else { /* missing .swiftmodule */ \
2417
2424
if (!result) \
@@ -3111,7 +3118,7 @@ TypeSystemSwiftTypeRef::GetBitSize(opaque_compiler_type_t type,
3111
3118
AsMangledName (type));
3112
3119
3113
3120
if (auto *swift_ast_context =
3114
- GetSwiftASTContextFromExecutionScope ( exe_scope))
3121
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) ))
3115
3122
return swift_ast_context->GetBitSize (ReconstructType (type, exe_scope),
3116
3123
exe_scope);
3117
3124
}
@@ -3158,7 +3165,7 @@ TypeSystemSwiftTypeRef::GetByteStride(opaque_compiler_type_t type,
3158
3165
" Couldn't compute stride of type %s using SwiftLanguageRuntime." ,
3159
3166
AsMangledName (type));
3160
3167
if (auto *swift_ast_context =
3161
- GetSwiftASTContextFromExecutionScope ( exe_scope))
3168
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) ))
3162
3169
return swift_ast_context->GetByteStride (ReconstructType (type), exe_scope);
3163
3170
return {};
3164
3171
};
@@ -3279,7 +3286,7 @@ TypeSystemSwiftTypeRef::GetNumChildren(opaque_compiler_type_t type,
3279
3286
AsMangledName (type));
3280
3287
3281
3288
// Try SwiftASTContext.
3282
- if (auto *swift_ast_context = GetSwiftASTContextFromExecutionContext ( exe_ctx))
3289
+ if (auto *swift_ast_context = GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3283
3290
if (auto n = llvm::expectedToStdOptional (swift_ast_context->GetNumChildren (
3284
3291
ReconstructType (type, exe_ctx), omit_empty_base_classes,
3285
3292
exe_ctx))) {
@@ -3340,7 +3347,7 @@ uint32_t TypeSystemSwiftTypeRef::GetNumFields(opaque_compiler_type_t type,
3340
3347
" Using SwiftASTContext::GetNumFields fallback for type %s" ,
3341
3348
AsMangledName (type));
3342
3349
3343
- if (auto *swift_ast_context = GetSwiftASTContextFromExecutionContext ( exe_ctx))
3350
+ if (auto *swift_ast_context = GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3344
3351
return swift_ast_context->GetNumFields (ReconstructType (type, exe_ctx), exe_ctx);
3345
3352
return {};
3346
3353
}
@@ -3415,7 +3422,7 @@ TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
3415
3422
" Had to engage SwiftASTContext fallback for type {0}, field #{1}." ,
3416
3423
AsMangledName (type), idx);
3417
3424
if (auto *swift_ast_context =
3418
- GetSwiftASTContextFromExecutionContext ( exe_ctx))
3425
+ GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3419
3426
return swift_ast_context->GetChildCompilerTypeAtIndex (
3420
3427
ReconstructType (type, exe_ctx), exe_ctx, idx, transparent_pointers,
3421
3428
omit_empty_base_classes, ignore_array_bounds, child_name,
@@ -3430,7 +3437,7 @@ TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
3430
3437
if (ast_num_children)
3431
3438
return *ast_num_children;
3432
3439
if (auto *swift_ast_context =
3433
- GetSwiftASTContextFromExecutionContext ( exe_ctx))
3440
+ GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3434
3441
ast_num_children = llvm::expectedToStdOptional (
3435
3442
swift_ast_context->GetNumChildren (ReconstructType (type, exe_ctx),
3436
3443
omit_empty_base_classes, exe_ctx));
@@ -3693,15 +3700,15 @@ size_t TypeSystemSwiftTypeRef::GetIndexOfChildMemberWithName(
3693
3700
if (!ModuleList::GetGlobalModuleListProperties ()
3694
3701
.GetSwiftValidateTypeSystem ())
3695
3702
return index_size;
3696
- if (!GetSwiftASTContextFromExecutionContext ( exe_ctx))
3703
+ if (!GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3697
3704
return index_size;
3698
3705
auto swift_scratch_ctx_lock = SwiftScratchContextLock (exe_ctx);
3699
3706
auto ast_type = ReconstructType (type, exe_ctx);
3700
3707
if (!ast_type)
3701
3708
return index_size;
3702
3709
std::vector<uint32_t > ast_child_indexes;
3703
3710
auto ast_index_size =
3704
- GetSwiftASTContextFromExecutionContext ( exe_ctx)
3711
+ GetSwiftASTContext ( GetSymbolContext ( exe_ctx) )
3705
3712
->GetIndexOfChildMemberWithName (ast_type, name, exe_ctx,
3706
3713
omit_empty_base_classes,
3707
3714
ast_child_indexes);
@@ -3741,7 +3748,7 @@ size_t TypeSystemSwiftTypeRef::GetIndexOfChildMemberWithName(
3741
3748
" type %s" ,
3742
3749
AsMangledName (type));
3743
3750
3744
- if (auto *swift_ast_context = GetSwiftASTContextFromExecutionContext ( exe_ctx))
3751
+ if (auto *swift_ast_context = GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3745
3752
return swift_ast_context->GetIndexOfChildMemberWithName (
3746
3753
ReconstructType (type, exe_ctx), name, exe_ctx, omit_empty_base_classes,
3747
3754
child_indexes);
@@ -4039,7 +4046,7 @@ TypeSystemSwiftTypeRef::GetInstanceType(opaque_compiler_type_t type,
4039
4046
// type alias in the REPL. In these cases, fallback to asking the AST
4040
4047
// for the canonical type.
4041
4048
if (auto *swift_ast_context =
4042
- GetSwiftASTContextFromExecutionScope ( exe_scope))
4049
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) ))
4043
4050
return swift_ast_context->GetInstanceType (
4044
4051
ReconstructType (type, exe_scope), exe_scope);
4045
4052
return {};
@@ -4283,7 +4290,7 @@ void TypeSystemSwiftTypeRef::DumpTypeDescription(
4283
4290
// Also dump the swift ast context info, as this functions should not be in
4284
4291
// any critical path.
4285
4292
if (auto *swift_ast_context =
4286
- GetSwiftASTContextFromExecutionScope ( exe_scope)) {
4293
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) )) {
4287
4294
s->PutCString (" Source code info:\n " );
4288
4295
swift_ast_context->DumpTypeDescription (
4289
4296
ReconstructType (type, exe_scope), s, print_help_if_available,
@@ -4419,7 +4426,7 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
4419
4426
// No result available from the runtime, fallback to the AST. This occurs
4420
4427
// for some Clang imported enums.
4421
4428
if (auto *swift_ast_context =
4422
- GetSwiftASTContextFromExecutionScope ( exe_scope)) {
4429
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) )) {
4423
4430
ExecutionContext exe_ctx;
4424
4431
exe_scope->CalculateExecutionContext (exe_ctx);
4425
4432
if (swift_ast_context->DumpTypeValue (
@@ -4438,7 +4445,7 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
4438
4445
// typedefs such as CFString in the REPL. More investigation is
4439
4446
// needed.
4440
4447
if (auto *swift_ast_context =
4441
- GetSwiftASTContextFromExecutionScope ( exe_scope))
4448
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) ))
4442
4449
return swift_ast_context->DumpTypeValue (
4443
4450
ReconstructType (type, exe_scope), s, format, data, data_offset,
4444
4451
data_byte_size, bitfield_bit_size, bitfield_bit_offset, exe_scope,
@@ -4463,7 +4470,7 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
4463
4470
bool unresolved_typealias = false ;
4464
4471
CollectTypeInfo (dem, node, unresolved_typealias);
4465
4472
if (!node || unresolved_typealias) {
4466
- if (auto swift_ast_ctx = GetSwiftASTContextFromExecutionScope ( exe_scope))
4473
+ if (auto swift_ast_ctx = GetSwiftASTContext ( GetSymbolContext ( exe_scope) ))
4467
4474
return swift_ast_ctx->DumpTypeValue (
4468
4475
ReconstructType (type, exe_scope), s, format, data, data_offset,
4469
4476
data_byte_size, bitfield_bit_size, bitfield_bit_offset, exe_scope,
@@ -4541,7 +4548,7 @@ TypeSystemSwiftTypeRef::GetTypeBitAlign(opaque_compiler_type_t type,
4541
4548
// defined in the expression. In that case we don't have debug
4542
4549
// info for it, so defer to SwiftASTContext.
4543
4550
if (llvm::isa_and_nonnull<SwiftASTContextForExpressions>(
4544
- GetSwiftASTContextFromExecutionScope ( exe_scope))) {
4551
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) ))) {
4545
4552
ExecutionContext exe_ctx;
4546
4553
if (exe_scope)exe_scope->CalculateExecutionContext (exe_ctx);
4547
4554
return ReconstructType ({weak_from_this (), type}, &exe_ctx)
0 commit comments