@@ -1541,24 +1541,6 @@ bool Equivalent(llvm::Optional<T> l, T r) {
1541
1541
return Equivalent (l, llvm::Optional<T>(r));
1542
1542
}
1543
1543
1544
- template <typename T>
1545
- bool Equivalent (const std::vector<T> &l, const std::vector<T> &r) {
1546
- if (std::equal (l.begin (), l.end (), r.begin (), r.end ()))
1547
- return true ;
1548
-
1549
- auto join = [](const std::vector<T> &v) -> std::string {
1550
- if (v.empty ())
1551
- return {};
1552
- std::ostringstream buf;
1553
- buf << v[0 ];
1554
- for (size_t i = 1 ; i < v.size (); ++i)
1555
- buf << " , " << v[i];
1556
- return buf.str ();
1557
- };
1558
- llvm::dbgs () << join (l) << " != " << join (r) << " \n " ;
1559
- return false ;
1560
- }
1561
-
1562
1544
} // namespace
1563
1545
#endif
1564
1546
@@ -2399,17 +2381,43 @@ size_t TypeSystemSwiftTypeRef::GetIndexOfChildMemberWithName(
2399
2381
// checking the return value, plus the by-ref `child_indexes`.
2400
2382
if (!m_swift_ast_context)
2401
2383
return *index_size;
2402
- auto v_type = ReconstructType (type);
2403
- std::vector<uint32_t > v_child_indexes;
2404
- auto v_index_size = m_swift_ast_context->GetIndexOfChildMemberWithName (
2405
- v_type, name, exe_ctx, omit_empty_base_classes, v_child_indexes);
2406
- bool equivalent =
2407
- !v_type || (Equivalent (*index_size, v_index_size) &&
2408
- Equivalent (child_indexes, v_child_indexes));
2409
- if (!equivalent)
2410
- llvm::dbgs () << " failing type was " << (const char *)type << " \n " ;
2411
- assert (equivalent &&
2412
- " TypeSystemSwiftTypeRef diverges from SwiftASTContext" );
2384
+ auto ast_type = ReconstructType (type);
2385
+ if (!ast_type)
2386
+ return *index_size;
2387
+ std::vector<uint32_t > ast_child_indexes;
2388
+ auto ast_index_size = m_swift_ast_context->GetIndexOfChildMemberWithName (
2389
+ ast_type, name, exe_ctx, omit_empty_base_classes,
2390
+ ast_child_indexes);
2391
+ // The runtime has more info than the AST. No useful validation can be
2392
+ // done.
2393
+ if (*index_size > ast_index_size)
2394
+ return *index_size;
2395
+
2396
+ auto fail = [&]() {
2397
+ auto join = [](const auto &v) {
2398
+ std::ostringstream buf;
2399
+ buf << " {" ;
2400
+ for (const auto &item : v)
2401
+ buf << item << " ," ;
2402
+ buf.seekp (-1 , std::ios_base::end);
2403
+ buf << " }" ;
2404
+ return buf.str ();
2405
+ };
2406
+ llvm::dbgs () << join (child_indexes)
2407
+ << " != " << join (ast_child_indexes) << " \n " ;
2408
+ llvm::dbgs () << " failing type was " << (const char *)type
2409
+ << " , member was " << name << " \n " ;
2410
+ assert (false &&
2411
+ " TypeSystemSwiftTypeRef diverges from SwiftASTContext" );
2412
+ };
2413
+ if (*index_size != ast_index_size)
2414
+ fail ();
2415
+ for (unsigned i = 0 ; i < *index_size; ++i)
2416
+ if (child_indexes[i] < ast_child_indexes[i])
2417
+ // When the runtime may know know about more children. When this
2418
+ // happens, indexes will be larger. But if an index is smaller, that
2419
+ // means the runtime has dropped info somehow.
2420
+ fail ();
2413
2421
#endif
2414
2422
return *index_size;
2415
2423
}
0 commit comments