diff options
author | Thomas Lively <7121787+tlively@users.noreply.github.com> | 2022-02-08 10:55:23 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-08 18:55:23 +0000 |
commit | ac6c450b38b2fe4d049eef8aaa2acd56e3be9ae2 (patch) | |
tree | 0cdd0611d86cd27e6e3ab6cd75a7ef4f7d86c405 /test | |
parent | 419b7e23696c7dbd7e7c5464433cfd23da4157df (diff) | |
download | binaryen-ac6c450b38b2fe4d049eef8aaa2acd56e3be9ae2.tar.gz binaryen-ac6c450b38b2fe4d049eef8aaa2acd56e3be9ae2.tar.bz2 binaryen-ac6c450b38b2fe4d049eef8aaa2acd56e3be9ae2.zip |
Eagerly canonicalize basic types (#4507)
We were already eagerly canonicalizing basic HeapTypes when building types so
the more complicated canonicalization algorithms would not have to handle
noncanonical heap types, but we were not doing the same for Types. Equirecursive
canonicalization was properly handling noncanonical Types everywhere, but
isorecursive canonicalization was not. Rather than update isorecursive
canonicalization in multiple places, remove the special handling from
equirecursive canonicalization and canonicalize types in a single location.
Diffstat (limited to 'test')
-rw-r--r-- | test/gtest/type-builder.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/gtest/type-builder.cpp b/test/gtest/type-builder.cpp index 2a29d11b0..4ae9e0e63 100644 --- a/test/gtest/type-builder.cpp +++ b/test/gtest/type-builder.cpp @@ -457,3 +457,30 @@ TEST_F(IsorecursiveTest, CanonicalizeTypesBeforeSubtyping) { auto result = builder.build(); EXPECT_TRUE(result); } + +static void testCanonicalizeBasicTypes() { + TypeBuilder builder(5); + + Type externref = builder.getTempRefType(builder[0], Nullable); + Type externrefs = builder.getTempTupleType({externref, externref}); + + builder[0] = HeapType::ext; + builder[1] = Struct({Field(externref, Immutable)}); + builder[2] = Struct({Field(Type::externref, Immutable)}); + builder[3] = Signature(externrefs, Type::none); + builder[4] = Signature({Type::externref, Type::externref}, Type::none); + + auto result = builder.build(); + ASSERT_TRUE(result); + auto built = *result; + + EXPECT_EQ(built[1], built[2]); + EXPECT_EQ(built[3], built[4]); +} + +TEST_F(EquirecursiveTest, CanonicalizeBasicTypes) { + testCanonicalizeBasicTypes(); +} +TEST_F(IsorecursiveTest, CanonicalizeBasicTypes) { + testCanonicalizeBasicTypes(); +} |