From ac6c450b38b2fe4d049eef8aaa2acd56e3be9ae2 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Tue, 8 Feb 2022 10:55:23 -0800 Subject: 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. --- test/gtest/type-builder.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'test') 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(); +} -- cgit v1.2.3