Skip to content

Commit 1cb9b37

Browse files
committed
use Equivalent(Optional<T>, Optional<T>)
1 parent 9af8222 commit 1cb9b37

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ template <typename T> bool Equivalent(T l, T r) {
13281328

13291329
/// Specialization for GetTypeInfo().
13301330
template <> bool Equivalent<uint32_t>(uint32_t l, uint32_t r) {
1331-
if (l < r) {
1331+
if (l != r) {
13321332
// Failure. Dump it for easier debugging.
13331333
llvm::dbgs() << "TypeSystemSwiftTypeRef diverges from SwiftASTContext:\n";
13341334
#define HANDLE_ENUM_CASE(VAL, CASE) \
@@ -1399,7 +1399,7 @@ template <> bool Equivalent<uint32_t>(uint32_t l, uint32_t r) {
13991399
HANDLE_ENUM_CASE(r, eTypeIsBound);
14001400
llvm::dbgs() << "\n";
14011401
}
1402-
return l >= r;
1402+
return l == r;
14031403
}
14041404

14051405
/// Determine wether this demangle tree contains a sugar () node.
@@ -1508,10 +1508,9 @@ template <> bool Equivalent<ConstString>(ConstString l, ConstString r) {
15081508
return l == r;
15091509
}
15101510

1511-
/// Version taylored to GetBitSize & friends.
1512-
template <>
1513-
bool Equivalent<llvm::Optional<uint64_t>>(llvm::Optional<uint64_t> l,
1514-
llvm::Optional<uint64_t> r) {
1511+
/// Version tailored to GetBitSize & friends.
1512+
template <typename T>
1513+
bool Equivalent(llvm::Optional<T> l, llvm::Optional<T> r) {
15151514
if (l == r)
15161515
return true;
15171516
// There are situations where SwiftASTContext incorrectly returns
@@ -1526,6 +1525,12 @@ bool Equivalent<llvm::Optional<uint64_t>>(llvm::Optional<uint64_t> l,
15261525
return false;
15271526
}
15281527

1528+
// Introduced for `GetNumChildren`.
1529+
template <typename T>
1530+
bool Equivalent(llvm::Optional<T> l, T r) {
1531+
return Equivalent(l, llvm::Optional<T>(r));
1532+
}
1533+
15291534
} // namespace
15301535
#endif
15311536

@@ -2079,10 +2084,13 @@ TypeSystemSwiftTypeRef::GetNumChildren(opaque_compiler_type_t type,
20792084
SwiftLanguageRuntime::Get(exe_scope->CalculateProcess()))
20802085
if (auto num_children =
20812086
runtime->GetNumChildren(GetCanonicalType(type), nullptr)) {
2082-
auto impl = [&]() -> uint32_t { return *num_children; };
2083-
VALIDATE_AND_RETURN(
2084-
impl, GetNumChildren, type,
2085-
(ReconstructType(type), omit_empty_base_classes, exe_ctx));
2087+
// Use lambda to intercept and unwrap the `Optional` return value.
2088+
return [&]() {
2089+
auto impl = [&]() { return num_children; };
2090+
VALIDATE_AND_RETURN(
2091+
impl, GetNumChildren, type,
2092+
(ReconstructType(type), omit_empty_base_classes, exe_ctx));
2093+
}().getValue();
20862094
}
20872095

20882096
LLDB_LOGF(GetLogIfAllCategoriesSet(LIBLLDB_LOG_TYPES),

0 commit comments

Comments
 (0)