@@ -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
};
@@ -3277,7 +3284,7 @@ TypeSystemSwiftTypeRef::GetNumChildren(opaque_compiler_type_t type,
3277
3284
AsMangledName (type));
3278
3285
3279
3286
// Try SwiftASTContext.
3280
- if (auto *swift_ast_context = GetSwiftASTContextFromExecutionContext ( exe_ctx))
3287
+ if (auto *swift_ast_context = GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3281
3288
if (auto n = llvm::expectedToStdOptional (swift_ast_context->GetNumChildren (
3282
3289
ReconstructType (type, exe_ctx), omit_empty_base_classes,
3283
3290
exe_ctx))) {
@@ -3338,7 +3345,7 @@ uint32_t TypeSystemSwiftTypeRef::GetNumFields(opaque_compiler_type_t type,
3338
3345
" Using SwiftASTContext::GetNumFields fallback for type %s" ,
3339
3346
AsMangledName (type));
3340
3347
3341
- if (auto *swift_ast_context = GetSwiftASTContextFromExecutionContext ( exe_ctx))
3348
+ if (auto *swift_ast_context = GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3342
3349
return swift_ast_context->GetNumFields (ReconstructType (type, exe_ctx), exe_ctx);
3343
3350
return {};
3344
3351
}
@@ -3413,7 +3420,7 @@ TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
3413
3420
" Had to engage SwiftASTContext fallback for type {0}, field #{1}." ,
3414
3421
AsMangledName (type), idx);
3415
3422
if (auto *swift_ast_context =
3416
- GetSwiftASTContextFromExecutionContext ( exe_ctx))
3423
+ GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3417
3424
return swift_ast_context->GetChildCompilerTypeAtIndex (
3418
3425
ReconstructType (type, exe_ctx), exe_ctx, idx, transparent_pointers,
3419
3426
omit_empty_base_classes, ignore_array_bounds, child_name,
@@ -3428,7 +3435,7 @@ TypeSystemSwiftTypeRef::GetChildCompilerTypeAtIndex(
3428
3435
if (ast_num_children)
3429
3436
return *ast_num_children;
3430
3437
if (auto *swift_ast_context =
3431
- GetSwiftASTContextFromExecutionContext ( exe_ctx))
3438
+ GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3432
3439
ast_num_children = llvm::expectedToStdOptional (
3433
3440
swift_ast_context->GetNumChildren (ReconstructType (type, exe_ctx),
3434
3441
omit_empty_base_classes, exe_ctx));
@@ -3691,15 +3698,15 @@ size_t TypeSystemSwiftTypeRef::GetIndexOfChildMemberWithName(
3691
3698
if (!ModuleList::GetGlobalModuleListProperties ()
3692
3699
.GetSwiftValidateTypeSystem ())
3693
3700
return index_size;
3694
- if (!GetSwiftASTContextFromExecutionContext ( exe_ctx))
3701
+ if (!GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3695
3702
return index_size;
3696
3703
auto swift_scratch_ctx_lock = SwiftScratchContextLock (exe_ctx);
3697
3704
auto ast_type = ReconstructType (type, exe_ctx);
3698
3705
if (!ast_type)
3699
3706
return index_size;
3700
3707
std::vector<uint32_t > ast_child_indexes;
3701
3708
auto ast_index_size =
3702
- GetSwiftASTContextFromExecutionContext ( exe_ctx)
3709
+ GetSwiftASTContext ( GetSymbolContext ( exe_ctx) )
3703
3710
->GetIndexOfChildMemberWithName (ast_type, name, exe_ctx,
3704
3711
omit_empty_base_classes,
3705
3712
ast_child_indexes);
@@ -3739,7 +3746,7 @@ size_t TypeSystemSwiftTypeRef::GetIndexOfChildMemberWithName(
3739
3746
" type %s" ,
3740
3747
AsMangledName (type));
3741
3748
3742
- if (auto *swift_ast_context = GetSwiftASTContextFromExecutionContext ( exe_ctx))
3749
+ if (auto *swift_ast_context = GetSwiftASTContext ( GetSymbolContext ( exe_ctx) ))
3743
3750
return swift_ast_context->GetIndexOfChildMemberWithName (
3744
3751
ReconstructType (type, exe_ctx), name, exe_ctx, omit_empty_base_classes,
3745
3752
child_indexes);
@@ -4037,7 +4044,7 @@ TypeSystemSwiftTypeRef::GetInstanceType(opaque_compiler_type_t type,
4037
4044
// type alias in the REPL. In these cases, fallback to asking the AST
4038
4045
// for the canonical type.
4039
4046
if (auto *swift_ast_context =
4040
- GetSwiftASTContextFromExecutionScope ( exe_scope))
4047
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) ))
4041
4048
return swift_ast_context->GetInstanceType (
4042
4049
ReconstructType (type, exe_scope), exe_scope);
4043
4050
return {};
@@ -4281,7 +4288,7 @@ void TypeSystemSwiftTypeRef::DumpTypeDescription(
4281
4288
// Also dump the swift ast context info, as this functions should not be in
4282
4289
// any critical path.
4283
4290
if (auto *swift_ast_context =
4284
- GetSwiftASTContextFromExecutionScope ( exe_scope)) {
4291
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) )) {
4285
4292
s->PutCString (" Source code info:\n " );
4286
4293
swift_ast_context->DumpTypeDescription (
4287
4294
ReconstructType (type, exe_scope), s, print_help_if_available,
@@ -4417,7 +4424,7 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
4417
4424
// No result available from the runtime, fallback to the AST. This occurs
4418
4425
// for some Clang imported enums.
4419
4426
if (auto *swift_ast_context =
4420
- GetSwiftASTContextFromExecutionScope ( exe_scope)) {
4427
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) )) {
4421
4428
ExecutionContext exe_ctx;
4422
4429
exe_scope->CalculateExecutionContext (exe_ctx);
4423
4430
if (swift_ast_context->DumpTypeValue (
@@ -4436,7 +4443,7 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
4436
4443
// typedefs such as CFString in the REPL. More investigation is
4437
4444
// needed.
4438
4445
if (auto *swift_ast_context =
4439
- GetSwiftASTContextFromExecutionScope ( exe_scope))
4446
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) ))
4440
4447
return swift_ast_context->DumpTypeValue (
4441
4448
ReconstructType (type, exe_scope), s, format, data, data_offset,
4442
4449
data_byte_size, bitfield_bit_size, bitfield_bit_offset, exe_scope,
@@ -4461,7 +4468,7 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
4461
4468
bool unresolved_typealias = false ;
4462
4469
CollectTypeInfo (dem, node, unresolved_typealias);
4463
4470
if (!node || unresolved_typealias) {
4464
- if (auto swift_ast_ctx = GetSwiftASTContextFromExecutionScope ( exe_scope))
4471
+ if (auto swift_ast_ctx = GetSwiftASTContext ( GetSymbolContext ( exe_scope) ))
4465
4472
return swift_ast_ctx->DumpTypeValue (
4466
4473
ReconstructType (type, exe_scope), s, format, data, data_offset,
4467
4474
data_byte_size, bitfield_bit_size, bitfield_bit_offset, exe_scope,
@@ -4539,7 +4546,7 @@ TypeSystemSwiftTypeRef::GetTypeBitAlign(opaque_compiler_type_t type,
4539
4546
// defined in the expression. In that case we don't have debug
4540
4547
// info for it, so defer to SwiftASTContext.
4541
4548
if (llvm::isa_and_nonnull<SwiftASTContextForExpressions>(
4542
- GetSwiftASTContextFromExecutionScope ( exe_scope))) {
4549
+ GetSwiftASTContext ( GetSymbolContext ( exe_scope) ))) {
4543
4550
ExecutionContext exe_ctx;
4544
4551
if (exe_scope)exe_scope->CalculateExecutionContext (exe_ctx);
4545
4552
return ReconstructType ({weak_from_this (), type}, &exe_ctx)
0 commit comments