Matcher: Helper for checking the equivalence of two defined types.
| 456 | private: |
| 457 | /// Matcher: Helper for checking the equivalence of two defined types. |
| 458 | static bool isDefTypeEqual(Span<const SubType *const> LHSList, |
| 459 | uint32_t LHSIdx, |
| 460 | Span<const SubType *const> RHSList, |
| 461 | uint32_t RHSIdx) { |
| 462 | if (LHSList.data() == RHSList.data() && LHSIdx == RHSIdx) { |
| 463 | // Two type indices in the same module are the same. |
| 464 | return true; |
| 465 | } |
| 466 | const auto *LHSType = LHSList[LHSIdx]; |
| 467 | const auto *RHSType = RHSList[RHSIdx]; |
| 468 | // For GC proposal, a single subtype can be treated as a self-recursive |
| 469 | // type. That is, `(rec (type $t1 (func (param (ref $t1)))))` and |
| 470 | // `(type $t1 (func (param (ref $t1))))` are the same. |
| 471 | // Therefore, use the subtype length for the recursive type size. |
| 472 | const uint32_t LRecSize = LHSType->getRecursiveInfo().has_value() |
| 473 | ? LHSType->getRecursiveInfo()->RecTypeSize |
| 474 | : 1U; |
| 475 | const uint32_t RRecSize = RHSType->getRecursiveInfo().has_value() |
| 476 | ? RHSType->getRecursiveInfo()->RecTypeSize |
| 477 | : 1U; |
| 478 | if (LRecSize != RRecSize) { |
| 479 | // The two recursive type sizes are different, so they must not be the |
| 480 | // same. |
| 481 | return false; |
| 482 | } |
| 483 | if (LRecSize > 1) { |
| 484 | // Both are in a recursive type with > 1 subtypes. |
| 485 | if (LHSType->getRecursiveInfo()->Index != |
| 486 | RHSType->getRecursiveInfo()->Index) { |
| 487 | // The recursive indices should be the same. |
| 488 | return false; |
| 489 | } |
| 490 | // The recursive types should be the same. |
| 491 | uint32_t LStartIdx = LHSIdx - LHSType->getRecursiveInfo()->Index; |
| 492 | uint32_t RStartIdx = RHSIdx - RHSType->getRecursiveInfo()->Index; |
| 493 | return isRecTypeEqual(LHSList, LStartIdx, RHSList, RStartIdx, LRecSize); |
| 494 | } else { |
| 495 | // Both are composite types or self-recursive types. |
| 496 | return isRecTypeEqual(LHSList, LHSIdx, RHSList, RHSIdx, 1); |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | /// Matcher: Helper for checking the equivalence of two recursive types. |
| 501 | static bool isRecTypeEqual(Span<const SubType *const> LHSList, |
nothing calls this directly
no test coverage detected