diff options
Diffstat (limited to 'test/example')
-rw-r--r-- | test/example/c-api-kitchen-sink.c | 2 | ||||
-rw-r--r-- | test/example/c-api-kitchen-sink.txt | 12 | ||||
-rw-r--r-- | test/example/module-splitting.txt | 220 | ||||
-rw-r--r-- | test/example/type-builder.cpp | 259 | ||||
-rw-r--r-- | test/example/type-builder.txt | 74 | ||||
-rw-r--r-- | test/example/typeinfo.txt | 40 |
6 files changed, 213 insertions, 394 deletions
diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index d59c9e0c7..8dd9260d5 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -2089,7 +2089,7 @@ void test_func_opt() { void test_typesystem() { BinaryenTypeSystem defaultTypeSystem = BinaryenGetTypeSystem(); - assert(defaultTypeSystem == BinaryenTypeSystemEquirecursive()); + assert(defaultTypeSystem == BinaryenTypeSystemIsorecursive()); printf("BinaryenTypeSystemEquirecursive: %d\n", BinaryenTypeSystemEquirecursive()); BinaryenSetTypeSystem(BinaryenTypeSystemNominal()); diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 408c06444..857988419 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -99,7 +99,7 @@ BinaryenFeatureAll: 126975 (export "mem" (memory $0)) (export "kitchen_sinker" (func "$kitchen()sinker")) (start $starter) - (func "$kitchen()sinker" (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) + (func "$kitchen()sinker" (type $i32_i64_f32_f64_=>_i32) (param $0 i32) (param $1 i64) (param $2 f32) (param $3 f64) (result i32) (local $4 i32) (local $5 externref) (block $the-body (result i32) @@ -2454,7 +2454,7 @@ BinaryenFeatureAll: 126975 (i32.const 42) ) ) - (func $starter + (func $starter (type $none_=>_none) (nop) ) ) @@ -3037,10 +3037,10 @@ TypeBuilderErrorReasonForwardSupertypeReference: 2 TypeBuilderErrorReasonForwardChildReference: 3 module with recursive GC types: (module - (type $SomeArray (array_subtype (mut (ref null $SomeArray)) data)) - (type $SomeStruct (struct_subtype (field $SomeField (mut (ref null $SomeStruct))) data)) - (type $SomeSignature (func_subtype (param (ref null $SomeSignature) (ref null $SomeArray)) (result (ref null $SomeSignature)) func)) - (type $none_=>_none (func_subtype func)) + (type $SomeArray (array (mut (ref null $SomeArray)))) + (type $SomeStruct (struct (field $SomeField (mut (ref null $SomeStruct))))) + (type $SomeSignature (func (param (ref null $SomeSignature) (ref null $SomeArray)) (result (ref null $SomeSignature)))) + (type $none_=>_none (func)) (type $SomeSubStruct (struct_subtype (field $SomeField (mut (ref null $SomeStruct))) (field $SomePackedField i8) $SomeStruct)) (func $test (type $none_=>_none) (local $0 (ref null $SomeArray)) diff --git a/test/example/module-splitting.txt b/test/example/module-splitting.txt index 6ebcb96c7..79221d664 100644 --- a/test/example/module-splitting.txt +++ b/test/example/module-splitting.txt @@ -110,7 +110,7 @@ Secondary: Before: (module (type $i32_=>_i32 (func (param i32) (result i32))) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -118,7 +118,7 @@ Keeping: foo After: (module (type $i32_=>_i32 (func (param i32) (result i32))) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -131,7 +131,7 @@ Before: (module (type $i32_=>_i32 (func (param i32) (result i32))) (export "foo" (func $foo)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -140,7 +140,7 @@ After: (module (type $i32_=>_i32 (func (param i32) (result i32))) (export "foo" (func $foo)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -154,7 +154,7 @@ Before: (type $i32_=>_i32 (func (param i32) (result i32))) (table $table 1 funcref) (elem (i32.const 0) $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -165,7 +165,7 @@ After: (table $table 1 funcref) (elem (i32.const 0) $foo) (export "%table" (table $table)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -180,7 +180,7 @@ Before: (type $i32_=>_i32 (func (param i32) (result i32))) (table $table 2 funcref) (elem (i32.const 0) $foo $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -191,7 +191,7 @@ After: (table $table 2 funcref) (elem (i32.const 0) $foo $foo) (export "%table" (table $table)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -207,7 +207,7 @@ Before: (import "env" "base" (global $base i32)) (table $table 1 funcref) (elem (global.get $base) $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -220,7 +220,7 @@ After: (elem (global.get $base) $foo) (export "%table" (table $table)) (export "%global" (global $base)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -237,7 +237,7 @@ Before: (import "env" "base" (global $base i32)) (table $table 2 funcref) (elem (global.get $base) $foo $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -250,7 +250,7 @@ After: (elem (global.get $base) $foo $foo) (export "%table" (table $table)) (export "%global" (global $base)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -332,7 +332,7 @@ Secondary: Before: (module (type $i32_=>_i32 (func (param i32) (result i32))) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -343,7 +343,7 @@ After: Secondary: (module (type $i32_=>_i32 (func (param i32) (result i32))) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -353,7 +353,7 @@ Before: (module (type $i32_=>_i32 (func (param i32) (result i32))) (export "foo" (func $foo)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -366,7 +366,7 @@ After: (elem (i32.const 0) $placeholder_0) (export "foo" (func $foo)) (export "%table" (table $0)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (call_indirect $0 (type $i32_=>_i32) (local.get $0) (i32.const 0) @@ -378,7 +378,7 @@ Secondary: (type $i32_=>_i32 (func (param i32) (result i32))) (import "primary" "%table" (table $0 1 funcref)) (elem (i32.const 0) $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -389,7 +389,7 @@ Before: (type $i32_=>_i32 (func (param i32) (result i32))) (table $table 1 funcref) (elem (i32.const 0) $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -407,7 +407,7 @@ Secondary: (type $i32_=>_i32 (func (param i32) (result i32))) (import "primary" "%table" (table $table 1 funcref)) (elem (i32.const 0) $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -418,7 +418,7 @@ Before: (type $i32_=>_i32 (func (param i32) (result i32))) (table $table 2 funcref) (elem (i32.const 0) $foo $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -437,7 +437,7 @@ Secondary: (type $i32_=>_i32 (func (param i32) (result i32))) (import "primary" "%table" (table $table 2 funcref)) (elem (i32.const 0) $foo $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -449,7 +449,7 @@ Before: (table $table 1000 funcref) (elem (i32.const 42) $foo) (export "foo" (func $foo)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -462,7 +462,7 @@ After: (elem (i32.const 42) $placeholder_42) (export "foo" (func $foo)) (export "%table" (table $table)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (call_indirect $table (type $i32_=>_i32) (local.get $0) (i32.const 42) @@ -474,7 +474,7 @@ Secondary: (type $i32_=>_i32 (func (param i32) (result i32))) (import "primary" "%table" (table $table 1000 funcref)) (elem (i32.const 42) $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -487,7 +487,7 @@ Before: (table $table 1000 funcref) (elem (global.get $base) $foo) (export "foo" (func $foo)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -502,7 +502,7 @@ After: (export "foo" (func $foo)) (export "%table" (table $table)) (export "%global" (global $base)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (call_indirect $table (type $i32_=>_i32) (local.get $0) (global.get $base) @@ -515,7 +515,7 @@ Secondary: (import "primary" "%table" (table $table 1000 funcref)) (import "primary" "%global" (global $base i32)) (elem (global.get $base) $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -528,7 +528,7 @@ Before: (table $table 1000 funcref) (elem (global.get $base) $foo $foo) (export "foo" (func $foo)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -544,7 +544,7 @@ After: (export "foo" (func $foo)) (export "%table" (table $table)) (export "%global" (global $base)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (call_indirect $table (type $i32_=>_i32) (local.get $0) (global.get $base) @@ -557,7 +557,7 @@ Secondary: (import "primary" "%table" (table $table 1000 funcref)) (import "primary" "%global" (global $base i32)) (elem (global.get $base) $foo $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -571,10 +571,10 @@ Before: (table $table 1000 funcref) (elem (global.get $base) $null $foo) (export "foo" (func $foo)) - (func $null + (func $null (type $none_=>_none) (nop) ) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -591,10 +591,10 @@ After: (export "%null" (func $null)) (export "%table" (table $table)) (export "%global" (global $base)) - (func $null + (func $null (type $none_=>_none) (nop) ) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (call_indirect $table (type $i32_=>_i32) (local.get $0) (i32.add @@ -612,7 +612,7 @@ Secondary: (import "primary" "%global" (global $base i32)) (import "primary" "%null" (func $null)) (elem (global.get $base) $null $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (local.get $0) ) ) @@ -621,10 +621,10 @@ Secondary: Before: (module (type $none_=>_none (func)) - (func $foo + (func $foo (type $none_=>_none) (call $bar) ) - (func $bar + (func $bar (type $none_=>_none) (nop) ) ) @@ -632,10 +632,10 @@ Keeping: bar, foo After: (module (type $none_=>_none (func)) - (func $foo + (func $foo (type $none_=>_none) (call $bar) ) - (func $bar + (func $bar (type $none_=>_none) (nop) ) ) @@ -647,10 +647,10 @@ Secondary: Before: (module (type $none_=>_none (func)) - (func $foo + (func $foo (type $none_=>_none) (call $bar) ) - (func $bar + (func $bar (type $none_=>_none) (nop) ) ) @@ -659,7 +659,7 @@ After: (module (type $none_=>_none (func)) (export "%bar" (func $bar)) - (func $bar + (func $bar (type $none_=>_none) (nop) ) ) @@ -667,7 +667,7 @@ Secondary: (module (type $none_=>_none (func)) (import "primary" "%bar" (func $bar)) - (func $foo + (func $foo (type $none_=>_none) (call $bar) ) ) @@ -676,10 +676,10 @@ Secondary: Before: (module (type $none_=>_none (func)) - (func $foo + (func $foo (type $none_=>_none) (call $bar) ) - (func $bar + (func $bar (type $none_=>_none) (nop) ) ) @@ -691,7 +691,7 @@ After: (table $0 1 funcref) (elem (i32.const 0) $placeholder_0) (export "%table" (table $0)) - (func $foo + (func $foo (type $none_=>_none) (call_indirect $0 (type $none_=>_none) (i32.const 0) ) @@ -702,7 +702,7 @@ Secondary: (type $none_=>_none (func)) (import "primary" "%table" (table $0 1 funcref)) (elem (i32.const 0) $bar) - (func $bar + (func $bar (type $none_=>_none) (nop) ) ) @@ -711,10 +711,10 @@ Secondary: Before: (module (type $none_=>_none (func)) - (func $foo + (func $foo (type $none_=>_none) (call $bar) ) - (func $bar + (func $bar (type $none_=>_none) (nop) ) ) @@ -725,10 +725,10 @@ After: Secondary: (module (type $none_=>_none (func)) - (func $bar + (func $bar (type $none_=>_none) (nop) ) - (func $foo + (func $foo (type $none_=>_none) (call $bar) ) ) @@ -738,10 +738,10 @@ Before: (module (type $none_=>_none (func)) (export "%foo" (func $bar)) - (func $foo + (func $foo (type $none_=>_none) (nop) ) - (func $bar + (func $bar (type $none_=>_none) (call $foo) ) ) @@ -755,10 +755,10 @@ After: (export "%foo" (func $bar)) (export "%foo_0" (func $foo)) (export "%table" (table $0)) - (func $foo + (func $foo (type $none_=>_none) (nop) ) - (func $bar + (func $bar (type $none_=>_none) (call_indirect $0 (type $none_=>_none) (i32.const 0) ) @@ -770,7 +770,7 @@ Secondary: (import "primary" "%table" (table $0 1 funcref)) (import "primary" "%foo_0" (func $foo)) (elem (i32.const 0) $bar) - (func $bar + (func $bar (type $none_=>_none) (call $foo) ) ) @@ -781,16 +781,16 @@ Before: (type $none_=>_none (func)) (table $table 4 funcref) (elem (i32.const 0) $foo $bar $baz $quux) - (func $foo + (func $foo (type $none_=>_none) (nop) ) - (func $bar + (func $bar (type $none_=>_none) (nop) ) - (func $baz + (func $baz (type $none_=>_none) (nop) ) - (func $quux + (func $quux (type $none_=>_none) (nop) ) ) @@ -803,10 +803,10 @@ After: (table $table 4 funcref) (elem (i32.const 0) $placeholder_0 $bar $placeholder_2 $quux) (export "%table" (table $table)) - (func $bar + (func $bar (type $none_=>_none) (nop) ) - (func $quux + (func $quux (type $none_=>_none) (nop) ) ) @@ -816,10 +816,10 @@ Secondary: (import "primary" "%table" (table $table 4 funcref)) (elem $0 (i32.const 0) $foo) (elem $1 (i32.const 2) $baz) - (func $baz + (func $baz (type $none_=>_none) (nop) ) - (func $foo + (func $foo (type $none_=>_none) (nop) ) ) @@ -831,16 +831,16 @@ Before: (import "env" "base" (global $base i32)) (table $table 4 funcref) (elem (global.get $base) $foo $bar $baz $quux) - (func $foo + (func $foo (type $none_=>_none) (nop) ) - (func $bar + (func $bar (type $none_=>_none) (nop) ) - (func $baz + (func $baz (type $none_=>_none) (nop) ) - (func $quux + (func $quux (type $none_=>_none) (nop) ) ) @@ -856,10 +856,10 @@ After: (export "%bar" (func $bar)) (export "%table" (table $table)) (export "%global" (global $base)) - (func $bar + (func $bar (type $none_=>_none) (nop) ) - (func $quux + (func $quux (type $none_=>_none) (nop) ) ) @@ -870,10 +870,10 @@ Secondary: (import "primary" "%global" (global $base i32)) (import "primary" "%bar" (func $bar)) (elem (global.get $base) $foo $bar $baz) - (func $baz + (func $baz (type $none_=>_none) (nop) ) - (func $foo + (func $foo (type $none_=>_none) (nop) ) ) @@ -884,16 +884,16 @@ Before: (type $none_=>_none (func)) (table $table 4 funcref) (elem (i32.const 0) $foo $bar $baz $quux) - (func $foo + (func $foo (type $none_=>_none) (nop) ) - (func $bar + (func $bar (type $none_=>_none) (nop) ) - (func $baz + (func $baz (type $none_=>_none) (nop) ) - (func $quux + (func $quux (type $none_=>_none) (nop) ) ) @@ -907,7 +907,7 @@ After: (table $table 4 funcref) (elem (i32.const 0) $placeholder_0 $placeholder_1 $baz $placeholder_3) (export "%table" (table $table)) - (func $baz + (func $baz (type $none_=>_none) (nop) ) ) @@ -917,13 +917,13 @@ Secondary: (import "primary" "%table" (table $table 4 funcref)) (elem $0 (i32.const 0) $foo $bar) (elem $1 (i32.const 3) $quux) - (func $bar + (func $bar (type $none_=>_none) (nop) ) - (func $foo + (func $foo (type $none_=>_none) (nop) ) - (func $quux + (func $quux (type $none_=>_none) (nop) ) ) @@ -935,16 +935,16 @@ Before: (import "env" "base" (global $base i32)) (table $table 4 funcref) (elem (global.get $base) $foo $bar $baz $quux) - (func $foo + (func $foo (type $none_=>_none) (nop) ) - (func $bar + (func $bar (type $none_=>_none) (nop) ) - (func $baz + (func $baz (type $none_=>_none) (nop) ) - (func $quux + (func $quux (type $none_=>_none) (nop) ) ) @@ -961,7 +961,7 @@ After: (export "%baz" (func $baz)) (export "%table" (table $table)) (export "%global" (global $base)) - (func $baz + (func $baz (type $none_=>_none) (nop) ) ) @@ -972,13 +972,13 @@ Secondary: (import "primary" "%global" (global $base i32)) (import "primary" "%baz" (func $baz)) (elem (global.get $base) $foo $bar $baz $quux) - (func $bar + (func $bar (type $none_=>_none) (nop) ) - (func $foo + (func $foo (type $none_=>_none) (nop) ) - (func $quux + (func $quux (type $none_=>_none) (nop) ) ) @@ -990,10 +990,10 @@ Before: (import "env" "base" (global $base i32)) (table $table 2 funcref) (elem (global.get $base) $foo $bar) - (func $foo + (func $foo (type $none_=>_none) (nop) ) - (func $bar + (func $bar (type $none_=>_none) (call $foo) ) ) @@ -1008,7 +1008,7 @@ After: (export "%foo" (func $foo)) (export "%table" (table $table)) (export "%global" (global $base)) - (func $foo + (func $foo (type $none_=>_none) (nop) ) ) @@ -1019,7 +1019,7 @@ Secondary: (import "primary" "%global" (global $base i32)) (import "primary" "%foo" (func $foo)) (elem (global.get $base) $foo $bar) - (func $bar + (func $bar (type $none_=>_none) (call $foo) ) ) @@ -1030,12 +1030,12 @@ Before: (type $i32_=>_i32 (func (param i32) (result i32))) (table $table 1 1 funcref) (elem (i32.const 0) $foo) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (call $bar (i32.const 0) ) ) - (func $bar (param $0 i32) (result i32) + (func $bar (type $i32_=>_i32) (param $0 i32) (result i32) (call $foo (i32.const 1) ) @@ -1050,7 +1050,7 @@ After: (elem (i32.const 0) $foo $placeholder_1) (export "%foo" (func $foo)) (export "%table" (table $table)) - (func $foo (param $0 i32) (result i32) + (func $foo (type $i32_=>_i32) (param $0 i32) (result i32) (call_indirect $table (type $i32_=>_i32) (i32.const 0) (i32.const 1) @@ -1063,7 +1063,7 @@ Secondary: (import "primary" "%table" (table $table 2 2 funcref)) (import "primary" "%foo" (func $foo (param i32) (result i32))) (elem (i32.const 1) $bar) - (func $bar (param $0 i32) (result i32) + (func $bar (type $i32_=>_i32) (param $0 i32) (result i32) (call $foo (i32.const 1) ) @@ -1076,7 +1076,7 @@ Before: (type $none_=>_none (func)) (export "foo1" (func $foo)) (export "foo2" (func $foo)) - (func $foo + (func $foo (type $none_=>_none) (nop) ) ) @@ -1090,7 +1090,7 @@ After: (export "foo1" (func $foo)) (export "foo2" (func $foo)) (export "%table" (table $0)) - (func $foo + (func $foo (type $none_=>_none) (call_indirect $0 (type $none_=>_none) (i32.const 0) ) @@ -1101,7 +1101,7 @@ Secondary: (type $none_=>_none (func)) (import "primary" "%table" (table $0 1 funcref)) (elem (i32.const 0) $foo) - (func $foo + (func $foo (type $none_=>_none) (nop) ) ) @@ -1120,34 +1120,34 @@ Minimized names primary: (export "%g" (func $6)) (export "%h" (func $8)) (export "%i" (func $9)) - (func $0 + (func $0 (type $none_=>_none) (nop) ) - (func $1 + (func $1 (type $none_=>_none) (nop) ) - (func $2 + (func $2 (type $none_=>_none) (nop) ) - (func $3 + (func $3 (type $none_=>_none) (nop) ) - (func $4 + (func $4 (type $none_=>_none) (nop) ) - (func $5 + (func $5 (type $none_=>_none) (nop) ) - (func $6 + (func $6 (type $none_=>_none) (nop) ) - (func $7 + (func $7 (type $none_=>_none) (nop) ) - (func $8 + (func $8 (type $none_=>_none) (nop) ) - (func $9 + (func $9 (type $none_=>_none) (nop) ) ) @@ -1165,7 +1165,7 @@ Minimized names secondary: (import "primary" "%b" (func $7)) (import "primary" "%h" (func $8)) (import "primary" "%i" (func $9)) - (func $call + (func $call (type $none_=>_none) (call $0) (call $1) (call $2) diff --git a/test/example/type-builder.cpp b/test/example/type-builder.cpp index 7da2f8f03..2ce064b5f 100644 --- a/test/example/type-builder.cpp +++ b/test/example/type-builder.cpp @@ -18,26 +18,26 @@ void test_canonicalization() { TypeBuilder builder(4); - Type tempSigRef1 = builder.getTempRefType(builder[2], Nullable); - Type tempSigRef2 = builder.getTempRefType(builder[3], Nullable); + 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] = + builder[0] = Signature(Type::none, Type::none); + builder[1] = Signature(Type::none, Type::none); + builder[2] = Struct({Field(tempSigRef1, Immutable), Field(tempSigRef1, Immutable)}); - builder[1] = + builder[3] = Struct({Field(tempSigRef2, Immutable), Field(tempSigRef2, Immutable)}); - builder[2] = Signature(Type::none, Type::none); - builder[3] = Signature(Type::none, Type::none); std::vector<HeapType> built = *builder.build(); - assert(built[0] == struct_); - assert(built[1] == struct_); - assert(built[2] == sig); - assert(built[3] == sig); + assert(built[0] == sig); + assert(built[1] == sig); + assert(built[2] == struct_); + assert(built[3] == struct_); } // Check that defined basic HeapTypes are handled correctly. @@ -92,6 +92,7 @@ void test_recursive() { 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); @@ -103,7 +104,6 @@ void test_recursive() { std::cout << print(built[1]) << "\n\n"; assert(built[0].getSignature().results.getHeapType() == built[1]); assert(built[1].getSignature().results.getHeapType() == built[0]); - assert(built[0] == built[1]); } { @@ -111,6 +111,7 @@ void test_recursive() { 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); @@ -134,10 +135,10 @@ void test_recursive() { 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]); + assert(built[0] != built[1]); + assert(built[1] != built[2]); + assert(built[2] != built[3]); + assert(built[3] != built[4]); } { @@ -152,12 +153,13 @@ void test_recursive() { Type temp3 = builder.getTempRefType(builder[3], Nullable); Type tuple0_2 = builder.getTempTupleType({temp0, temp2}); Type tuple1_3 = builder.getTempTupleType({temp1, temp3}); - builder[0] = Signature(Type::none, tuple0_2); - builder[1] = Signature(Type::none, tuple1_3); - builder[2] = Signature(); - builder[3] = Signature(); - builder[4] = Signature(Type::none, temp0); - builder[5] = Signature(Type::none, temp1); + 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); @@ -168,13 +170,13 @@ void test_recursive() { 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[0]); - assert(built[5].getSignature().results.getHeapType() == built[1]); - assert(built[0].getSignature().results == + 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[1].getSignature().results == + assert(built[3].getSignature().results == Type({Type(built[1], Nullable), Type(built[3], Nullable)})); } @@ -193,7 +195,7 @@ void test_recursive() { 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]); + assert(built[0] != built[1]); } { @@ -201,202 +203,22 @@ void test_recursive() { std::vector<HeapType> built; { TypeBuilder builder(3); - Type temp0 = builder.getTempRefType(builder[0], Nullable); - Type anyref = builder.getTempRefType(builder[2], Nullable); - builder[0] = Signature(anyref, temp0); - builder[1] = Signature(anyref, temp0); - builder[2] = HeapType::any; + 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].getSignature().results.getHeapType() == built[0]); - assert(built[1].getSignature().results.getHeapType() == built[0]); - assert(built[0].getSignature().params == Type(HeapType::any, Nullable)); + 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[0] == built[1]); - assert(built[2] == HeapType::any); - } -} - -void test_lub() { - std::cout << ";; Test LUBs\n"; - - Type ext = Type(HeapType::ext, Nullable); - Type func = Type(HeapType::func, Nullable); - Type any = Type(HeapType::any, Nullable); - Type eq = Type(HeapType::eq, Nullable); - Type i31 = Type(HeapType::i31, Nullable); - Type data = Type(HeapType::data, Nullable); - - auto LUB = [&](Type a, Type b) { - Type lubAB = Type::getLeastUpperBound(a, b); - Type lubBA = Type::getLeastUpperBound(b, a); - assert(lubAB == lubBA); - if (lubAB == Type::none) { - assert(!Type::hasLeastUpperBound(a, b)); - assert(!Type::hasLeastUpperBound(b, a)); - } else { - assert(Type::hasLeastUpperBound(a, b)); - assert(Type::hasLeastUpperBound(b, a)); - assert(Type::isSubType(a, lubAB)); - assert(Type::isSubType(b, lubAB)); - } - return lubAB; - }; - - { - // Basic Types - for (auto other : {any, eq, i31, data}) { - assert(LUB(any, other) == any); - assert(LUB(func, other) == Type::none); - assert(LUB(ext, other) == Type::none); - } - assert(LUB(i31, data) == eq); - } - - { - // Nullable and non-nullable references - Type nullable(HeapType::any, Nullable); - Type nonNullable(HeapType::any, NonNullable); - assert(LUB(nullable, nullable) == nullable); - assert(LUB(nullable, nonNullable) == nullable); - assert(LUB(nonNullable, nonNullable) == nonNullable); - } - - { - // Funcref with specific signature - assert(LUB(func, Type(Signature(), Nullable)) == func); - } - - { - // Incompatible signatures - Type a(Signature(Type::none, any), Nullable); - Type b(Signature(any, Type::none), Nullable); - assert(LUB(a, b) == Type(HeapType::func, Nullable)); - } - - { - // Signatures incompatible in tuple size - Type a(Signature(Type::none, {any, any}), Nullable); - Type b(Signature(Type::none, {any, any, any}), Nullable); - assert(LUB(a, b) == Type(HeapType::func, Nullable)); - } - - // { - // // Covariance of function results - // Type a(Signature(Type::none, {Type::eqref, Type::funcref}), Nullable); - // Type b(Signature(Type::none, {Type::funcref, Type::eqref}), Nullable); - // assert(LUB(a, b) == Type(Signature(Type::none, {Type::anyref, - // Type::anyref}), Nullable)); - // } - - // TODO: Test contravariance in function parameters once that is supported. - - // { - // // Nested signatures - // Type baseA(Signature(Type::none, Type::eqref), Nullable); - // Type baseB(Signature(Type::none, Type::funcref), Nullable); - // Type a(Signature(Type::none, baseA), Nullable); - // Type b(Signature(Type::none, baseB), Nullable); - // Type baseLub(Signature(Type::none, Type::anyref), Nullable); - // Type lub(Signature(Type::none, baseLub), Nullable); - // assert(LUB(a, b) == lub); - // } - - // TODO: Test recursive signatures once signature subtyping is supported. - - { - // Mutable fields are invariant - Type a(Array(Field(eq, Mutable)), Nullable); - Type b(Array(Field(func, Mutable)), Nullable); - assert(LUB(a, b) == data); - } - - { - // Immutable fields are covariant - Type a(Array(Field(data, Immutable)), Nullable); - Type b(Array(Field(i31, Immutable)), Nullable); - Type lub(Array(Field(eq, Immutable)), Nullable); - assert(LUB(a, b) == lub); - } - - { - // Depth subtyping - Type a(Struct({Field(data, Immutable)}), Nullable); - Type b(Struct({Field(i31, Immutable)}), Nullable); - Type lub(Struct({Field(eq, Immutable)}), Nullable); - assert(LUB(a, b) == lub); - } - - { - // Width subtyping - Type a(Struct({Field(Type::i32, Immutable)}), Nullable); - Type b(Struct({Field(Type::i32, Immutable), Field(Type::i32, Immutable)}), - Nullable); - assert(LUB(a, b) == a); - } - - { - // Width subtyping with different suffixes - Type a(Struct({Field(Type::i32, Immutable), Field(Type::i64, Immutable)}), - Nullable); - Type b(Struct({Field(Type::i32, Immutable), Field(Type::f32, Immutable)}), - Nullable); - Type lub(Struct({Field(Type::i32, Immutable)}), Nullable); - assert(LUB(a, b) == lub); - } - - { - // Width and depth subtyping with different suffixes - Type a(Struct({Field(data, Immutable), Field(Type::i64, Immutable)}), - Nullable); - Type b(Struct({Field(i31, Immutable), Field(Type::f32, Immutable)}), - Nullable); - Type lub(Struct({Field(eq, Immutable)}), Nullable); - assert(LUB(a, b) == lub); - } - - { - // No common prefix - Type a(Struct({Field(Type::i32, Immutable), Field(any, Immutable)}), - Nullable); - Type b(Struct({Field(Type::f32, Immutable), Field(any, Immutable)}), - Nullable); - Type lub(Struct(), Nullable); - assert(LUB(a, b) == lub); - } - - { - // Nested structs - Type innerA(Struct({Field(data, Immutable)}), Nullable); - Type innerB(Struct({Field(i31, Immutable)}), Nullable); - Type innerLub(Struct({Field(eq, Immutable)}), Nullable); - Type a(Struct({Field(innerA, Immutable)}), Nullable); - Type b(Struct({Field(innerB, Immutable)}), Nullable); - Type lub(Struct({Field(innerLub, Immutable)}), Nullable); - assert(LUB(a, b) == lub); - } - - { - // Recursive structs - TypeBuilder builder(2); - Type tempA = builder.getTempRefType(builder[0], Nullable); - Type tempB = builder.getTempRefType(builder[1], Nullable); - builder[0] = Struct({Field(tempB, Immutable), Field(data, Immutable)}); - builder[1] = Struct({Field(tempA, Immutable), Field(i31, Immutable)}); - auto built = *builder.build(); - Type a(built[0], Nullable); - Type b(built[1], Nullable); - - TypeBuilder lubBuilder(1); - Type tempLub = builder.getTempRefType(lubBuilder[0], Nullable); - lubBuilder[0] = Struct({Field(tempLub, Immutable), Field(eq, Immutable)}); - built = *lubBuilder.build(); - Type lub(built[0], Nullable); - - assert(LUB(a, b) == lub); + assert(built[2].getSignature().params == Type(HeapType::any, Nullable)); + assert(built[1] != built[2]); } } @@ -407,6 +229,5 @@ int main() { test_canonicalization(); test_basic(); test_recursive(); - test_lub(); } } diff --git a/test/example/type-builder.txt b/test/example/type-builder.txt index 372e531a1..af40fd5de 100644 --- a/test/example/type-builder.txt +++ b/test/example/type-builder.txt @@ -1,56 +1,54 @@ ;; Test canonicalization ;; Test basic ;; Test recursive types -(func (result (ref null $0))) +(func_subtype (result (ref null $0)) func) -(func (result (ref null $0))) -(func (result (ref null $0))) +(func_subtype (result (ref null $1)) func) +(func_subtype (result (ref null $0)) func) -(func (result (ref null $0))) -(func (result (ref null $0))) -(func (result (ref null $0))) -(func (result (ref null $0))) -(func (result (ref null $0))) +(func_subtype (result (ref null $1)) func) +(func_subtype (result (ref null $2)) func) +(func_subtype (result (ref null $3)) func) +(func_subtype (result (ref null $4)) func) +(func_subtype (result (ref null $0)) func) -(func (result (ref null $0) (ref null $2))) -(func (result (ref null $0) (ref null $2))) -(func) -(func) -(func (result (ref null $0))) -(func (result (ref null $0))) +(func_subtype func) +(func_subtype func) +(func_subtype (result (ref null $0) (ref null $2)) func) +(func_subtype (result (ref null $0) (ref null $3)) func) +(func_subtype (result (ref null $2)) func) +(func_subtype (result (ref null $3)) func) -(func (result (ref null $0))) -(func (result (ref null $0))) +(func_subtype (result (ref null $0)) func) +(func_subtype (result (ref null $0)) func) -(func (param anyref) (result (ref null $0))) -(func (param anyref) (result (ref null $0))) +any +(func_subtype (param anyref) (result (ref null $1)) func) -;; Test LUBs ;; Test canonicalization ;; Test basic ;; Test recursive types -(func (result (ref null $0))) +(func_subtype (result (ref null $0)) func) -(func (result (ref null $0))) -(func (result (ref null $0))) +(func_subtype (result (ref null $1)) func) +(func_subtype (result (ref null $0)) func) -(func (result (ref null $0))) -(func (result (ref null $0))) -(func (result (ref null $0))) -(func (result (ref null $0))) -(func (result (ref null $0))) +(func_subtype (result (ref null $1)) func) +(func_subtype (result (ref null $2)) func) +(func_subtype (result (ref null $3)) func) +(func_subtype (result (ref null $4)) func) +(func_subtype (result (ref null $0)) func) -(func (result (ref null $0) (ref null $2))) -(func (result (ref null $0) (ref null $2))) -(func) -(func) -(func (result (ref null $0))) -(func (result (ref null $0))) +(func_subtype func) +(func_subtype func) +(func_subtype (result (ref null $0) (ref null $2)) func) +(func_subtype (result (ref null $0) (ref null $3)) func) +(func_subtype (result (ref null $2)) func) +(func_subtype (result (ref null $3)) func) -(func (result (ref null $0))) -(func (result (ref null $0))) +(func_subtype (result (ref null $0)) func) +(func_subtype (result (ref null $0)) func) -(func (param anyref) (result (ref null $0))) -(func (param anyref) (result (ref null $0))) +any +(func_subtype (param anyref) (result (ref null $1)) func) -;; Test LUBs diff --git a/test/example/typeinfo.txt b/test/example/typeinfo.txt index 7015e6cfc..67f9766d0 100644 --- a/test/example/typeinfo.txt +++ b/test/example/typeinfo.txt @@ -11,31 +11,31 @@ eqref i31 i31ref (ref i31) -(func) -(struct) -(array i32) +(func_subtype func) +(struct_subtype data) +(array_subtype i32 data) ;; Signature -(func) +(func_subtype func) (ref $func.0) (ref null $func.0) -(func (param i32) (result f64)) +(func_subtype (param i32) (result f64) func) (ref $func.0) (ref null $func.0) ;; Struct -(struct) +(struct_subtype data) (ref $struct.0) (ref null $struct.0) -(struct (field i32 i64 (mut f32) (mut f64))) +(struct_subtype (field i32 i64 (mut f32) (mut f64)) data) (ref $struct.0) (ref null $struct.0) ;; Array -(array i32) +(array_subtype i32 data) (ref $array.0) (ref null $array.0) -(array (mut i64)) +(array_subtype (mut i64) data) (ref $array.0) (ref null $array.0) @@ -46,33 +46,33 @@ none (i32 f64) ;; Signature of references (param/result) -(func (param (ref null $struct.0)) (result (ref $array.0))) +(func_subtype (param (ref null $struct.0)) (result (ref $array.0)) func) ;; Signature of references (params/results) -(func (param (ref null $struct.0) (ref $array.0)) (result (ref $struct.0) (ref null $array.1))) +(func_subtype (param (ref null $struct.0) (ref $array.0)) (result (ref $struct.0) (ref null $array.1)) func) ;; Struct of references -(struct (field (ref $func.0) (mut (ref $func.0)) (ref null $func.0) (mut (ref null $func.0)))) +(struct_subtype (field (ref $func.0) (mut (ref $func.0)) (ref null $func.0) (mut (ref null $func.0))) data) (ref $struct.0) (ref null $struct.0) -(struct (field (ref $struct.0) (mut (ref $struct.0)) (ref null $struct.0) (mut (ref null $struct.0)))) +(struct_subtype (field (ref $struct.0) (mut (ref $struct.0)) (ref null $struct.0) (mut (ref null $struct.0))) data) (ref $struct.0) (ref null $struct.0) -(struct (field (ref $array.0) (mut (ref $array.0)) (ref null $array.0) (mut (ref null $array.0)))) +(struct_subtype (field (ref $array.0) (mut (ref $array.0)) (ref null $array.0) (mut (ref null $array.0))) data) (ref $struct.0) (ref null $struct.0) -(struct (field (mut i32) (mut (ref null $func.0)) (mut (ref null $struct.0)) (mut (ref null $array.0)))) +(struct_subtype (field (mut i32) (mut (ref null $func.0)) (mut (ref null $struct.0)) (mut (ref null $array.0))) data) (ref $struct.0) (ref null $struct.0) ;; Array of references -(array (ref null $func.0)) +(array_subtype (ref null $func.0) data) (ref $array.0) (ref null $array.0) -(array (mut (ref null $struct.0))) +(array_subtype (mut (ref null $struct.0)) data) (ref $array.0) (ref null $array.0) -(array (ref null $array.0)) +(array_subtype (ref null $array.0) data) (ref $array.0) (ref null $array.0) @@ -81,7 +81,7 @@ none ((ref $func.0) (ref null $func.0) (ref $struct.0) (ref null $struct.0) (ref $array.0) (ref null $array.0)) ;; Recursive (not really) -(func (param (ref $func.0))) +(func_subtype (param (ref $func.0)) func) (ref $func.0) -(func (param (ref $array.0))) +(func_subtype (param (ref $array.0)) func) (ref $func.0) |