summaryrefslogtreecommitdiff
path: root/test/gtest
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2024-06-12 12:30:28 -0700
committerGitHub <noreply@github.com>2024-06-12 12:30:28 -0700
commit0e1187664ebf93bd268ba7d77813441a4874d998 (patch)
tree5a71076f179d4edfd3cdb811676ccd5c420e582b /test/gtest
parentac21c8cc9204e09fab070d2fd915e7ab583a5dac (diff)
downloadbinaryen-0e1187664ebf93bd268ba7d77813441a4874d998.tar.gz
binaryen-0e1187664ebf93bd268ba7d77813441a4874d998.tar.bz2
binaryen-0e1187664ebf93bd268ba7d77813441a4874d998.zip
[threads] Parse, build, and print shared composite types (#6654)
Parse the text format for shared composite types as described in the shared-everything thread proposal. Update the parser to use 'comptype' instead of 'strtype' to match the final GC spec and add the new syntactic class 'sharecomptype'. Update the type canonicalization logic to take sharedness into account to avoid merging shared and unshared types. Make the same change in the TypeMerging pass. Ensure that shared and unshared types cannot be in a subtype relationship with each other. Follow-up PRs will add shared abstract heap types, binary parsing and emitting for shared types, and fuzzer support for shared types.
Diffstat (limited to 'test/gtest')
-rw-r--r--test/gtest/type-builder.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/gtest/type-builder.cpp b/test/gtest/type-builder.cpp
index 443a7ee66..c0a27b229 100644
--- a/test/gtest/type-builder.cpp
+++ b/test/gtest/type-builder.cpp
@@ -273,6 +273,40 @@ TEST_F(TypeTest, InvalidFinalSupertype) {
EXPECT_EQ(error->index, 1u);
}
+TEST_F(TypeTest, InvalidSharedSupertype) {
+ TypeBuilder builder(2);
+ builder[0] = Struct{};
+ builder[1] = Struct{};
+ builder[0].setShared(true);
+ builder[1].setShared(false);
+ builder[1].subTypeOf(builder[0]);
+
+ auto result = builder.build();
+ EXPECT_FALSE(result);
+
+ const auto* error = result.getError();
+ ASSERT_TRUE(error);
+ EXPECT_EQ(error->reason, TypeBuilder::ErrorReason::InvalidSupertype);
+ EXPECT_EQ(error->index, 1u);
+}
+
+TEST_F(TypeTest, InvalidUnsharedSupertype) {
+ TypeBuilder builder(2);
+ builder[0] = Struct{};
+ builder[1] = Struct{};
+ builder[0].setShared(false);
+ builder[1].setShared(true);
+ builder[1].subTypeOf(builder[0]);
+
+ auto result = builder.build();
+ EXPECT_FALSE(result);
+
+ const auto* error = result.getError();
+ ASSERT_TRUE(error);
+ EXPECT_EQ(error->reason, TypeBuilder::ErrorReason::InvalidSupertype);
+ EXPECT_EQ(error->index, 1u);
+}
+
TEST_F(TypeTest, ForwardReferencedChild) {
TypeBuilder builder(3);
builder.createRecGroup(0, 2);