diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 24 | ||||
-rw-r--r-- | test/gtest/type-builder.cpp | 84 | ||||
-rw-r--r-- | test/lit/basic/typed_continuations.wast | 26 | ||||
-rw-r--r-- | test/spec/typed_continuations.wast | 8 |
4 files changed, 129 insertions, 13 deletions
diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 469267a4d..8bdf1ba52 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -25,18 +25,18 @@ BinaryenPackedTypeInt8: 1 BinaryenPackedTypeInt16: 2 BinaryenHeapTypeExt: 0 BinaryenHeapTypeFunc: 1 -BinaryenHeapTypeAny: 2 -BinaryenHeapTypeEq: 3 -BinaryenHeapTypeI31: 4 -BinaryenHeapTypeStruct: 5 -BinaryenHeapTypeArray: 6 -BinaryenHeapTypeString: 8 -BinaryenHeapTypeStringviewWTF8: 9 -BinaryenHeapTypeStringviewWTF16: 10 -BinaryenHeapTypeStringviewIter: 11 -BinaryenHeapTypeNone: 12 -BinaryenHeapTypeNoext: 13 -BinaryenHeapTypeNofunc: 14 +BinaryenHeapTypeAny: 3 +BinaryenHeapTypeEq: 4 +BinaryenHeapTypeI31: 5 +BinaryenHeapTypeStruct: 6 +BinaryenHeapTypeArray: 7 +BinaryenHeapTypeString: 9 +BinaryenHeapTypeStringviewWTF8: 10 +BinaryenHeapTypeStringviewWTF16: 11 +BinaryenHeapTypeStringviewIter: 12 +BinaryenHeapTypeNone: 13 +BinaryenHeapTypeNoext: 14 +BinaryenHeapTypeNofunc: 15 BinaryenFeatureMVP: 0 BinaryenFeatureAtomics: 1 BinaryenFeatureBulkMemory: 16 diff --git a/test/gtest/type-builder.cpp b/test/gtest/type-builder.cpp index e8c24b06c..3c97028a4 100644 --- a/test/gtest/type-builder.cpp +++ b/test/gtest/type-builder.cpp @@ -521,6 +521,7 @@ TEST_F(TypeTest, CanonicalizeTypesBeforeSubtyping) { TEST_F(TypeTest, TestHeapTypeRelations) { HeapType ext = HeapType::ext; HeapType func = HeapType::func; + HeapType cont = HeapType::cont; HeapType any = HeapType::any; HeapType eq = HeapType::eq; HeapType i31 = HeapType::i31; @@ -533,7 +534,9 @@ TEST_F(TypeTest, TestHeapTypeRelations) { HeapType none = HeapType::none; HeapType noext = HeapType::noext; HeapType nofunc = HeapType::nofunc; + HeapType nocont = HeapType::nocont; HeapType defFunc = Signature(); + HeapType defCont = Continuation(defFunc); HeapType defStruct = Struct(); HeapType defArray = Array(Field(Type::i32, Immutable)); @@ -578,6 +581,7 @@ TEST_F(TypeTest, TestHeapTypeRelations) { assertLUB(ext, ext, ext); assertLUB(ext, func, {}); + assertLUB(ext, cont, {}); assertLUB(ext, any, {}); assertLUB(ext, eq, {}); assertLUB(ext, i31, {}); @@ -590,11 +594,13 @@ TEST_F(TypeTest, TestHeapTypeRelations) { assertLUB(ext, none, {}); assertLUB(ext, noext, ext); assertLUB(ext, nofunc, {}); + assertLUB(ext, nocont, {}); assertLUB(ext, defFunc, {}); assertLUB(ext, defStruct, {}); assertLUB(ext, defArray, {}); assertLUB(func, func, func); + assertLUB(func, cont, {}); assertLUB(func, any, {}); assertLUB(func, eq, {}); assertLUB(func, i31, {}); @@ -607,11 +613,34 @@ TEST_F(TypeTest, TestHeapTypeRelations) { assertLUB(func, none, {}); assertLUB(func, noext, {}); assertLUB(func, nofunc, func); + assertLUB(func, nocont, {}); assertLUB(func, defFunc, func); + assertLUB(func, defCont, {}); assertLUB(func, defStruct, {}); assertLUB(func, defArray, {}); + assertLUB(cont, cont, cont); + assertLUB(cont, func, {}); + assertLUB(cont, any, {}); + assertLUB(cont, eq, {}); + assertLUB(cont, i31, {}); + assertLUB(cont, struct_, {}); + assertLUB(cont, array, {}); + assertLUB(cont, string, {}); + assertLUB(cont, stringview_wtf8, {}); + assertLUB(cont, stringview_wtf16, {}); + assertLUB(cont, stringview_iter, {}); + assertLUB(cont, none, {}); + assertLUB(cont, noext, {}); + assertLUB(cont, nofunc, {}); + assertLUB(cont, nocont, cont); + assertLUB(cont, defFunc, {}); + assertLUB(cont, defCont, cont); + assertLUB(cont, defStruct, {}); + assertLUB(cont, defArray, {}); + assertLUB(any, any, any); + assertLUB(any, cont, {}); assertLUB(any, eq, any); assertLUB(any, i31, any); assertLUB(any, struct_, any); @@ -623,11 +652,14 @@ TEST_F(TypeTest, TestHeapTypeRelations) { assertLUB(any, none, any); assertLUB(any, noext, {}); assertLUB(any, nofunc, {}); + assertLUB(any, nocont, {}); assertLUB(any, defFunc, {}); + assertLUB(any, defCont, {}); assertLUB(any, defStruct, any); assertLUB(any, defArray, any); assertLUB(eq, eq, eq); + assertLUB(eq, cont, {}); assertLUB(eq, i31, eq); assertLUB(eq, struct_, eq); assertLUB(eq, array, eq); @@ -638,11 +670,14 @@ TEST_F(TypeTest, TestHeapTypeRelations) { assertLUB(eq, none, eq); assertLUB(eq, noext, {}); assertLUB(eq, nofunc, {}); + assertLUB(eq, nocont, {}); assertLUB(eq, defFunc, {}); + assertLUB(eq, defCont, {}); assertLUB(eq, defStruct, eq); assertLUB(eq, defArray, eq); assertLUB(i31, i31, i31); + assertLUB(i31, cont, {}); assertLUB(i31, struct_, eq); assertLUB(i31, array, eq); assertLUB(i31, string, any); @@ -652,11 +687,14 @@ TEST_F(TypeTest, TestHeapTypeRelations) { assertLUB(i31, none, i31); assertLUB(i31, noext, {}); assertLUB(i31, nofunc, {}); + assertLUB(i31, nocont, {}); assertLUB(i31, defFunc, {}); + assertLUB(i31, defCont, {}); assertLUB(i31, defStruct, eq); assertLUB(i31, defArray, eq); assertLUB(struct_, struct_, struct_); + assertLUB(struct_, cont, {}); assertLUB(struct_, array, eq); assertLUB(struct_, string, any); assertLUB(struct_, stringview_wtf8, {}); @@ -665,11 +703,14 @@ TEST_F(TypeTest, TestHeapTypeRelations) { assertLUB(struct_, none, struct_); assertLUB(struct_, noext, {}); assertLUB(struct_, nofunc, {}); + assertLUB(struct_, nocont, {}); assertLUB(struct_, defFunc, {}); + assertLUB(struct_, defCont, {}); assertLUB(struct_, defStruct, struct_); assertLUB(struct_, defArray, eq); assertLUB(array, array, array); + assertLUB(array, cont, {}); assertLUB(array, string, any); assertLUB(array, stringview_wtf8, {}); assertLUB(array, stringview_wtf16, {}); @@ -677,18 +718,23 @@ TEST_F(TypeTest, TestHeapTypeRelations) { assertLUB(array, none, array); assertLUB(array, noext, {}); assertLUB(array, nofunc, {}); + assertLUB(array, nocont, {}); assertLUB(array, defFunc, {}); + assertLUB(array, defCont, {}); assertLUB(array, defStruct, eq); assertLUB(array, defArray, array); assertLUB(string, string, string); + assertLUB(string, cont, {}); assertLUB(string, stringview_wtf8, {}); assertLUB(string, stringview_wtf16, {}); assertLUB(string, stringview_iter, {}); assertLUB(string, none, string); assertLUB(string, noext, {}); assertLUB(string, nofunc, {}); + assertLUB(string, nocont, {}); assertLUB(string, defFunc, {}); + assertLUB(string, defCont, {}); assertLUB(string, defStruct, any); assertLUB(string, defArray, any); @@ -698,8 +744,10 @@ TEST_F(TypeTest, TestHeapTypeRelations) { assertLUB(stringview_wtf8, none, stringview_wtf8); assertLUB(stringview_wtf8, noext, {}); assertLUB(stringview_wtf8, nofunc, {}); + assertLUB(stringview_wtf8, nocont, {}); assertLUB(stringview_wtf8, defFunc, {}); assertLUB(stringview_wtf8, defStruct, {}); + assertLUB(stringview_wtf8, defCont, {}); assertLUB(stringview_wtf8, defArray, {}); assertLUB(stringview_wtf16, stringview_wtf16, stringview_wtf16); @@ -707,40 +755,65 @@ TEST_F(TypeTest, TestHeapTypeRelations) { assertLUB(stringview_wtf16, none, stringview_wtf16); assertLUB(stringview_wtf16, noext, {}); assertLUB(stringview_wtf16, nofunc, {}); + assertLUB(stringview_wtf16, nocont, {}); assertLUB(stringview_wtf16, defFunc, {}); assertLUB(stringview_wtf16, defStruct, {}); + assertLUB(stringview_wtf16, defCont, {}); assertLUB(stringview_wtf16, defArray, {}); assertLUB(stringview_iter, stringview_iter, stringview_iter); assertLUB(stringview_iter, none, stringview_iter); assertLUB(stringview_iter, noext, {}); assertLUB(stringview_iter, nofunc, {}); + assertLUB(stringview_iter, nocont, {}); assertLUB(stringview_iter, defFunc, {}); assertLUB(stringview_iter, defStruct, {}); + assertLUB(stringview_iter, defCont, {}); assertLUB(stringview_iter, defArray, {}); assertLUB(none, none, none); assertLUB(none, noext, {}); assertLUB(none, nofunc, {}); + assertLUB(none, nocont, {}); assertLUB(none, defFunc, {}); + assertLUB(none, defCont, {}); assertLUB(none, defStruct, defStruct); assertLUB(none, defArray, defArray); assertLUB(noext, noext, noext); assertLUB(noext, nofunc, {}); + assertLUB(noext, nocont, {}); assertLUB(noext, defFunc, {}); + assertLUB(noext, defCont, {}); assertLUB(noext, defStruct, {}); assertLUB(noext, defArray, {}); assertLUB(nofunc, nofunc, nofunc); + assertLUB(nofunc, nocont, {}); assertLUB(nofunc, defFunc, defFunc); + assertLUB(nofunc, defCont, {}); assertLUB(nofunc, defStruct, {}); assertLUB(nofunc, defArray, {}); + assertLUB(nocont, nocont, nocont); + assertLUB(nocont, func, {}); + assertLUB(nocont, cont, cont); + assertLUB(nocont, nofunc, {}); + assertLUB(nocont, defFunc, {}); + assertLUB(nocont, defCont, defCont); + assertLUB(nocont, defStruct, {}); + assertLUB(nocont, defArray, {}); + assertLUB(defFunc, defFunc, defFunc); + assertLUB(defFunc, defCont, {}); assertLUB(defFunc, defStruct, {}); assertLUB(defFunc, defArray, {}); + assertLUB(defCont, defCont, defCont); + assertLUB(defCont, defFunc, {}); + assertLUB(defCont, defStruct, {}); + assertLUB(defCont, defArray, {}); + assertLUB(defStruct, defStruct, defStruct); assertLUB(defStruct, defArray, eq); @@ -1005,6 +1078,7 @@ TEST_F(TypeTest, TestMaxArrayDepths) { // Test .depth() helper. TEST_F(TypeTest, TestDepth) { HeapType A, B, C; + HeapType sig = HeapType(Signature(Type::none, Type::none)); { TypeBuilder builder(3); builder[0].setOpen() = Struct(); @@ -1029,7 +1103,11 @@ TEST_F(TypeTest, TestDepth) { // Signature types are subtypes of func. EXPECT_EQ(HeapType(HeapType::func).getDepth(), 0U); - EXPECT_EQ(HeapType(Signature(Type::none, Type::none)).getDepth(), 1U); + EXPECT_EQ(sig.getDepth(), 1U); + + // Continuation types are subtypes of cont. + EXPECT_EQ(HeapType(HeapType::cont).getDepth(), 0U); + EXPECT_EQ(HeapType(Continuation(sig)).getDepth(), 1U); EXPECT_EQ(HeapType(HeapType::ext).getDepth(), 0U); @@ -1097,6 +1175,7 @@ TEST_F(TypeTest, TestSupertypes) { // Basic types: getDeclaredSuperType always returns nothing. ASSERT_FALSE(HeapType(HeapType::ext).getDeclaredSuperType()); ASSERT_FALSE(HeapType(HeapType::func).getDeclaredSuperType()); + ASSERT_FALSE(HeapType(HeapType::cont).getDeclaredSuperType()); ASSERT_FALSE(HeapType(HeapType::any).getDeclaredSuperType()); ASSERT_FALSE(HeapType(HeapType::eq).getDeclaredSuperType()); ASSERT_FALSE(HeapType(HeapType::i31).getDeclaredSuperType()); @@ -1109,10 +1188,12 @@ TEST_F(TypeTest, TestSupertypes) { ASSERT_FALSE(HeapType(HeapType::none).getDeclaredSuperType()); ASSERT_FALSE(HeapType(HeapType::noext).getDeclaredSuperType()); ASSERT_FALSE(HeapType(HeapType::nofunc).getDeclaredSuperType()); + ASSERT_FALSE(HeapType(HeapType::nocont).getDeclaredSuperType()); // Basic types: getSuperType does return a super, when there is one. ASSERT_FALSE(HeapType(HeapType::ext).getSuperType()); ASSERT_FALSE(HeapType(HeapType::func).getSuperType()); + ASSERT_FALSE(HeapType(HeapType::cont).getSuperType()); ASSERT_FALSE(HeapType(HeapType::any).getSuperType()); ASSERT_EQ(HeapType(HeapType::eq).getSuperType(), HeapType::any); ASSERT_EQ(HeapType(HeapType::i31).getSuperType(), HeapType::eq); @@ -1125,6 +1206,7 @@ TEST_F(TypeTest, TestSupertypes) { ASSERT_FALSE(HeapType(HeapType::none).getSuperType()); ASSERT_FALSE(HeapType(HeapType::noext).getSuperType()); ASSERT_FALSE(HeapType(HeapType::nofunc).getSuperType()); + ASSERT_FALSE(HeapType(HeapType::nocont).getSuperType()); // Non-basic types. HeapType struct1, struct2, array1, array2, sig1, sig2; diff --git a/test/lit/basic/typed_continuations.wast b/test/lit/basic/typed_continuations.wast index 998837817..52258403f 100644 --- a/test/lit/basic/typed_continuations.wast +++ b/test/lit/basic/typed_continuations.wast @@ -19,17 +19,37 @@ ;; CHECK-TEXT: (type $2 (func (param (ref $ct)) (result (ref $ct)))) + ;; CHECK-TEXT: (type $3 (func (param contref nullcontref (ref cont) (ref nocont)) (result contref))) + ;; CHECK-TEXT: (func $id (type $2) (param $x (ref $ct)) (result (ref $ct)) ;; CHECK-TEXT-NEXT: (local.get $x) ;; CHECK-TEXT-NEXT: ) ;; CHECK-BIN: (type $2 (func (param (ref $ct)) (result (ref $ct)))) + ;; CHECK-BIN: (type $3 (func (param contref nullcontref (ref func) (ref nocont)) (result contref))) + ;; CHECK-BIN: (func $id (type $2) (param $x (ref $ct)) (result (ref $ct)) ;; CHECK-BIN-NEXT: (local.get $x) ;; CHECK-BIN-NEXT: ) (func $id (param $x (ref $ct)) (result (ref $ct)) (local.get $x) ) + + ;; CHECK-TEXT: (func $id2 (type $3) (param $w contref) (param $x nullcontref) (param $y (ref cont)) (param $z (ref nocont)) (result contref) + ;; CHECK-TEXT-NEXT: (local.get $z) + ;; CHECK-TEXT-NEXT: ) + ;; CHECK-BIN: (func $id2 (type $3) (param $w contref) (param $x nullcontref) (param $y (ref func)) (param $z (ref nocont)) (result contref) + ;; CHECK-BIN-NEXT: (local.get $z) + ;; CHECK-BIN-NEXT: ) + (func $id2 + (param $w contref) + (param $x nullcontref) + (param $y (ref cont)) + (param $z (ref nocont)) + (result contref) + (local.get $z) + ) + ) ;; CHECK-BIN-NODEBUG: (type $0 (func (param i32) (result i32))) @@ -37,6 +57,12 @@ ;; CHECK-BIN-NODEBUG: (type $2 (func (param (ref $1)) (result (ref $1)))) +;; CHECK-BIN-NODEBUG: (type $3 (func (param contref nullcontref (ref func) (ref nocont)) (result contref))) + ;; CHECK-BIN-NODEBUG: (func $0 (type $2) (param $0 (ref $1)) (result (ref $1)) ;; CHECK-BIN-NODEBUG-NEXT: (local.get $0) ;; CHECK-BIN-NODEBUG-NEXT: ) + +;; CHECK-BIN-NODEBUG: (func $1 (type $3) (param $0 contref) (param $1 nullcontref) (param $2 (ref func)) (param $3 (ref nocont)) (result contref) +;; CHECK-BIN-NODEBUG-NEXT: (local.get $3) +;; CHECK-BIN-NODEBUG-NEXT: ) diff --git a/test/spec/typed_continuations.wast b/test/spec/typed_continuations.wast index 5f7b86f6c..e3bddbf77 100644 --- a/test/spec/typed_continuations.wast +++ b/test/spec/typed_continuations.wast @@ -5,6 +5,14 @@ (func $id (param $x (ref $ct)) (result (ref $ct)) (local.get $x) ) + + (func $cont-nocont (param $x (ref null $ct)) + (local $l1 (ref null cont)) + (local $l2 (ref null $ct)) + (local.set $l1 (local.get $x)) ;; $ct <: cont + (local.set $l2 (ref.null nocont)) ;; nocont <: $ct + (local.set $l1 (ref.null nocont)) ;; nocont <: cont + ) ) (assert_invalid |