diff options
author | Daniel Wirtz <dcode@dcode.io> | 2020-08-26 23:05:36 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-26 23:05:36 +0200 |
commit | a61b9dff9be3da4d4c56f92f494e5f2914f32e1e (patch) | |
tree | dd00fd7998998819ebb571f09bdc8954b6e08a0b /test/example | |
parent | 9371352930ccfc1947dadb8130530db65608732b (diff) | |
download | binaryen-a61b9dff9be3da4d4c56f92f494e5f2914f32e1e.tar.gz binaryen-a61b9dff9be3da4d4c56f92f494e5f2914f32e1e.tar.bz2 binaryen-a61b9dff9be3da4d4c56f92f494e5f2914f32e1e.zip |
Add new compound Rtt type (#3076)
Extends compound types introduced in #3012 with a representation of `Rtt`s as described in the GC proposal, by also introducing the concept of a `HeapType` shared between `TypeInfo` and `Rtt`. Again, this should be a non-functional change since `Rtt`s are not used anywhere yet. Subtyping rules and updating the `xref` aliases is left for future work.
Diffstat (limited to 'test/example')
-rw-r--r-- | test/example/typeinfo.cpp | 122 | ||||
-rw-r--r-- | test/example/typeinfo.txt | 45 |
2 files changed, 164 insertions, 3 deletions
diff --git a/test/example/typeinfo.cpp b/test/example/typeinfo.cpp index dc9866706..ac01c6a1b 100644 --- a/test/example/typeinfo.cpp +++ b/test/example/typeinfo.cpp @@ -7,6 +7,49 @@ using namespace wasm; void test_compound() { { + HeapType func(HeapType::FuncKind); + assert(Type(func, true).getID() == Type::funcref); + assert(Type(func, false).getID() == Type(func, false).getID()); + assert(Type(func, false).getID() != Type(func, true).getID()); + HeapType sameFunc(HeapType::FuncKind); + assert(Type(func, false).getID() == Type(sameFunc, false).getID()); + + HeapType extern_(HeapType::ExternKind); + assert(Type(extern_, true).getID() == Type::externref); + assert(Type(extern_, false).getID() == Type(extern_, false).getID()); + assert(Type(extern_, false).getID() != Type(extern_, true).getID()); + HeapType sameExtern(HeapType::ExternKind); + assert(Type(extern_, false).getID() == Type(sameExtern, false).getID()); + + HeapType any(HeapType::AnyKind); + // assert(Type(any, true).getID() == Type::anyref); + assert(Type(any, false).getID() == Type(any, false).getID()); + assert(Type(any, false).getID() != Type(any, true).getID()); + HeapType sameAny(HeapType::AnyKind); + assert(Type(any, false).getID() == Type(sameAny, false).getID()); + + HeapType eq(HeapType::EqKind); + // assert(Type(eq, true).getID() == Type::eqref); + assert(Type(eq, false).getID() == Type(eq, false).getID()); + assert(Type(eq, false).getID() != Type(eq, true).getID()); + HeapType sameEq(HeapType::EqKind); + assert(Type(eq, false).getID() == Type(sameEq, false).getID()); + + HeapType i31(HeapType::I31Kind); + // assert(Type(i31, false).getID() == Type::i31ref); + assert(Type(i31, false).getID() == Type(i31, false).getID()); + assert(Type(i31, false).getID() != Type(i31, true).getID()); + HeapType sameI31(HeapType::I31Kind); + assert(Type(i31, false).getID() == Type(sameI31, false).getID()); + + HeapType exn(HeapType::ExnKind); + assert(Type(exn, true).getID() == Type::exnref); + assert(Type(exn, false).getID() == Type(exn, false).getID()); + assert(Type(exn, false).getID() != Type(exn, true).getID()); + HeapType sameExn(HeapType::ExnKind); + assert(Type(exn, false).getID() == Type(sameExn, false).getID()); + } + { Signature signature(Type::i32, Type::none); assert(Type(signature, false).getID() == Type(signature, false).getID()); assert(Type(signature, false).getID() != Type(signature, true).getID()); @@ -54,11 +97,62 @@ void test_compound() { Tuple otherTuple({Type::f64, Type::externref}); assert(Type(tuple).getID() != Type(otherTuple).getID()); } + { + Rtt rtt(0, HeapType::FuncKind); + assert(Type(rtt).getID() == Type(rtt).getID()); + + Rtt sameRtt(0, HeapType::FuncKind); + assert(rtt == sameRtt); + assert(Type(rtt).getID() == Type(sameRtt).getID()); + + Rtt otherDepthRtt(1, HeapType::FuncKind); + assert(rtt != otherDepthRtt); + assert(Type(rtt).getID() != Type(otherDepthRtt).getID()); + + Rtt otherHeapTypeRtt(0, HeapType::AnyKind); + assert(rtt != otherHeapTypeRtt); + assert(Type(rtt).getID() != Type(otherHeapTypeRtt).getID()); + + Rtt structRtt(0, Struct({})); + assert(Type(structRtt).getID() == Type(structRtt).getID()); + + Rtt sameStructRtt(0, Struct({})); + assert(structRtt == sameStructRtt); + assert(Type(structRtt).getID() == Type(sameStructRtt).getID()); + + Rtt otherStructRtt(0, Struct({{Type::i32, false}})); + assert(structRtt != otherStructRtt); + assert(Type(structRtt).getID() != Type(otherStructRtt).getID()); + } } void test_printing() { { - std::cout << ";; Signature\n"; + std::cout << ";; Heap types\n"; + std::cout << HeapType(HeapType::FuncKind) << "\n"; + std::cout << Type(HeapType::FuncKind, true) << "\n"; + std::cout << Type(HeapType::FuncKind, false) << "\n"; + std::cout << HeapType(HeapType::ExternKind) << "\n"; + std::cout << Type(HeapType::ExternKind, true) << "\n"; + std::cout << Type(HeapType::ExternKind, false) << "\n"; + std::cout << HeapType(HeapType::AnyKind) << "\n"; + std::cout << Type(HeapType::AnyKind, true) << "\n"; + std::cout << Type(HeapType::AnyKind, false) << "\n"; + std::cout << HeapType(HeapType::EqKind) << "\n"; + std::cout << Type(HeapType::EqKind, true) << "\n"; + std::cout << Type(HeapType::EqKind, false) << "\n"; + std::cout << HeapType(HeapType::I31Kind) << "\n"; + std::cout << Type(HeapType::I31Kind, true) << "\n"; + std::cout << Type(HeapType::I31Kind, false) << "\n"; + std::cout << HeapType(HeapType::ExnKind) << "\n"; + std::cout << Type(HeapType::ExnKind, true) << "\n"; + std::cout << Type(HeapType::ExnKind, false) << "\n"; + std::cout << HeapType(Signature(Type::none, Type::none)) << "\n"; + std::cout << HeapType(Struct({})) << "\n"; + std::cout << HeapType(Array({Type::i32, false})) << "\n"; + } + { + std::cout << "\n;; Signature\n"; Signature emptySignature(Type::none, Type::none); std::cout << emptySignature << "\n"; std::cout << Type(emptySignature, false) << "\n"; @@ -110,6 +204,30 @@ void test_printing() { std::cout << Type(tuple) << "\n"; } { + std::cout << "\n;; Rtt\n"; + std::cout << Rtt(0, HeapType::FuncKind) << "\n"; + std::cout << Type(Rtt(0, HeapType::FuncKind)) << "\n"; + std::cout << Rtt(1, HeapType::ExternKind) << "\n"; + std::cout << Type(Rtt(1, HeapType::ExternKind)) << "\n"; + std::cout << Rtt(2, HeapType::AnyKind) << "\n"; + std::cout << Type(Rtt(2, HeapType::AnyKind)) << "\n"; + std::cout << Rtt(3, HeapType::EqKind) << "\n"; + std::cout << Type(Rtt(3, HeapType::EqKind)) << "\n"; + std::cout << Rtt(4, HeapType::I31Kind) << "\n"; + std::cout << Type(Rtt(4, HeapType::I31Kind)) << "\n"; + std::cout << Rtt(5, HeapType::ExnKind) << "\n"; + std::cout << Type(Rtt(5, HeapType::ExnKind)) << "\n"; + Rtt signatureRtt(6, Signature(Type::none, Type::none)); + std::cout << signatureRtt << "\n"; + std::cout << Type(signatureRtt) << "\n"; + Rtt structRtt(7, Struct({})); + std::cout << structRtt << "\n"; + std::cout << Type(structRtt) << "\n"; + Rtt arrayRtt(8, Array({Type::i32, false})); + std::cout << arrayRtt << "\n"; + std::cout << Type(arrayRtt) << "\n"; + } + { std::cout << "\n;; Signature of references (param/result)\n"; Signature signature(Type(Struct({}), true), Type(Array({Type::i32, true}), false)); @@ -197,7 +315,7 @@ void test_printing() { } // TODO: Think about recursive types. Currently impossible to construct. { - std::cout << "\n;; Recursive\n"; + std::cout << "\n;; Recursive (not really)\n"; Signature signatureSignature(Type::none, Type::none); signatureSignature.params = Type(signatureSignature, false); // ^ copies diff --git a/test/example/typeinfo.txt b/test/example/typeinfo.txt index 71e9a3e9c..95706d5e2 100644 --- a/test/example/typeinfo.txt +++ b/test/example/typeinfo.txt @@ -1,3 +1,26 @@ +;; Heap types +func +funcref +(ref func) +extern +externref +(ref extern) +any +(ref null any) +(ref any) +eq +(ref null eq) +(ref eq) +i31 +(ref null i31) +(ref i31) +exn +exnref +(ref exn) +(func) +(struct) +(array i32) + ;; Signature (func) (ref (func)) @@ -28,6 +51,26 @@ none (i32 f64 externref) (i32 f64 externref) +;; Rtt +(rtt 0 func) +(rtt 0 func) +(rtt 1 extern) +(rtt 1 extern) +(rtt 2 any) +(rtt 2 any) +(rtt 3 eq) +(rtt 3 eq) +(rtt 4 i31) +(rtt 4 i31) +(rtt 5 exn) +(rtt 5 exn) +(rtt 6 (func)) +(rtt 6 (func)) +(rtt 7 (struct)) +(rtt 7 (struct)) +(rtt 8 (array i32)) +(rtt 8 (array i32)) + ;; Signature of references (param/result) (func (param (ref null (struct))) (result (ref (array (mut i32))))) @@ -63,7 +106,7 @@ none ((ref (func)) (ref null (func)) (ref (struct)) (ref null (struct)) (ref (array i32)) (ref null (array i32))) ((ref (func)) (ref null (func)) (ref (struct)) (ref null (struct)) (ref (array i32)) (ref null (array i32))) -;; Recursive +;; Recursive (not really) (func (param (ref (func)))) (ref (func (param (ref (func))))) (func (param (ref (array (ref (func)))))) |