Skip to content

Commit 83ef63f

Browse files
committed
simplify validation
1 parent 3e6a52c commit 83ef63f

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

Diff for: lldb/source/Plugins/TypeSystem/Swift/TypeSystemSwiftTypeRef.cpp

+17-28
Original file line numberDiff line numberDiff line change
@@ -2794,7 +2794,7 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
27942794
size_t data_byte_size, uint32_t bitfield_bit_size,
27952795
uint32_t bitfield_bit_offset, ExecutionContextScope *exe_scope,
27962796
bool is_base_class) {
2797-
auto impl = [&]() -> llvm::Optional<bool> {
2797+
auto impl = [&]() -> bool {
27982798
if (!type)
27992799
return false;
28002800

@@ -2894,7 +2894,13 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
28942894
}
28952895
}
28962896

2897-
return {};
2897+
// No result available from the runtime, fallback to the AST.
2898+
// This can happen in two cases:
2899+
// 1. MultiPayloadEnums not currently supported by Swift reflection
2900+
// 2. Some clang imported enums
2901+
return m_swift_ast_context->DumpTypeValue(
2902+
ReconstructType(type), s, format, data, data_offset, data_byte_size,
2903+
bitfield_bit_size, bitfield_bit_offset, exe_scope, is_base_class);
28982904
}
28992905
default:
29002906
assert(false && "Unhandled node kind");
@@ -2906,34 +2912,17 @@ bool TypeSystemSwiftTypeRef::DumpTypeValue(
29062912
};
29072913

29082914
#ifndef NDEBUG
2909-
auto result = impl();
2910-
if (!result) {
2911-
if (!m_swift_ast_context)
2912-
return false;
2913-
// Swift reflection provided no result, fallback to the AST.
2914-
return m_swift_ast_context->DumpTypeValue(
2915-
ReconstructType(type), s, format, data, data_offset, data_byte_size,
2916-
bitfield_bit_size, bitfield_bit_offset, exe_scope, is_base_class);
2917-
}
2918-
auto ast_type = ReconstructType(type);
2919-
if (!ast_type)
2920-
return false; /* missing .swiftmodule */
29212915
StreamString ast_s;
2922-
bool eq_result =
2923-
Equivalent(result, m_swift_ast_context->DumpTypeValue(
2924-
ast_type, &ast_s, format, data, data_offset,
2925-
data_byte_size, bitfield_bit_size,
2926-
bitfield_bit_offset, exe_scope, is_base_class));
2927-
bool eq_stream = Equivalent(ConstString(ast_s.GetString()),
2928-
ConstString(((StreamString *)s)->GetString()));
2929-
if (!eq_result || !eq_stream)
2930-
llvm::dbgs() << "failing type was " << (const char *)type << "\n";
2931-
assert(eq_result && eq_stream &&
2932-
"TypeSystemSwiftTypeRef diverges from SwiftASTContext");
2933-
return *result;
2934-
#else
2935-
return impl().getValueOr(false);
2916+
auto defer = llvm::make_scope_exit([&] {
2917+
assert(Equivalent(ConstString(ast_s.GetString()),
2918+
ConstString(((StreamString *)s)->GetString())) &&
2919+
"TypeSystemSwiftTypeRef diverges from SwiftASTContext");
2920+
});
29362921
#endif
2922+
VALIDATE_AND_RETURN(impl, DumpTypeValue, type,
2923+
(ReconstructType(type), &ast_s, format, data, data_offset,
2924+
data_byte_size, bitfield_bit_size, bitfield_bit_offset,
2925+
exe_scope, is_base_class));
29372926
}
29382927

29392928
void TypeSystemSwiftTypeRef::DumpTypeDescription(opaque_compiler_type_t type,

0 commit comments

Comments
 (0)