@@ -1561,9 +1561,8 @@ static bool IsPrivateNSClass(NodePointer node) {
1561
1561
}
1562
1562
1563
1563
bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Class (
1564
- ValueObject &in_value, SwiftASTContextForExpressions &scratch_ctx,
1565
- lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name,
1566
- Address &address) {
1564
+ ValueObject &in_value, lldb::DynamicValueType use_dynamic,
1565
+ TypeAndOrName &class_type_or_name, Address &address) {
1567
1566
AddressType address_type;
1568
1567
lldb::addr_t instance_ptr = in_value.GetPointerValue (&address_type);
1569
1568
if (instance_ptr == LLDB_INVALID_ADDRESS || instance_ptr == 0 )
@@ -1612,7 +1611,17 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Class(
1612
1611
class_type_or_name.SetCompilerType (ts.RemangleAsType (dem, node));
1613
1612
1614
1613
#ifndef NDEBUG
1615
- auto &remote_ast = GetRemoteASTContext (scratch_ctx);
1614
+ // Dynamic type resolution in RemoteAST might pull in other Swift modules, so
1615
+ // use the scratch context where such operations are legal and safe.
1616
+ llvm::Optional<SwiftScratchContextReader> maybe_scratch_ctx =
1617
+ in_value.GetSwiftScratchContext ();
1618
+ if (!maybe_scratch_ctx)
1619
+ return false ;
1620
+ SwiftASTContextForExpressions *scratch_ctx = maybe_scratch_ctx->get ();
1621
+ if (!scratch_ctx)
1622
+ return true ;
1623
+
1624
+ auto &remote_ast = GetRemoteASTContext (*scratch_ctx);
1616
1625
auto remote_ast_metadata_address = remote_ast.getHeapMetadataForObject (
1617
1626
swift::remote::RemoteAddress (instance_ptr));
1618
1627
if (remote_ast_metadata_address) {
@@ -1705,14 +1714,24 @@ bool SwiftLanguageRuntimeImpl::IsValidErrorValue(ValueObject &in_value) {
1705
1714
1706
1715
bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Protocol (
1707
1716
ValueObject &in_value, CompilerType protocol_type,
1708
- SwiftASTContextForExpressions &scratch_ctx,
1709
1717
lldb::DynamicValueType use_dynamic, TypeAndOrName &class_type_or_name,
1710
1718
Address &address) {
1711
1719
auto remote_ast_impl = [&](bool use_local_buffer,
1712
1720
lldb::addr_t existential_address)
1713
1721
-> llvm::Optional<std::pair<CompilerType, Address>> {
1722
+ // Dynamic type resolution in RemoteAST might pull in other Swift modules,
1723
+ // so
1724
+ // use the scratch context where such operations are legal and safe.
1725
+ llvm::Optional<SwiftScratchContextReader> maybe_scratch_ctx =
1726
+ in_value.GetSwiftScratchContext ();
1727
+ if (!maybe_scratch_ctx)
1728
+ return {};
1729
+ SwiftASTContextForExpressions *scratch_ctx = maybe_scratch_ctx->get ();
1730
+ if (!scratch_ctx)
1731
+ return {};
1732
+
1714
1733
swift::remote::RemoteAddress remote_existential (existential_address);
1715
- auto &remote_ast = GetRemoteASTContext (scratch_ctx);
1734
+ auto &remote_ast = GetRemoteASTContext (* scratch_ctx);
1716
1735
auto swift_type = GetSwiftType (protocol_type);
1717
1736
if (!swift_type)
1718
1737
return {};
@@ -1737,11 +1756,6 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Protocol(
1737
1756
};
1738
1757
1739
1758
Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
1740
-
1741
- auto &target = m_process.GetTarget ();
1742
- assert (IsScratchContextLocked (target) &&
1743
- " Swift scratch context not locked ahead" );
1744
-
1745
1759
auto *tss =
1746
1760
llvm::dyn_cast_or_null<TypeSystemSwift>(protocol_type.GetTypeSystem ());
1747
1761
if (!tss) {
@@ -2017,9 +2031,6 @@ CompilerType
2017
2031
SwiftLanguageRuntimeImpl::BindGenericTypeParameters (StackFrame &stack_frame,
2018
2032
CompilerType base_type) {
2019
2033
LLDB_SCOPED_TIMER ();
2020
- auto &target = m_process.GetTarget ();
2021
- assert (IsScratchContextLocked (target) &&
2022
- " Swift scratch context not locked ahead of archetype binding" );
2023
2034
2024
2035
// If this is a TypeRef type, bind that.
2025
2036
auto sc = stack_frame.GetSymbolContext (lldb::eSymbolContextEverything);
@@ -2029,6 +2040,10 @@ SwiftLanguageRuntimeImpl::BindGenericTypeParameters(StackFrame &stack_frame,
2029
2040
base_type.GetMangledTypeName ());
2030
2041
2031
2042
Status error;
2043
+ auto &target = m_process.GetTarget ();
2044
+ assert (IsScratchContextLocked (target) &&
2045
+ " Swift scratch context not locked ahead of archetype binding" );
2046
+
2032
2047
// A failing Clang import in a module context permanently damages
2033
2048
// that module context. Binding archetypes can trigger an import of
2034
2049
// another module, so switch to a scratch context where such an
@@ -2545,59 +2560,26 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress(
2545
2560
if (!CouldHaveDynamicValue (in_value))
2546
2561
return false ;
2547
2562
2548
- // Dynamic type resolution in RemoteAST might pull in other Swift modules, so
2549
- // use the scratch context where such operations are legal and safe.
2550
- assert (IsScratchContextLocked (in_value.GetTargetSP ()) &&
2551
- " Swift scratch context not locked ahead of dynamic type resolution" );
2552
- llvm::Optional<SwiftScratchContextReader> maybe_scratch_ctx =
2553
- in_value.GetSwiftScratchContext ();
2554
- if (!maybe_scratch_ctx)
2555
- return false ;
2556
- SwiftASTContextForExpressions *scratch_ctx = maybe_scratch_ctx->get ();
2557
-
2558
- auto retry_once = [&]() {
2559
- // Retry exactly once using the per-module fallback scratch context.
2560
- auto &target = m_process.GetTarget ();
2561
- if (!target.UseScratchTypesystemPerModule ()) {
2562
- Log *log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_TYPES));
2563
- if (log)
2564
- log->Printf (" Dynamic type resolution detected fatal errors in "
2565
- " shared Swift state. Falling back to per-module "
2566
- " scratch context.\n " );
2567
- target.SetUseScratchTypesystemPerModule (true );
2568
- return GetDynamicTypeAndAddress (in_value, use_dynamic, class_type_or_name,
2569
- address, value_type);
2570
- }
2571
- return false ;
2572
- };
2573
-
2574
- if (scratch_ctx->HasFatalErrors ())
2575
- return retry_once ();
2576
-
2577
- // Import the type into the scratch context. Any form of dynamic
2578
- // type resolution may trigger a cross-module import.
2579
2563
CompilerType val_type (in_value.GetCompilerType ());
2580
2564
Flags type_info (val_type.GetTypeInfo ());
2581
2565
if (!type_info.AnySet (eTypeIsSwift))
2582
2566
return false ;
2583
2567
2584
2568
bool success = false ;
2585
2569
bool is_indirect_enum_case = IsIndirectEnumCase (in_value);
2586
- // Type kinds with metadata don't need archetype binding .
2570
+ // Type kinds with instance metadata don't need generic type resolution .
2587
2571
if (is_indirect_enum_case)
2588
- // ..._IndirectEnumCase() recurses, no need to bind archetypes.
2589
2572
success = GetDynamicTypeAndAddress_IndirectEnumCase (
2590
2573
in_value, use_dynamic, class_type_or_name, address);
2591
2574
else if (type_info.AnySet (eTypeIsClass) ||
2592
2575
type_info.AllSet (eTypeIsBuiltIn | eTypeIsPointer | eTypeHasValue))
2593
- success = GetDynamicTypeAndAddress_Class (
2594
- in_value, *scratch_ctx, use_dynamic, class_type_or_name, address);
2576
+ success = GetDynamicTypeAndAddress_Class (in_value, use_dynamic,
2577
+ class_type_or_name, address);
2595
2578
else if (type_info.AnySet (eTypeIsProtocol))
2596
- success = GetDynamicTypeAndAddress_Protocol (in_value, val_type,
2597
- *scratch_ctx, use_dynamic,
2579
+ success = GetDynamicTypeAndAddress_Protocol (in_value, val_type, use_dynamic,
2598
2580
class_type_or_name, address);
2599
2581
else {
2600
- // Perform archetype binding in the scratch context .
2582
+ // Perform generic type resolution .
2601
2583
StackFrameSP frame = in_value.GetExecutionContextRef ().GetFrameSP ();
2602
2584
if (!frame)
2603
2585
return false ;
@@ -2608,12 +2590,11 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress(
2608
2590
2609
2591
Flags subst_type_info (bound_type.GetTypeInfo ());
2610
2592
if (subst_type_info.AnySet (eTypeIsClass)) {
2611
- success = GetDynamicTypeAndAddress_Class (
2612
- in_value, *scratch_ctx, use_dynamic, class_type_or_name, address);
2593
+ success = GetDynamicTypeAndAddress_Class (in_value, use_dynamic,
2594
+ class_type_or_name, address);
2613
2595
} else if (subst_type_info.AnySet (eTypeIsProtocol)) {
2614
- success = GetDynamicTypeAndAddress_Protocol (in_value, bound_type,
2615
- *scratch_ctx, use_dynamic,
2616
- class_type_or_name, address);
2596
+ success = GetDynamicTypeAndAddress_Protocol (
2597
+ in_value, bound_type, use_dynamic, class_type_or_name, address);
2617
2598
} else {
2618
2599
success = GetDynamicTypeAndAddress_Value (
2619
2600
in_value, bound_type, use_dynamic, class_type_or_name, address);
@@ -2623,8 +2604,6 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress(
2623
2604
if (success)
2624
2605
value_type = GetValueType (in_value, class_type_or_name.GetCompilerType (),
2625
2606
is_indirect_enum_case);
2626
- else if (scratch_ctx->HasFatalErrors ())
2627
- return retry_once ();
2628
2607
return success;
2629
2608
}
2630
2609
0 commit comments