Skip to content

Commit 48fd6e6

Browse files
committed
fallback to SwiftASTContext for unsupported cases
1 parent dae5d8a commit 48fd6e6

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2786,7 +2786,7 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
27862786
size_t data_byte_size, uint32_t bitfield_bit_size,
27872787
uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope,
27882788
bool is_base_class) {
2789-
auto impl = [&]() -> bool {
2789+
auto impl = [&]() -> llvm::Optional<bool> {
27902790
if (!type)
27912791
return false;
27922792

@@ -2892,17 +2892,34 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
28922892
};
28932893

28942894
#ifndef NDEBUG
2895+
auto result = impl();
2896+
if (!result) {
2897+
if (!m_swift_ast_context)
2898+
return false;
2899+
// Swift reflection provided no result, fallback to the AST.
2900+
return m_swift_ast_context->DumpTypeValue(
2901+
ReconstructType(type), s, format, data, data_offset, data_byte_size,
2902+
bitfield_bit_size, bitfield_bit_offset, exe_scope, is_base_class);
2903+
}
2904+
auto ast_type = ReconstructType(type);
2905+
if (!ast_type)
2906+
return false; /* missing .swiftmodule */
28952907
StreamString ast_s;
2896-
auto defer = llvm::make_scope_exit([&] {
2897-
assert(Equivalent(ConstString(ast_s.GetString()),
2898-
ConstString(((StreamString *)s)->GetString())) &&
2899-
"TypeSystemSwiftTypeRef diverges from SwiftASTContext");
2900-
});
2908+
bool eq_result =
2909+
Equivalent(result, m_swift_ast_context->DumpTypeValue(
2910+
ast_type, &ast_s, format, data, data_offset,
2911+
data_byte_size, bitfield_bit_size,
2912+
bitfield_bit_offset, exe_scope, is_base_class));
2913+
bool eq_stream = Equivalent(ConstString(ast_s.GetString()),
2914+
ConstString(((StreamString *)s)->GetString()));
2915+
if (!eq_result || !eq_stream)
2916+
llvm::dbgs() << "failing type was " << (const char *)type << "\n";
2917+
assert(eq_result && eq_stream &&
2918+
"TypeSystemSwiftTypeRef diverges from SwiftASTContext");
2919+
return *result;
2920+
#else
2921+
return impl().getValueOr(false);
29012922
#endif
2902-
VALIDATE_AND_RETURN(impl, DumpTypeValue, type,
2903-
(ReconstructType(type), &ast_s, format, data, data_offset,
2904-
data_byte_size, bitfield_bit_size, bitfield_bit_offset,
2905-
exe_scope, is_base_class));
29062923
}
29072924

29082925
void TypeSystemSwiftTypeRef::DumpTypeDescription(opaque_compiler_type_t type,

0 commit comments

Comments
 (0)