diff options
author | Alon Zakai <azakai@google.com> | 2022-10-13 13:22:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-13 20:22:40 +0000 |
commit | 7183a3be321ac76abcede1ecb05d5eea8d42d78f (patch) | |
tree | c0cd3071f17a741955505dd8eab34e92691426af /test | |
parent | b30ab74e349eed23f949ba92842ac474bd991607 (diff) | |
download | binaryen-7183a3be321ac76abcede1ecb05d5eea8d42d78f.tar.gz binaryen-7183a3be321ac76abcede1ecb05d5eea8d42d78f.tar.bz2 binaryen-7183a3be321ac76abcede1ecb05d5eea8d42d78f.zip |
[Wasm GC] Add a getMaxDepths() helper for heap types (#5134)
This computes how deep the children of a heap type are. This will be useful in
cone type optimizations, since we want to "normalize" cones: a cone of depth
infinity can just be a cone of the actual maximum depth of existing children, etc.,
and it's simpler to have a single canonical representation to avoid extra work.
Diffstat (limited to 'test')
-rw-r--r-- | test/gtest/type-builder.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/test/gtest/type-builder.cpp b/test/gtest/type-builder.cpp index cb2150974..d92057502 100644 --- a/test/gtest/type-builder.cpp +++ b/test/gtest/type-builder.cpp @@ -620,6 +620,35 @@ TEST_F(IsorecursiveTest, TestExistingSuperType) { EXPECT_EQ(B1.getHeapType(), B2.getHeapType()); } +// Test .getMaxDepths() helper. +TEST_F(NominalTest, TestMaxDepths) { + /* + A + | + B + */ + HeapType A, B; + { + TypeBuilder builder(2); + builder[0] = Struct(); + builder[1] = Struct(); + builder.setSubType(1, builder.getTempHeapType(0)); + auto result = builder.build(); + ASSERT_TRUE(result); + auto built = *result; + A = built[0]; + B = built[1]; + } + + SubTypes subTypes({A, B}); + auto maxDepths = subTypes.getMaxDepths(); + + EXPECT_EQ(maxDepths[B], Index(0)); + EXPECT_EQ(maxDepths[A], Index(1)); + EXPECT_EQ(maxDepths[HeapType::data], Index(2)); + EXPECT_EQ(maxDepths[HeapType::eq], Index(3)); +} + // Test .depth() helper. TEST_F(NominalTest, TestDepth) { HeapType A, B, C; |