From 098e02abadefe0e227c3c88a36e93d083ce004a8 Mon Sep 17 00:00:00 2001 From: Thomas Lively <7121787+tlively@users.noreply.github.com> Date: Fri, 28 Jan 2022 17:56:12 -0800 Subject: Isorecursive HeapType constructors (#4482) Update the HeapType constructors that take Signature, Structs, and Arrays to work properly with isorecursive typing. This is particularly important for the Signature constructor, which is used frequently throughout the code base. --- test/gtest/type-builder.cpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test') diff --git a/test/gtest/type-builder.cpp b/test/gtest/type-builder.cpp index 8f922380d..b6ed40262 100644 --- a/test/gtest/type-builder.cpp +++ b/test/gtest/type-builder.cpp @@ -402,3 +402,32 @@ TEST_F(IsorecursiveTest, CanonicalizeSupertypes) { EXPECT_NE(built[3], built[5]); EXPECT_NE(built[4], built[5]); } + +TEST_F(IsorecursiveTest, HeapTypeConstructors) { + HeapType sig(Signature(Type::i32, Type::i32)); + HeapType struct_(Struct({Field(Type(sig, Nullable), Mutable)})); + HeapType array(Field(Type(struct_, Nullable), Mutable)); + + TypeBuilder builder(3); + builder[0] = Signature(Type::i32, Type::i32); + Type sigRef = builder.getTempRefType(builder[0], Nullable); + builder[1] = Struct({Field(sigRef, Mutable)}); + Type structRef = builder.getTempRefType(builder[1], Nullable); + builder[2] = Array(Field(structRef, Mutable)); + + auto result = builder.build(); + ASSERT_TRUE(result); + auto built = *result; + + EXPECT_EQ(built[0], sig); + EXPECT_EQ(built[1], struct_); + EXPECT_EQ(built[2], array); + + HeapType sig2(Signature(Type::i32, Type::i32)); + HeapType struct2(Struct({Field(Type(sig, Nullable), Mutable)})); + HeapType array2(Field(Type(struct_, Nullable), Mutable)); + + EXPECT_EQ(sig, sig2); + EXPECT_EQ(struct_, struct2); + EXPECT_EQ(array, array2); +} -- cgit v1.2.3