summaryrefslogtreecommitdiff
path: root/test/example
diff options
context:
space:
mode:
authorThomas Lively <tlively@google.com>2023-04-19 17:22:28 -0700
committerGitHub <noreply@github.com>2023-04-19 17:22:28 -0700
commit9e5961792a91774962815d58c5c73bfb5612e27c (patch)
tree5f076b905041cc31c0cb58b298f010cbe0a4e226 /test/example
parent7cd2396dacf276750a3e27320d6b9d2af6f939d9 (diff)
downloadbinaryen-9e5961792a91774962815d58c5c73bfb5612e27c.tar.gz
binaryen-9e5961792a91774962815d58c5c73bfb5612e27c.tar.bz2
binaryen-9e5961792a91774962815d58c5c73bfb5612e27c.zip
Remove the ability to construct basic types in a TypeBuilder (#5678)
This capability was originally introduced to support calculating LUBs in the equirecursive type system, but has not been needed for anything except tests since the equirecursive type system was removed. Since building basic heap types is no longer useful and was a source of significant complexity, remove the APIs that allowed it and the tests that used those APIs. Also remove test/example/type-builder.cpp, since a significant portion of it tested the removed APIs and the rest is already better tested in test/gtest/type-builder.cpp.
Diffstat (limited to 'test/example')
-rw-r--r--test/example/c-api-kitchen-sink.c37
-rw-r--r--test/example/c-api-kitchen-sink.txt3
-rw-r--r--test/example/type-builder.cpp233
-rw-r--r--test/example/type-builder.txt54
4 files changed, 7 insertions, 320 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c
index 760f4be1d..2c6ec2d6c 100644
--- a/test/example/c-api-kitchen-sink.c
+++ b/test/example/c-api-kitchen-sink.c
@@ -2134,8 +2134,8 @@ void test_typebuilder() {
TypeBuilderRef builder = TypeBuilderCreate(0);
assert(TypeBuilderGetSize(builder) == 0);
- TypeBuilderGrow(builder, 5);
- assert(TypeBuilderGetSize(builder) == 5);
+ TypeBuilderGrow(builder, 4);
+ assert(TypeBuilderGetSize(builder) == 4);
// Create a recursive array of its own type
const BinaryenIndex tempArrayIndex = 0;
@@ -2179,19 +2179,8 @@ void test_typebuilder() {
tempSignatureType);
}
- // Create a basic heap type
- const BinaryenIndex tempBasicIndex = 3;
- TypeBuilderSetBasicHeapType(
- builder, 3, BinaryenTypeGetHeapType(BinaryenTypeEqref()));
- assert(TypeBuilderIsBasic(builder, tempBasicIndex));
- assert(TypeBuilderGetBasic(builder, tempBasicIndex) ==
- BinaryenTypeGetHeapType(BinaryenTypeEqref()));
- assert(!TypeBuilderIsBasic(builder, tempArrayIndex));
- assert(!TypeBuilderIsBasic(builder, tempStructIndex));
- assert(!TypeBuilderIsBasic(builder, tempSignatureIndex));
-
// Create a subtype (with an additional immutable packed field)
- const BinaryenIndex tempSubStructIndex = 4;
+ const BinaryenIndex tempSubStructIndex = 3;
BinaryenHeapType tempSubStructHeapType =
TypeBuilderGetTempHeapType(builder, tempSubStructIndex);
BinaryenType tempSubStructType =
@@ -2214,7 +2203,7 @@ void test_typebuilder() {
// TODO: Rtts (post-MVP?)
// Build the type hierarchy and dispose the builder
- BinaryenHeapType heapTypes[5];
+ BinaryenHeapType heapTypes[4];
BinaryenIndex errorIndex;
TypeBuilderErrorReason errorReason;
bool didBuildAndDispose = TypeBuilderBuildAndDispose(
@@ -2222,7 +2211,6 @@ void test_typebuilder() {
assert(didBuildAndDispose);
BinaryenHeapType arrayHeapType = heapTypes[tempArrayIndex];
- assert(!BinaryenHeapTypeIsBasic(arrayHeapType));
assert(!BinaryenHeapTypeIsSignature(arrayHeapType));
assert(!BinaryenHeapTypeIsStruct(arrayHeapType));
assert(BinaryenHeapTypeIsArray(arrayHeapType));
@@ -2235,7 +2223,6 @@ void test_typebuilder() {
assert(BinaryenArrayTypeIsElementMutable(arrayHeapType));
BinaryenHeapType structHeapType = heapTypes[tempStructIndex];
- assert(!BinaryenHeapTypeIsBasic(structHeapType));
assert(!BinaryenHeapTypeIsSignature(structHeapType));
assert(BinaryenHeapTypeIsStruct(structHeapType));
assert(!BinaryenHeapTypeIsArray(structHeapType));
@@ -2249,7 +2236,6 @@ void test_typebuilder() {
assert(BinaryenStructTypeIsFieldMutable(structHeapType, 0));
BinaryenHeapType signatureHeapType = heapTypes[tempSignatureIndex];
- assert(!BinaryenHeapTypeIsBasic(signatureHeapType));
assert(BinaryenHeapTypeIsSignature(signatureHeapType));
assert(!BinaryenHeapTypeIsStruct(signatureHeapType));
assert(!BinaryenHeapTypeIsArray(signatureHeapType));
@@ -2269,17 +2255,7 @@ void test_typebuilder() {
assert(BinaryenTypeArity(signatureResults) == 1);
assert(signatureResults == signatureType);
- BinaryenHeapType basicHeapType = heapTypes[tempBasicIndex]; // = eq
- assert(BinaryenHeapTypeIsBasic(basicHeapType));
- assert(!BinaryenHeapTypeIsSignature(basicHeapType));
- assert(!BinaryenHeapTypeIsStruct(basicHeapType));
- assert(!BinaryenHeapTypeIsArray(basicHeapType));
- assert(!BinaryenHeapTypeIsBottom(basicHeapType));
- assert(BinaryenHeapTypeIsSubType(basicHeapType, BinaryenHeapTypeAny()));
- BinaryenType basicType = BinaryenTypeFromHeapType(basicHeapType, true);
-
BinaryenHeapType subStructHeapType = heapTypes[tempSubStructIndex];
- assert(!BinaryenHeapTypeIsBasic(subStructHeapType));
assert(!BinaryenHeapTypeIsSignature(subStructHeapType));
assert(BinaryenHeapTypeIsStruct(subStructHeapType));
assert(!BinaryenHeapTypeIsArray(subStructHeapType));
@@ -2306,7 +2282,6 @@ void test_typebuilder() {
BinaryenModuleSetTypeName(module, structHeapType, "SomeStruct");
BinaryenModuleSetFieldName(module, structHeapType, 0, "SomeField");
BinaryenModuleSetTypeName(module, signatureHeapType, "SomeSignature");
- BinaryenModuleSetTypeName(module, basicHeapType, "does-nothing");
BinaryenModuleSetTypeName(module, subStructHeapType, "SomeSubStruct");
BinaryenModuleSetFieldName(module, subStructHeapType, 0, "SomeField");
BinaryenModuleSetFieldName(module, subStructHeapType, 1, "SomePackedField");
@@ -2314,13 +2289,13 @@ void test_typebuilder() {
module, BinaryenFeatureReferenceTypes() | BinaryenFeatureGC());
{
BinaryenType varTypes[] = {
- arrayType, structType, signatureType, basicType, subStructType};
+ arrayType, structType, signatureType, subStructType};
BinaryenAddFunction(module,
"test",
BinaryenTypeNone(),
BinaryenTypeNone(),
varTypes,
- 5,
+ 4,
BinaryenNop(module));
}
bool didValidate = BinaryenModuleValidate(module);
diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt
index 1c1a3b956..f9b688eaf 100644
--- a/test/example/c-api-kitchen-sink.txt
+++ b/test/example/c-api-kitchen-sink.txt
@@ -3162,8 +3162,7 @@ module with recursive GC types:
(local $0 (ref null $SomeArray))
(local $1 (ref null $SomeStruct))
(local $2 (ref null $SomeSignature))
- (local $3 eqref)
- (local $4 (ref null $SomeSubStruct))
+ (local $3 (ref null $SomeSubStruct))
(nop)
)
)
diff --git a/test/example/type-builder.cpp b/test/example/type-builder.cpp
deleted file mode 100644
index 2ce064b5f..000000000
--- a/test/example/type-builder.cpp
+++ /dev/null
@@ -1,233 +0,0 @@
-#include <cassert>
-#include <iostream>
-
-#include "wasm-type-printing.h"
-#include "wasm-type.h"
-
-using namespace wasm;
-
-// Check that the builder works when there are duplicate definitions
-void test_canonicalization() {
- std::cout << ";; Test canonicalization\n";
-
- // (type $struct (struct (field (ref null $sig) (ref null $sig))))
- // (type $sig (func))
- HeapType sig = Signature(Type::none, Type::none);
- HeapType struct_ = Struct({Field(Type(sig, Nullable), Immutable),
- Field(Type(sig, Nullable), Immutable)});
-
- TypeBuilder builder(4);
-
- Type tempSigRef1 = builder.getTempRefType(builder[0], Nullable);
- Type tempSigRef2 = builder.getTempRefType(builder[1], Nullable);
-
- assert(tempSigRef1 != tempSigRef2);
- assert(tempSigRef1 != Type(sig, Nullable));
- assert(tempSigRef2 != Type(sig, Nullable));
-
- builder[0] = Signature(Type::none, Type::none);
- builder[1] = Signature(Type::none, Type::none);
- builder[2] =
- Struct({Field(tempSigRef1, Immutable), Field(tempSigRef1, Immutable)});
- builder[3] =
- Struct({Field(tempSigRef2, Immutable), Field(tempSigRef2, Immutable)});
-
- std::vector<HeapType> built = *builder.build();
-
- assert(built[0] == sig);
- assert(built[1] == sig);
- assert(built[2] == struct_);
- assert(built[3] == struct_);
-}
-
-// Check that defined basic HeapTypes are handled correctly.
-void test_basic() {
- std::cout << ";; Test basic\n";
-
- Type canonAnyref = Type(HeapType::any, Nullable);
- Type canonI31ref = Type(HeapType::i31, NonNullable);
-
- TypeBuilder builder(6);
-
- Type anyref = builder.getTempRefType(builder[4], Nullable);
- Type i31ref = builder.getTempRefType(builder[5], NonNullable);
-
- builder[0] = Signature(canonAnyref, canonI31ref);
- builder[1] = Signature(anyref, canonI31ref);
- builder[2] = Signature(canonAnyref, i31ref);
- builder[3] = Signature(anyref, i31ref);
- builder[4] = HeapType::any;
- builder[5] = HeapType::i31;
-
- std::vector<HeapType> built = *builder.build();
-
- assert(built[0] == Signature(canonAnyref, canonI31ref));
- assert(built[1] == built[0]);
- assert(built[2] == built[1]);
- assert(built[3] == built[2]);
- assert(built[4] == HeapType::any);
- assert(built[5] == HeapType::i31);
-}
-
-void test_recursive() {
- std::cout << ";; Test recursive types\n";
-
- {
- // Trivial recursion
- std::vector<HeapType> built;
- {
- TypeBuilder builder(1);
- Type temp = builder.getTempRefType(builder[0], Nullable);
- builder[0] = Signature(Type::none, temp);
- built = *builder.build();
- }
- IndexedTypeNameGenerator print(built);
- std::cout << print(built[0]) << "\n\n";
- assert(built[0] == built[0].getSignature().results.getHeapType());
- assert(Type(built[0], Nullable) == built[0].getSignature().results);
- }
-
- {
- // Mutual recursion
- std::vector<HeapType> built;
- {
- TypeBuilder builder(2);
- builder.createRecGroup(0, 2);
- Type temp0 = builder.getTempRefType(builder[0], Nullable);
- Type temp1 = builder.getTempRefType(builder[1], Nullable);
- builder[0] = Signature(Type::none, temp1);
- builder[1] = Signature(Type::none, temp0);
- built = *builder.build();
- }
- IndexedTypeNameGenerator print(built);
- std::cout << print(built[0]) << "\n";
- std::cout << print(built[1]) << "\n\n";
- assert(built[0].getSignature().results.getHeapType() == built[1]);
- assert(built[1].getSignature().results.getHeapType() == built[0]);
- }
-
- {
- // A longer chain of recursion
- std::vector<HeapType> built;
- {
- TypeBuilder builder(5);
- builder.createRecGroup(0, 5);
- Type temp0 = builder.getTempRefType(builder[0], Nullable);
- Type temp1 = builder.getTempRefType(builder[1], Nullable);
- Type temp2 = builder.getTempRefType(builder[2], Nullable);
- Type temp3 = builder.getTempRefType(builder[3], Nullable);
- Type temp4 = builder.getTempRefType(builder[4], Nullable);
- builder[0] = Signature(Type::none, temp1);
- builder[1] = Signature(Type::none, temp2);
- builder[2] = Signature(Type::none, temp3);
- builder[3] = Signature(Type::none, temp4);
- builder[4] = Signature(Type::none, temp0);
- built = *builder.build();
- }
- IndexedTypeNameGenerator print(built);
- std::cout << print(built[0]) << "\n";
- std::cout << print(built[1]) << "\n";
- std::cout << print(built[2]) << "\n";
- std::cout << print(built[3]) << "\n";
- std::cout << print(built[4]) << "\n\n";
- assert(built[0].getSignature().results.getHeapType() == built[1]);
- assert(built[1].getSignature().results.getHeapType() == built[2]);
- assert(built[2].getSignature().results.getHeapType() == built[3]);
- assert(built[3].getSignature().results.getHeapType() == built[4]);
- assert(built[4].getSignature().results.getHeapType() == built[0]);
- assert(built[0] != built[1]);
- assert(built[1] != built[2]);
- assert(built[2] != built[3]);
- assert(built[3] != built[4]);
- }
-
- {
- // Check canonicalization for non-recursive parents and children of
- // recursive HeapTypes.
- std::vector<HeapType> built;
- {
- TypeBuilder builder(6);
- Type temp0 = builder.getTempRefType(builder[0], Nullable);
- Type temp1 = builder.getTempRefType(builder[1], Nullable);
- Type temp2 = builder.getTempRefType(builder[2], Nullable);
- Type temp3 = builder.getTempRefType(builder[3], Nullable);
- Type tuple0_2 = builder.getTempTupleType({temp0, temp2});
- Type tuple1_3 = builder.getTempTupleType({temp1, temp3});
- builder[0] = Signature();
- builder[1] = Signature();
- builder.createRecGroup(2, 2);
- builder[2] = Signature(Type::none, tuple0_2);
- builder[3] = Signature(Type::none, tuple1_3);
- builder[4] = Signature(Type::none, temp2);
- builder[5] = Signature(Type::none, temp3);
- built = *builder.build();
- }
- IndexedTypeNameGenerator print(built);
- std::cout << print(built[0]) << "\n";
- std::cout << print(built[1]) << "\n";
- std::cout << print(built[2]) << "\n";
- std::cout << print(built[3]) << "\n";
- std::cout << print(built[4]) << "\n";
- std::cout << print(built[5]) << "\n\n";
- assert(built[0] == built[1]);
- assert(built[2] != built[3]);
- assert(built[4] != built[5]);
- assert(built[4].getSignature().results.getHeapType() == built[2]);
- assert(built[5].getSignature().results.getHeapType() == built[3]);
- assert(built[2].getSignature().results ==
- Type({Type(built[0], Nullable), Type(built[2], Nullable)}));
- assert(built[3].getSignature().results ==
- Type({Type(built[1], Nullable), Type(built[3], Nullable)}));
- }
-
- {
- // Folded and unfolded
- std::vector<HeapType> built;
- {
- TypeBuilder builder(2);
- Type temp0 = builder.getTempRefType(builder[0], Nullable);
- builder[0] = Signature(Type::none, temp0);
- builder[1] = Signature(Type::none, temp0);
- built = *builder.build();
- }
- IndexedTypeNameGenerator print(built);
- std::cout << print(built[0]) << "\n";
- std::cout << print(built[1]) << "\n\n";
- assert(built[0].getSignature().results.getHeapType() == built[0]);
- assert(built[1].getSignature().results.getHeapType() == built[0]);
- assert(built[0] != built[1]);
- }
-
- {
- // Including a basic heap type
- std::vector<HeapType> built;
- {
- TypeBuilder builder(3);
- Type anyref = builder.getTempRefType(builder[0], Nullable);
- Type temp1 = builder.getTempRefType(builder[1], Nullable);
- builder[0] = HeapType::any;
- builder[1] = Signature(anyref, temp1);
- builder[2] = Signature(anyref, temp1);
- built = *builder.build();
- }
- IndexedTypeNameGenerator print(built);
- std::cout << print(built[0]) << "\n";
- std::cout << print(built[1]) << "\n\n";
- assert(built[0] == HeapType::any);
- assert(built[1].getSignature().results.getHeapType() == built[1]);
- assert(built[2].getSignature().results.getHeapType() == built[1]);
- assert(built[1].getSignature().params == Type(HeapType::any, Nullable));
- assert(built[2].getSignature().params == Type(HeapType::any, Nullable));
- assert(built[1] != built[2]);
- }
-}
-
-int main() {
- // Run the tests twice to ensure things still work when the global stores are
- // already populated.
- for (size_t i = 0; i < 2; ++i) {
- test_canonicalization();
- test_basic();
- test_recursive();
- }
-}
diff --git a/test/example/type-builder.txt b/test/example/type-builder.txt
deleted file mode 100644
index b0cff3cc0..000000000
--- a/test/example/type-builder.txt
+++ /dev/null
@@ -1,54 +0,0 @@
-;; Test canonicalization
-;; Test basic
-;; Test recursive types
-(type $0 (func (result (ref null $0))))
-
-(type $0 (func (result (ref null $1))))
-(type $1 (func (result (ref null $0))))
-
-(type $0 (func (result (ref null $1))))
-(type $1 (func (result (ref null $2))))
-(type $2 (func (result (ref null $3))))
-(type $3 (func (result (ref null $4))))
-(type $4 (func (result (ref null $0))))
-
-(type $0 (func))
-(type $0 (func))
-(type $2 (func (result (ref null $0) (ref null $2))))
-(type $3 (func (result (ref null $0) (ref null $3))))
-(type $4 (func (result (ref null $2))))
-(type $5 (func (result (ref null $3))))
-
-(type $0 (func (result (ref null $0))))
-(type $1 (func (result (ref null $0))))
-
-any
-(type $1 (func (param anyref) (result (ref null $1))))
-
-;; Test canonicalization
-;; Test basic
-;; Test recursive types
-(type $0 (func (result (ref null $0))))
-
-(type $0 (func (result (ref null $1))))
-(type $1 (func (result (ref null $0))))
-
-(type $0 (func (result (ref null $1))))
-(type $1 (func (result (ref null $2))))
-(type $2 (func (result (ref null $3))))
-(type $3 (func (result (ref null $4))))
-(type $4 (func (result (ref null $0))))
-
-(type $0 (func))
-(type $0 (func))
-(type $2 (func (result (ref null $0) (ref null $2))))
-(type $3 (func (result (ref null $0) (ref null $3))))
-(type $4 (func (result (ref null $2))))
-(type $5 (func (result (ref null $3))))
-
-(type $0 (func (result (ref null $0))))
-(type $1 (func (result (ref null $0))))
-
-any
-(type $1 (func (param anyref) (result (ref null $1))))
-