diff options
Diffstat (limited to 'test')
43 files changed, 1053 insertions, 805 deletions
diff --git a/test/binaryen.js/exception-handling.js b/test/binaryen.js/exception-handling.js index 3f5f6de74..e6cadcf88 100644 --- a/test/binaryen.js/exception-handling.js +++ b/test/binaryen.js/exception-handling.js @@ -1,7 +1,9 @@ function cleanInfo(info) { var ret = {}; for (var x in info) { - if (x == 'id' || x == 'type' || x == 'name' || x == 'event') { + // Filter out address pointers and only print meaningful info + if (x == 'id' || x == 'type' || x == 'name' || x == 'event' || + x == 'depth' || x == 'hasCatchAll') { ret[x] = info[x]; } } @@ -23,36 +25,31 @@ var event_ = module.addEvent("e", 0, binaryen.i32, binaryen.none); // (throw $e (i32.const 0)) // ) // (catch -// ;; We don't support multi-value yet. Use locals instead. -// (local.set 0 (exnref.pop)) -// (drop -// (block $l (result i32) -// (rethrow -// (br_on_exn $l $e (local.get 0)) -// ) -// ) -// ) +// (drop (pop i32)) +// (rethrow 0) // ) // ) var throw_ = module.throw("e", [module.i32.const(0)]); -var br_on_exn = module.br_on_exn("l", "e", module.local.get(0, binaryen.exnref)); -var rethrow = module.rethrow(br_on_exn); +var rethrow = module.rethrow(0); var try_ = module.try( throw_, - module.block(null, [ - module.local.set(0, module.exnref.pop()), - module.drop( - module.block("l", [rethrow], binaryen.i32) + ["e"], + [ + module.block(null, + [ + module.drop(module.i32.pop()), + rethrow + ], + binaryen.none ) ] - ) ); -var func = module.addFunction("test", binaryen.none, binaryen.none, [binaryen.exnref], try_); + +var func = module.addFunction("test", binaryen.none, binaryen.none, [], try_); console.log(module.emitText()); assert(module.validate()); console.log("getExpressionInfo(throw) = " + stringify(throw_)); -console.log("getExpressionInfo(br_on_exn) = " + stringify(br_on_exn)); console.log("getExpressionInfo(rethrow) = " + stringify(rethrow)); console.log("getExpressionInfo(try) = " + stringify(try_)); diff --git a/test/binaryen.js/exception-handling.js.txt b/test/binaryen.js/exception-handling.js.txt index 19861dd21..e7c72e6a7 100644 --- a/test/binaryen.js/exception-handling.js.txt +++ b/test/binaryen.js/exception-handling.js.txt @@ -3,32 +3,22 @@ (type $i32_=>_none (func (param i32))) (event $e (attr 0) (param i32)) (func $test - (local $0 exnref) (try (do (throw $e (i32.const 0) ) ) - (catch - (local.set $0 - (pop exnref) - ) + (catch $e (drop - (block $l (result i32) - (rethrow - (br_on_exn $l $e - (local.get $0) - ) - ) - ) + (pop i32) ) + (rethrow 0) ) ) ) ) getExpressionInfo(throw) = {"id":47,"type":1,"event":"e"} -getExpressionInfo(br_on_exn) = {"id":49,"type":9,"name":"l","event":"e"} -getExpressionInfo(rethrow) = {"id":48,"type":1} -getExpressionInfo(try) = {"id":46,"type":0} +getExpressionInfo(rethrow) = {"id":48,"type":1,"depth":0} +getExpressionInfo(try) = {"id":46,"type":1,"hasCatchAll":0} diff --git a/test/binaryen.js/expressions.js b/test/binaryen.js/expressions.js index 61fc0a3ef..757d88b1b 100644 --- a/test/binaryen.js/expressions.js +++ b/test/binaryen.js/expressions.js @@ -1435,31 +1435,69 @@ console.log("# RefEq"); console.log("# Try"); (function testTry() { const module = new binaryen.Module(); + module.addEvent("event1", 0, binaryen.none, binaryen.none); + module.addEvent("event2", 0, binaryen.none, binaryen.none); + module.addEvent("event3", 0, binaryen.none, binaryen.none); var body = module.i32.const(1); - var catchBody = module.i32.const(2); - const theTry = binaryen.Try(module.try(body, catchBody)); + var catchBodies = [ + module.i32.const(2), + module.i32.const(3) + ]; + const theTry = binaryen.Try(module.try(body, ["event1"], catchBodies)); assert(theTry instanceof binaryen.Try); assert(theTry instanceof binaryen.Expression); assert(theTry.body === body); - assert(theTry.catchBody === catchBody); + assertDeepEqual(theTry.catchBodies, catchBodies); assert(theTry.type === binaryen.i32); + assert(theTry.getNumCatchEvents() == 1); + assert(theTry.getNumCatchBodies() == 2); + assert(theTry.hasCatchAll() == 1); + console.log(theTry.toText()); - theTry.body = body = module.i32.const(3); + theTry.body = body = module.i32.const(4); assert(theTry.body === body); - theTry.catchBody = catchBody = module.i32.const(4); - assert(theTry.catchBody === catchBody); + catchBodies = [ + module.i32.const(5) // set + //remove + ]; + theTry.setCatchBodies(catchBodies); + assertDeepEqual(theTry.catchBodies, catchBodies); + assertDeepEqual(theTry.getCatchBodies(), catchBodies); + console.log(theTry.toText()); + + theTry.insertCatchEventAt(1, "event2"); + theTry.insertCatchBodyAt(0, module.i32.const(6)); + assert(theTry.getNumCatchEvents() == 2); + assert(theTry.getNumCatchBodies() == 2); + assert(theTry.hasCatchAll() == 0); + console.log(theTry.toText()); + + assert(theTry.removeCatchEventAt(1) == "event2"); + theTry.removeCatchBodyAt(1); + assert(theTry.getNumCatchEvents() == 1); + assert(theTry.getNumCatchBodies() == 1); + console.log(theTry.toText()); + + theTry.appendCatchEvent("event3"); + theTry.appendCatchBody(module.drop(module.i32.const(7))); + assert(theTry.getCatchEventAt(0) == "event1"); + assert(theTry.getCatchEventAt(1) == "event3"); + theTry.setCatchEvents(["event2", "event3"]); + assertDeepEqual(theTry.getCatchEvents(), ["event2", "event3"]); + theTry.setCatchBodies([module.i32.const(8), module.i32.const(9)]); + assert(theTry.getCatchEventAt(0) == "event2"); + assert(theTry.getCatchEventAt(1) == "event3"); + theTry.setCatchEventAt(1, "event1"); + theTry.setCatchBodyAt(1, module.i32.const(10)); + assert(theTry.getCatchEventAt(1) == "event1"); + console.log(theTry.toText()); + theTry.type = binaryen.f64; theTry.finalize(); assert(theTry.type === binaryen.i32); console.log(theTry.toText()); - assert( - theTry.toText() - == - "(try (result i32)\n (do\n (i32.const 3)\n )\n (catch\n (i32.const 4)\n )\n)\n" - ); - module.dispose(); })(); @@ -1512,15 +1550,14 @@ console.log("# Rethrow"); (function testRethrow() { const module = new binaryen.Module(); - var exnref = module.local.get(1, binaryen.exnref); - const theRethrow = binaryen.Rethrow(module.rethrow(exnref)); + const theRethrow = binaryen.Rethrow(module.rethrow(0)); assert(theRethrow instanceof binaryen.Rethrow); assert(theRethrow instanceof binaryen.Expression); - assert(theRethrow.exnref === exnref); + assert(theRethrow.depth === 0); assert(theRethrow.type === binaryen.unreachable); - theRethrow.exnref = exnref = module.local.get(2, binaryen.exnref); - assert(theRethrow.exnref === exnref); + theRethrow.depth = 1 + assert(theRethrow.depth === 1); theRethrow.type = binaryen.f64; theRethrow.finalize(); assert(theRethrow.type === binaryen.unreachable); @@ -1529,7 +1566,7 @@ console.log("# Rethrow"); assert( theRethrow.toText() == - "(rethrow\n (local.get $2)\n)\n" + "(rethrow 1)\n" ); module.dispose(); diff --git a/test/binaryen.js/expressions.js.txt b/test/binaryen.js/expressions.js.txt index ba946b296..d6c090d18 100644 --- a/test/binaryen.js/expressions.js.txt +++ b/test/binaryen.js/expressions.js.txt @@ -219,11 +219,68 @@ # Try (try (result i32) (do + (i32.const 1) + ) + (catch $event1 + (i32.const 2) + ) + (catch_all (i32.const 3) ) - (catch +) + +(try (result i32) + (do (i32.const 4) ) + (catch $event1 + (i32.const 5) + ) +) + +(try (result i32) + (do + (i32.const 4) + ) + (catch $event1 + (i32.const 6) + ) + (catch $event2 + (i32.const 5) + ) +) + +(try (result i32) + (do + (i32.const 4) + ) + (catch $event1 + (i32.const 6) + ) +) + +(try (result i32) + (do + (i32.const 4) + ) + (catch $event2 + (i32.const 8) + ) + (catch $event1 + (i32.const 10) + ) +) + +(try (result i32) + (do + (i32.const 4) + ) + (catch $event2 + (i32.const 8) + ) + (catch $event1 + (i32.const 10) + ) ) # Throw @@ -233,9 +290,7 @@ ) # Rethrow -(rethrow - (local.get $2) -) +(rethrow 1) # BrOnExn (br_on_exn $bar $event2 diff --git a/test/binaryen.js/kitchen-sink.js b/test/binaryen.js/kitchen-sink.js index 146335130..8e7e81f26 100644 --- a/test/binaryen.js/kitchen-sink.js +++ b/test/binaryen.js/kitchen-sink.js @@ -547,18 +547,8 @@ function test_core() { // Exception handling module.try( module.throw("a-event", [module.i32.const(0)]), - module.block(null, [ - module.local.set(5, module.exnref.pop()), - module.drop( - module.block("try-block", [ - module.rethrow( - module.br_on_exn("try-block", "a-event", - module.local.get(5, binaryen.exnref)), - ) - ], binaryen.i32) - ) - ] - ) + ["a-event"], + [module.drop(module.i32.pop())] ), // Atomics diff --git a/test/binaryen.js/kitchen-sink.js.txt b/test/binaryen.js/kitchen-sink.js.txt index 907d490fe..ef15d8a00 100644 --- a/test/binaryen.js/kitchen-sink.js.txt +++ b/test/binaryen.js/kitchen-sink.js.txt @@ -1865,18 +1865,9 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7} (i32.const 0) ) ) - (catch - (local.set $5 - (pop exnref) - ) + (catch $a-event (drop - (block $try-block (result i32) - (rethrow - (br_on_exn $try-block $a-event - (local.get $5) - ) - ) - ) + (pop i32) ) ) ) @@ -3737,18 +3728,9 @@ getExpressionInfo(tuple[3])={"id":14,"type":5,"value":3.7} (i32.const 0) ) ) - (catch - (local.set $5 - (pop exnref) - ) + (catch $a-event (drop - (block $try-block (result i32) - (rethrow - (br_on_exn $try-block $a-event - (local.get $5) - ) - ) - ) + (pop i32) ) ) ) diff --git a/test/binaryen.js/sideffects.js b/test/binaryen.js/sideffects.js index bfb5404c2..cb0e8ac7f 100644 --- a/test/binaryen.js/sideffects.js +++ b/test/binaryen.js/sideffects.js @@ -108,7 +108,7 @@ assert( assert( binaryen.getSideEffects( - module.drop(module.exnref.pop()), + module.drop(module.i32.pop()), module.getFeatures() ) == diff --git a/test/break-within-catch.wasm b/test/break-within-catch.wasm Binary files differindex 90b08f9a9..39a0cafb2 100644 --- a/test/break-within-catch.wasm +++ b/test/break-within-catch.wasm diff --git a/test/break-within-catch.wasm.fromBinary b/test/break-within-catch.wasm.fromBinary index 82ab6e717..d7e2dc57b 100644 --- a/test/break-within-catch.wasm.fromBinary +++ b/test/break-within-catch.wasm.fromBinary @@ -1,14 +1,16 @@ (module (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) + (event $event$0 (attr 0) (param i32)) (func $0 (block $label$2 (try (do (nop) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (br $label$2) ) diff --git a/test/example/c-api-kitchen-sink.c b/test/example/c-api-kitchen-sink.c index 79cbabca3..58b1e00aa 100644 --- a/test/example/c-api-kitchen-sink.c +++ b/test/example/c-api-kitchen-sink.c @@ -325,40 +325,18 @@ void test_core() { // (do // (throw $a-event (i32.const 0)) // ) - // (catch - // ;; We don't support multi-value yet. Use locals instead. - // (local.set 0 (exnref.pop)) - // (drop - // (block $try-block (result i32) - // (rethrow - // (br_on_exn $try-block $a-event (local.get 5)) - // ) - // ) - // ) + // (catch $a-event + // (drop (i32 pop)) // ) + // (catch_all) // ) BinaryenExpressionRef tryBody = BinaryenThrow( module, "a-event", (BinaryenExpressionRef[]){makeInt32(module, 0)}, 1); - BinaryenExpressionRef catchBody = BinaryenBlock( - module, - NULL, - (BinaryenExpressionRef[]){ - BinaryenLocalSet(module, 5, BinaryenPop(module, BinaryenTypeExnref())), - BinaryenDrop( - module, - BinaryenBlock(module, - "try-block", - (BinaryenExpressionRef[]){BinaryenRethrow( - module, - BinaryenBrOnExn( - module, - "try-block", - "a-event", - BinaryenLocalGet(module, 5, BinaryenTypeExnref())))}, - 1, - BinaryenTypeInt32()))}, - 2, - BinaryenTypeNone()); + BinaryenExpressionRef catchBody = + BinaryenDrop(module, BinaryenPop(module, BinaryenTypeInt32())); + BinaryenExpressionRef catchAllBody = BinaryenNop(module); + BinaryenExpressionRef catchBodies[] = {catchBody, catchAllBody}; + const char* catchEvents[] = {"a-event"}; BinaryenType i32 = BinaryenTypeInt32(); BinaryenType i64 = BinaryenTypeInt64(); @@ -747,7 +725,7 @@ void test_core() { BinaryenRefNull(module, BinaryenTypeEqref()), BinaryenRefNull(module, BinaryenTypeEqref())), // Exception handling - BinaryenTry(module, tryBody, catchBody), + BinaryenTry(module, tryBody, catchEvents, 1, catchBodies, 2), // Atomics BinaryenAtomicStore( module, diff --git a/test/example/c-api-kitchen-sink.txt b/test/example/c-api-kitchen-sink.txt index 083fa1ce5..7fa387daa 100644 --- a/test/example/c-api-kitchen-sink.txt +++ b/test/example/c-api-kitchen-sink.txt @@ -1771,20 +1771,14 @@ BinaryenFeatureAll: 8191 (i32.const 0) ) ) - (catch - (local.set $5 - (pop exnref) - ) + (catch $a-event (drop - (block $try-block (result i32) - (rethrow - (br_on_exn $try-block $a-event - (local.get $5) - ) - ) - ) + (pop i32) ) ) + (catch_all + (nop) + ) ) (i32.atomic.store (i32.const 0) diff --git a/test/exception-handling.wast b/test/exception-handling.wast index 862b82d88..72eb0be4a 100644 --- a/test/exception-handling.wast +++ b/test/exception-handling.wast @@ -1,6 +1,7 @@ (module - (event $e0 (attr 0) (param i32)) - (event $e1 (attr 0) (param externref)) + (event $e-i32 (attr 0) (param i32)) + (event $e-i64 (attr 0) (param i64)) + (event $e-i32-i64 (attr 0) (param i32 i64)) (func $exnref_test (param $0 exnref) (result exnref) (local.get $0) @@ -9,20 +10,27 @@ (func $foo) (func $bar) - (func $eh_test (local $exn exnref) + (func $eh_test (local $x (i32 i64)) + ;; Simple try-catch (try (do - (throw $e0 (i32.const 0)) + (throw $e-i32 (i32.const 0)) ) - (catch - ;; Multi-value is not available yet, so block can't take a value from - ;; stack. So this uses locals for now. - (local.set $exn (pop exnref)) + (catch $e-i32 + (drop (pop i32)) + ) + ) + + ;; try-catch with multivalue event + (try + (do + (throw $e-i32-i64 (i32.const 0) (i64.const 0)) + ) + (catch $e-i32-i64 + (local.set $x (pop i32 i64)) (drop - (block $l0 (result i32) - (rethrow - (br_on_exn $l0 $e0 (local.get $exn)) - ) + (tuple.extract 0 + (local.get $x) ) ) ) @@ -33,7 +41,8 @@ (do (br $l1) ) - (catch + (catch $e-i32 + (drop (pop i32)) (br $l1) ) ) @@ -41,8 +50,8 @@ ;; Empty try body (try (do) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) ) ) @@ -52,11 +61,60 @@ (call $foo) (call $bar) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) + (call $foo) + (call $bar) + ) + ) + + ;; Multiple catch clauses + (try + (do + (throw $e-i32 (i32.const 0)) + ) + (catch $e-i32 + (drop (pop i32)) + ) + (catch $e-i64 + (drop (pop i64)) + ) + ) + + ;; Single catch-all clause + (try + (do + (throw $e-i32 (i32.const 0)) + ) + (catch_all) + ) + + ;; catch and catch-all clauses together + (try + (do + (throw $e-i32 (i32.const 0)) + ) + (catch $e-i32 + (drop (pop i32)) + ) + (catch $e-i64 + (drop (pop i64)) + ) + (catch_all (call $foo) (call $bar) ) ) + + ;; rethrow + (try + (do + (throw $e-i32 (i32.const 0)) + ) + (catch $e-i32 + (drop (pop i32)) + (rethrow 0) + ) + ) ) ) diff --git a/test/exception-handling.wast.from-wast b/test/exception-handling.wast.from-wast index 9fd06c0b1..64d78d54e 100644 --- a/test/exception-handling.wast.from-wast +++ b/test/exception-handling.wast.from-wast @@ -1,10 +1,12 @@ (module (type $none_=>_none (func)) (type $i32_=>_none (func (param i32))) - (type $externref_=>_none (func (param externref))) + (type $i64_=>_none (func (param i64))) + (type $i32_i64_=>_none (func (param i32 i64))) (type $exnref_=>_exnref (func (param exnref) (result exnref))) - (event $e0 (attr 0) (param i32)) - (event $e1 (attr 0) (param externref)) + (event $e-i32 (attr 0) (param i32)) + (event $e-i64 (attr 0) (param i64)) + (event $e-i32-i64 (attr 0) (param i32 i64)) (func $exnref_test (param $0 exnref) (result exnref) (local.get $0) ) @@ -15,24 +17,33 @@ (nop) ) (func $eh_test - (local $exn exnref) + (local $x (i32 i64)) (try (do - (throw $e0 + (throw $e-i32 (i32.const 0) ) ) - (catch - (local.set $exn - (pop exnref) + (catch $e-i32 + (drop + (pop i32) + ) + ) + ) + (try + (do + (throw $e-i32-i64 + (i32.const 0) + (i64.const 0) + ) + ) + (catch $e-i32-i64 + (local.set $x + (pop i32 i64) ) (drop - (block $l0 (result i32) - (rethrow - (br_on_exn $l0 $e0 - (local.get $exn) - ) - ) + (tuple.extract 0 + (local.get $x) ) ) ) @@ -42,7 +53,10 @@ (do (br $l1) ) - (catch + (catch $e-i32 + (drop + (pop i32) + ) (br $l1) ) ) @@ -51,9 +65,9 @@ (do (nop) ) - (catch + (catch $e-i32 (drop - (pop exnref) + (pop i32) ) ) ) @@ -62,13 +76,74 @@ (call $foo) (call $bar) ) - (catch + (catch $e-i32 + (drop + (pop i32) + ) + (call $foo) + (call $bar) + ) + ) + (try + (do + (throw $e-i32 + (i32.const 0) + ) + ) + (catch $e-i32 + (drop + (pop i32) + ) + ) + (catch $e-i64 + (drop + (pop i64) + ) + ) + ) + (try + (do + (throw $e-i32 + (i32.const 0) + ) + ) + (catch_all + (nop) + ) + ) + (try + (do + (throw $e-i32 + (i32.const 0) + ) + ) + (catch $e-i32 (drop - (pop exnref) + (pop i32) ) + ) + (catch $e-i64 + (drop + (pop i64) + ) + ) + (catch_all (call $foo) (call $bar) ) ) + (try + (do + (throw $e-i32 + (i32.const 0) + ) + ) + (catch $e-i32 + (drop + (pop i32) + ) + (rethrow 0) + ) + ) ) ) diff --git a/test/exception-handling.wast.fromBinary b/test/exception-handling.wast.fromBinary index 4e1895593..292827970 100644 --- a/test/exception-handling.wast.fromBinary +++ b/test/exception-handling.wast.fromBinary @@ -1,10 +1,12 @@ (module (type $none_=>_none (func)) (type $i32_=>_none (func (param i32))) - (type $externref_=>_none (func (param externref))) + (type $i64_=>_none (func (param i64))) + (type $i32_i64_=>_none (func (param i32 i64))) (type $exnref_=>_exnref (func (param exnref) (result exnref))) (event $event$0 (attr 0) (param i32)) - (event $event$1 (attr 0) (param externref)) + (event $event$1 (attr 0) (param i64)) + (event $event$2 (attr 0) (param i32 i64)) (func $exnref_test (param $0 exnref) (result exnref) (local.get $0) ) @@ -15,38 +17,72 @@ (nop) ) (func $eh_test - (local $exn exnref) + (local $x i32) + (local $1 i64) + (local $2 (i32 i64)) + (local $3 i32) + (local $4 i32) (try (do (throw $event$0 (i32.const 0) ) ) - (catch - (local.set $exn - (pop exnref) - ) + (catch $event$0 (drop - (block $label$3 (result i32) - (rethrow - (br_on_exn $label$3 $event$0 - (local.get $exn) + (pop i32) + ) + ) + ) + (try + (do + (throw $event$2 + (i32.const 0) + (i64.const 0) + ) + ) + (catch $event$2 + (local.set $2 + (pop i32 i64) + ) + (local.set $x + (block (result i32) + (local.set $3 + (tuple.extract 0 + (local.get $2) + ) + ) + (local.set $1 + (tuple.extract 1 + (local.get $2) ) ) + (local.get $3) + ) + ) + (drop + (block (result i32) + (local.set $4 + (local.get $x) + ) + (drop + (local.get $1) + ) + (local.get $4) ) ) ) ) - (block $label$4 + (block $label$5 (try (do - (br $label$4) + (br $label$5) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) - (br $label$4) + (br $label$5) ) ) ) @@ -54,9 +90,9 @@ (do (nop) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) ) ) @@ -65,14 +101,75 @@ (call $foo) (call $bar) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (call $foo) (call $bar) ) ) + (try + (do + (throw $event$0 + (i32.const 0) + ) + ) + (catch $event$0 + (drop + (pop i32) + ) + ) + (catch $event$1 + (drop + (pop i64) + ) + ) + ) + (try + (do + (throw $event$0 + (i32.const 0) + ) + ) + (catch_all + (nop) + ) + ) + (try + (do + (throw $event$0 + (i32.const 0) + ) + ) + (catch $event$0 + (drop + (pop i32) + ) + ) + (catch $event$1 + (drop + (pop i64) + ) + ) + (catch_all + (call $foo) + (call $bar) + ) + ) + (try + (do + (throw $event$0 + (i32.const 0) + ) + ) + (catch $event$0 + (drop + (pop i32) + ) + (rethrow 0) + ) + ) ) ) diff --git a/test/exception-handling.wast.fromBinary.noDebugInfo b/test/exception-handling.wast.fromBinary.noDebugInfo index 0b5a7d896..1f1ebdb6f 100644 --- a/test/exception-handling.wast.fromBinary.noDebugInfo +++ b/test/exception-handling.wast.fromBinary.noDebugInfo @@ -1,10 +1,12 @@ (module (type $none_=>_none (func)) (type $i32_=>_none (func (param i32))) - (type $externref_=>_none (func (param externref))) + (type $i64_=>_none (func (param i64))) + (type $i32_i64_=>_none (func (param i32 i64))) (type $exnref_=>_exnref (func (param exnref) (result exnref))) (event $event$0 (attr 0) (param i32)) - (event $event$1 (attr 0) (param externref)) + (event $event$1 (attr 0) (param i64)) + (event $event$2 (attr 0) (param i32 i64)) (func $0 (param $0 exnref) (result exnref) (local.get $0) ) @@ -15,38 +17,72 @@ (nop) ) (func $3 - (local $0 exnref) + (local $0 i32) + (local $1 i64) + (local $2 (i32 i64)) + (local $3 i32) + (local $4 i32) (try (do (throw $event$0 (i32.const 0) ) ) - (catch + (catch $event$0 + (drop + (pop i32) + ) + ) + ) + (try + (do + (throw $event$2 + (i32.const 0) + (i64.const 0) + ) + ) + (catch $event$2 + (local.set $2 + (pop i32 i64) + ) (local.set $0 - (pop exnref) + (block (result i32) + (local.set $3 + (tuple.extract 0 + (local.get $2) + ) + ) + (local.set $1 + (tuple.extract 1 + (local.get $2) + ) + ) + (local.get $3) + ) ) (drop - (block $label$3 (result i32) - (rethrow - (br_on_exn $label$3 $event$0 - (local.get $0) - ) + (block (result i32) + (local.set $4 + (local.get $0) + ) + (drop + (local.get $1) ) + (local.get $4) ) ) ) ) - (block $label$4 + (block $label$5 (try (do - (br $label$4) + (br $label$5) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) - (br $label$4) + (br $label$5) ) ) ) @@ -54,9 +90,9 @@ (do (nop) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) ) ) @@ -65,14 +101,75 @@ (call $1) (call $2) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (call $1) (call $2) ) ) + (try + (do + (throw $event$0 + (i32.const 0) + ) + ) + (catch $event$0 + (drop + (pop i32) + ) + ) + (catch $event$1 + (drop + (pop i64) + ) + ) + ) + (try + (do + (throw $event$0 + (i32.const 0) + ) + ) + (catch_all + (nop) + ) + ) + (try + (do + (throw $event$0 + (i32.const 0) + ) + ) + (catch $event$0 + (drop + (pop i32) + ) + ) + (catch $event$1 + (drop + (pop i64) + ) + ) + (catch_all + (call $1) + (call $2) + ) + ) + (try + (do + (throw $event$0 + (i32.const 0) + ) + ) + (catch $event$0 + (drop + (pop i32) + ) + (rethrow 0) + ) + ) ) ) diff --git a/test/passes/code-pushing_all-features.txt b/test/passes/code-pushing_all-features.txt index 30eb7e458..1f975a2dd 100644 --- a/test/passes/code-pushing_all-features.txt +++ b/test/passes/code-pushing_all-features.txt @@ -40,7 +40,7 @@ ) ) ) - (func $can-push-past-throw-within-try + (func $can-push-past-try (local $x i32) (block $out (try @@ -49,9 +49,9 @@ (i32.const 0) ) ) - (catch + (catch_all (drop - (pop exnref) + (pop i32) ) ) ) @@ -69,6 +69,36 @@ ) ) ) + (func $foo + (nop) + ) + (func $cant-push-past-try + (local $x i32) + (block $out + (local.set $x + (i32.const 1) + ) + (try + (do + (call $foo) + ) + (catch $e + (drop + (pop i32) + ) + ) + ) + (drop + (i32.const 1) + ) + (br_if $out + (i32.const 2) + ) + (drop + (local.get $x) + ) + ) + ) (func $cant-push-past-rethrow-within-catch (local $x i32) (block $out @@ -81,10 +111,8 @@ (i32.const 0) ) ) - (catch - (rethrow - (pop exnref) - ) + (catch_all + (rethrow 0) ) ) (drop diff --git a/test/passes/code-pushing_all-features.wast b/test/passes/code-pushing_all-features.wast index b67b98d7e..0d18afcc5 100644 --- a/test/passes/code-pushing_all-features.wast +++ b/test/passes/code-pushing_all-features.wast @@ -25,18 +25,39 @@ ) ) - (func $can-push-past-throw-within-try + (func $can-push-past-try (local $x i32) (block $out ;; This local.set can be pushed down, because the 'throw' below is going - ;; to be caught by the inner catch + ;; to be caught by the inner catch_all (local.set $x (i32.const 1)) (try (do (throw $e (i32.const 0)) ) - (catch - (drop (pop exnref)) + (catch_all + (drop (pop i32)) + ) + ) + (drop (i32.const 1)) + (br_if $out (i32.const 2)) + (drop (local.get $x)) + ) + ) + + (func $foo) + (func $cant-push-past-try + (local $x i32) + (block $out + ;; This local.set cannot be pushed down, because the exception thrown by + ;; 'call $foo' below may not be caught by 'catch $e' + (local.set $x (i32.const 1)) + (try + (do + (call $foo) + ) + (catch $e + (drop (pop i32)) ) ) (drop (i32.const 1)) @@ -49,14 +70,14 @@ (local $x i32) (block $out ;; This local.set cannot be pushed down, because there is 'rethrow' within - ;; the inner catch + ;; the inner catch_all (local.set $x (i32.const 1)) (try (do (throw $e (i32.const 0)) ) - (catch - (rethrow (pop exnref)) + (catch_all + (rethrow 0) ) ) (drop (i32.const 1)) diff --git a/test/passes/dce_all-features.txt b/test/passes/dce_all-features.txt index 4088d5a34..447077b6c 100644 --- a/test/passes/dce_all-features.txt +++ b/test/passes/dce_all-features.txt @@ -551,10 +551,8 @@ (do (unreachable) ) - (catch - (drop - (pop exnref) - ) + (catch_all + (nop) ) ) (call $foo) @@ -564,7 +562,7 @@ (do (nop) ) - (catch + (catch_all (unreachable) ) ) @@ -575,7 +573,7 @@ (do (unreachable) ) - (catch + (catch_all (unreachable) ) ) @@ -591,9 +589,7 @@ (func $rethrow (block $label$0 (block $label$1 - (rethrow - (ref.null exn) - ) + (rethrow 0) ) ) ) @@ -624,7 +620,7 @@ (do (unreachable) ) - (catch + (catch_all (unreachable) ) ) diff --git a/test/passes/dce_all-features.wast b/test/passes/dce_all-features.wast index 9ebcccb60..fac6d7623 100644 --- a/test/passes/dce_all-features.wast +++ b/test/passes/dce_all-features.wast @@ -746,11 +746,7 @@ (do (unreachable) ) - (catch - (drop - (pop exnref) - ) - ) + (catch_all) ) (call $foo) ;; shouldn't be dce'd ) @@ -758,7 +754,7 @@ (func $catch_unreachable (try (do) - (catch + (catch_all (unreachable) ) ) @@ -770,7 +766,7 @@ (do (unreachable) ) - (catch + (catch_all (unreachable) ) ) @@ -799,9 +795,7 @@ (if (i32.clz (block $label$1 (result i32) - (rethrow - (ref.null exn) - ) + (rethrow 0) ) ) (nop) @@ -835,7 +829,7 @@ (do (unreachable) ) - (catch + (catch_all (unreachable) ) ) diff --git a/test/passes/generate-stack-ir_optimize-stack-ir_print-stack-ir_all-features.txt b/test/passes/generate-stack-ir_optimize-stack-ir_print-stack-ir_all-features.txt index 28348883a..fb9e2907b 100644 --- a/test/passes/generate-stack-ir_optimize-stack-ir_print-stack-ir_all-features.txt +++ b/test/passes/generate-stack-ir_optimize-stack-ir_print-stack-ir_all-features.txt @@ -3,20 +3,15 @@ (type $i32_=>_none (func (param i32))) (event $e0 (attr 0) (param i32)) (func $eh - (local $exn exnref) try i32.const 0 throw $e0 catch - local.set $exn - block $l0 (result i32) - local.get $exn - br_on_exn $l0 $e0 - rethrow - end drop + rethrow 0 end + unreachable ) ) (module @@ -24,26 +19,17 @@ (type $i32_=>_none (func (param i32))) (event $e0 (attr 0) (param i32)) (func $eh (; has Stack IR ;) - (local $exn exnref) (try (do (throw $e0 (i32.const 0) ) ) - (catch - (local.set $exn - (pop exnref) - ) + (catch $e0 (drop - (block $l0 (result i32) - (rethrow - (br_on_exn $l0 $e0 - (local.get $exn) - ) - ) - ) + (pop i32) ) + (rethrow 0) ) ) ) diff --git a/test/passes/generate-stack-ir_optimize-stack-ir_print-stack-ir_all-features.wast b/test/passes/generate-stack-ir_optimize-stack-ir_print-stack-ir_all-features.wast index e2bbfff2d..7dbb4aa72 100644 --- a/test/passes/generate-stack-ir_optimize-stack-ir_print-stack-ir_all-features.wast +++ b/test/passes/generate-stack-ir_optimize-stack-ir_print-stack-ir_all-features.wast @@ -1,20 +1,14 @@ (module (event $e0 (attr 0) (param i32)) - (func $eh (local $exn exnref) + (func $eh (try (do (throw $e0 (i32.const 0)) ) - (catch - (local.set $exn (pop exnref)) - (drop - (block $l0 (result i32) - (rethrow - (br_on_exn $l0 $e0 (local.get $exn)) - ) - ) - ) + (catch $e0 + (drop (pop i32)) + (rethrow 0) ) ) ) diff --git a/test/passes/instrument-locals_all-features_disable-typed-function-references.txt b/test/passes/instrument-locals_all-features_disable-typed-function-references.txt index d027f54a0..5fc177d9d 100644 --- a/test/passes/instrument-locals_all-features_disable-typed-function-references.txt +++ b/test/passes/instrument-locals_all-features_disable-typed-function-references.txt @@ -11,6 +11,7 @@ (type $i32_i32_eqref_=>_eqref (func (param i32 i32 eqref) (result eqref))) (type $i32_i32_i31ref_=>_i31ref (func (param i32 i32 i31ref) (result i31ref))) (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) (import "env" "get_i32" (func $get_i32 (param i32 i32 i32) (result i32))) (import "env" "get_i64" (func $get_i64 (param i32 i32 i64) (result i64))) (import "env" "get_f32" (func $get_f32 (param i32 i32 f32) (result f32))) @@ -33,6 +34,7 @@ (import "env" "set_i31ref" (func $set_i31ref (param i32 i32 i31ref) (result i31ref))) (import "env" "get_v128" (func $get_v128 (param i32 i32 v128) (result v128))) (import "env" "set_v128" (func $set_v128 (param i32 i32 v128) (result v128))) + (event $e (attr 0) (param i32)) (func $test (local $x i32) (local $y i64) @@ -242,29 +244,9 @@ (do (nop) ) - (catch - (local.set $F - (pop funcref) - ) - ) - ) - (try - (do - (nop) - ) - (catch - (local.set $X - (pop externref) - ) - ) - ) - (try - (do - (nop) - ) - (catch - (local.set $E - (pop exnref) + (catch $e + (local.set $x + (pop i32) ) ) ) diff --git a/test/passes/instrument-locals_all-features_disable-typed-function-references.wast b/test/passes/instrument-locals_all-features_disable-typed-function-references.wast index c709630b5..53b2349fa 100644 --- a/test/passes/instrument-locals_all-features_disable-typed-function-references.wast +++ b/test/passes/instrument-locals_all-features_disable-typed-function-references.wast @@ -1,4 +1,6 @@ (module + (event $e (attr 0) (param i32)) + (func $test (local $x i32) (local $y i64) @@ -44,20 +46,8 @@ ;; Pop instructions should not be instrumented (try (do) - (catch - (local.set $F (pop funcref)) - ) - ) - (try - (do) - (catch - (local.set $X (pop externref)) - ) - ) - (try - (do) - (catch - (local.set $E (pop exnref)) + (catch $e + (local.set $x (pop i32)) ) ) diff --git a/test/passes/optimize-instructions_all-features.txt b/test/passes/optimize-instructions_all-features.txt index 5a2ede97a..df60ebfaa 100644 --- a/test/passes/optimize-instructions_all-features.txt +++ b/test/passes/optimize-instructions_all-features.txt @@ -5687,10 +5687,7 @@ (do (i32.const 123) ) - (catch - (drop - (pop exnref) - ) + (catch_all (i32.const 456) ) ) diff --git a/test/passes/optimize-instructions_all-features.wast b/test/passes/optimize-instructions_all-features.wast index d90dd7aeb..191189f70 100644 --- a/test/passes/optimize-instructions_all-features.wast +++ b/test/passes/optimize-instructions_all-features.wast @@ -6160,10 +6160,7 @@ ) ) ) - (catch - (drop - (pop exnref) - ) + (catch_all (i32.eqz (i32.eqz (i32.const 456) diff --git a/test/passes/remove-unused-module-elements_all-features.txt b/test/passes/remove-unused-module-elements_all-features.txt index 81382e4f4..0873cfee4 100644 --- a/test/passes/remove-unused-module-elements_all-features.txt +++ b/test/passes/remove-unused-module-elements_all-features.txt @@ -279,34 +279,23 @@ ) ) (module - (type $i32_=>_none (func (param i32))) (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) (type $i64_=>_none (func (param i64))) (event $e-export (attr 0) (param i64)) (event $e-throw (attr 0) (param i32)) - (event $e-bronexn (attr 0) (param i32)) (export "e-export" (event $e-export)) (start $start) (func $start - (local $exn exnref) (try (do (throw $e-throw (i32.const 0) ) ) - (catch - (local.set $exn - (pop exnref) - ) + (catch $e-catch (drop - (block $l0 (result i32) - (rethrow - (br_on_exn $l0 $e-bronexn - (local.get $exn) - ) - ) - ) + (pop i32) ) ) ) diff --git a/test/passes/remove-unused-module-elements_all-features.wast b/test/passes/remove-unused-module-elements_all-features.wast index bf9d5c7ff..c70dc1495 100644 --- a/test/passes/remove-unused-module-elements_all-features.wast +++ b/test/passes/remove-unused-module-elements_all-features.wast @@ -266,24 +266,17 @@ (event $e-remove (attr 0) (type $0)) ;; can be removed (event $e-export (attr 0) (param i64)) ;; cannot be removed (exported) (event $e-throw (attr 0) (type $0)) ;; cannot be removed (used in throw) - (event $e-bronexn (attr 0) (type $0)) ;; cannot be removed (used in br_on_exn) + (event $e-catch (attr 0) (type $0)) ;; cannot be removed (used in catch) (export "e-export" (event $e-export)) (import "env" "e" (event $e-import (attr 0) (param i32))) (start $start) - (func $start (local $exn exnref) (; 0 ;) + (func $start (try (do (throw $e-throw (i32.const 0)) ) - (catch - (local.set $exn (pop exnref)) - (drop - (block $l0 (result i32) - (rethrow - (br_on_exn $l0 $e-bronexn (local.get $exn)) - ) - ) - ) + (catch $e-catch + (drop (pop i32)) ) ) ) diff --git a/test/passes/remove-unused-names_code-folding_all-features.txt b/test/passes/remove-unused-names_code-folding_all-features.txt index 9736c3c0a..2f78a83e7 100644 --- a/test/passes/remove-unused-names_code-folding_all-features.txt +++ b/test/passes/remove-unused-names_code-folding_all-features.txt @@ -1,9 +1,10 @@ (module (type $none_=>_none (func)) (type $none_=>_i32 (func (result i32))) + (type $i32_=>_none (func (param i32))) (type $i32_=>_i32 (func (param i32) (result i32))) (type $i32_i32_=>_i32 (func (param i32 i32) (result i32))) - (type $none_=>_exnref (func (result exnref))) + (event $e-i32 (attr 0) (param i32)) (event $e (attr 0) (param)) (func $ifs (if @@ -1710,8 +1711,7 @@ (i32.const 2) ) ) - (func $exnref_pop-test - (local $exn exnref) + (func $pop-test (block $folding-inner0 (try (do @@ -1719,17 +1719,17 @@ (do (nop) ) - (catch - (local.set $exn - (pop exnref) + (catch $e-i32 + (drop + (pop i32) ) (br $folding-inner0) ) ) ) - (catch - (local.set $exn - (pop exnref) + (catch $e-i32 + (drop + (pop i32) ) (br $folding-inner0) ) @@ -1791,7 +1791,7 @@ (func $foo (nop) ) - (func $try-call-optimize-terminating-tails (result exnref) + (func $try-call-optimize-terminating-tails (result i32) (try (do (call $foo) @@ -1799,26 +1799,22 @@ (call $foo) (call $foo) (return - (ref.null exn) + (i32.const 0) ) ) - (catch - (drop - (pop exnref) - ) + (catch_all (call $foo) (call $foo) (call $foo) (call $foo) (return - (ref.null exn) + (i32.const 0) ) ) ) - (ref.null exn) + (i32.const 0) ) (func $try-call-optimize-expression-tails - (local $exn exnref) (block $x (try (do @@ -1827,10 +1823,7 @@ (call $foo) (br $x) ) - (catch - (local.set $exn - (pop exnref) - ) + (catch_all (call $foo) (call $foo) (call $foo) diff --git a/test/passes/remove-unused-names_code-folding_all-features.wast b/test/passes/remove-unused-names_code-folding_all-features.wast index 823ed45eb..387b8600b 100644 --- a/test/passes/remove-unused-names_code-folding_all-features.wast +++ b/test/passes/remove-unused-names_code-folding_all-features.wast @@ -1192,15 +1192,15 @@ ) ) - (func $exnref_pop-test (local $exn exnref) + (event $e-i32 (attr 0) (param i32)) + (func $pop-test (try (do (try (do) - (catch - ;; Expressions containing (pop exnref) should NOT be taken out and - ;; folded. - (local.set $exn (pop exnref)) + (catch $e-i32 + ;; Expressions containing a pop should NOT be taken out and folded. + (drop (pop i32)) (drop (i32.const 111)) (drop (i32.const 222)) (drop (i32.const 333)) @@ -1208,8 +1208,8 @@ ) ) ) - (catch - (local.set $exn (pop exnref)) + (catch $e-i32 + (drop (pop i32)) (drop (i32.const 111)) (drop (i32.const 222)) (drop (i32.const 333)) @@ -1246,7 +1246,7 @@ ) (func $foo) - (func $try-call-optimize-terminating-tails (result exnref) + (func $try-call-optimize-terminating-tails (result i32) (try (do ;; Expressions that can throw should NOT be taken out of 'try' scope. @@ -1254,21 +1254,20 @@ (call $foo) (call $foo) (call $foo) - (return (ref.null exn)) + (return (i32.const 0)) ) - (catch - (drop (pop exnref)) + (catch_all (call $foo) (call $foo) (call $foo) (call $foo) - (return (ref.null exn)) + (return (i32.const 0)) ) ) - (ref.null exn) + (i32.const 0) ) - (func $try-call-optimize-expression-tails (local $exn exnref) + (func $try-call-optimize-expression-tails (block $x (try (do @@ -1278,8 +1277,7 @@ (call $foo) (br $x) ) - (catch - (local.set $exn (pop exnref)) + (catch_all (call $foo) (call $foo) (call $foo) diff --git a/test/passes/remove-unused-names_merge-blocks_all-features.txt b/test/passes/remove-unused-names_merge-blocks_all-features.txt index 90a56d32d..46d45d3fe 100644 --- a/test/passes/remove-unused-names_merge-blocks_all-features.txt +++ b/test/passes/remove-unused-names_merge-blocks_all-features.txt @@ -1711,13 +1711,6 @@ (i32.const 3) ) ) - (func $rethrow - (local $0 exnref) - (call $foo) - (rethrow - (local.get $0) - ) - ) (func $br_on_exn (result i32) (local $0 exnref) (block $label$0 (result i32) diff --git a/test/passes/remove-unused-names_merge-blocks_all-features.wast b/test/passes/remove-unused-names_merge-blocks_all-features.wast index 9a6840650..6869db6ad 100644 --- a/test/passes/remove-unused-names_merge-blocks_all-features.wast +++ b/test/passes/remove-unused-names_merge-blocks_all-features.wast @@ -1571,16 +1571,6 @@ ) ) - ;; 'call $foo' within 'block' of `rethrow' can be hoisted - (func $rethrow (local $0 exnref) - (rethrow - (block (result exnref) - (call $foo) - (local.get $0) - ) - ) - ) - ;; 'call $foo' within 'block' of `br_on_exn' can be hoisted (func $br_on_exn (result i32) (local $0 exnref) (block $label$0 (result i32) diff --git a/test/passes/remove-unused-names_optimize-instructions_all-features.txt b/test/passes/remove-unused-names_optimize-instructions_all-features.txt index 8b7fc343b..cf1e44132 100644 --- a/test/passes/remove-unused-names_optimize-instructions_all-features.txt +++ b/test/passes/remove-unused-names_optimize-instructions_all-features.txt @@ -10,15 +10,13 @@ (local $x1 i32) (local $x2 i32) (local $x3 i32) + (local $x4 i32) (local.set $x0 (try (result i32) (do (i32.const 1) ) - (catch - (drop - (pop exnref) - ) + (catch_all (i32.const 3) ) ) @@ -32,10 +30,7 @@ (call $dummy) (i32.const 1) ) - (catch - (drop - (pop exnref) - ) + (catch_all (i32.const 3) ) ) @@ -55,36 +50,59 @@ (i32.const 0) ) ) - (catch + (catch $e (drop - (pop exnref) + (pop i32) ) ) ) (i32.const 1) ) - (catch + (catch $e (drop - (pop exnref) + (pop i32) ) (i32.const 3) ) ) ) (drop - (local.get $x2) + (i32.and + (local.get $x2) + (i32.const 7) + ) ) (local.set $x3 (try (result i32) (do (try (do + (throw $e + (i32.const 0) + ) + ) + (catch_all (nop) ) - (catch - (drop - (pop exnref) - ) + ) + (i32.const 1) + ) + (catch_all + (i32.const 3) + ) + ) + ) + (drop + (local.get $x3) + ) + (local.set $x4 + (try (result i32) + (do + (try + (do + (nop) + ) + (catch_all (throw $e (i32.const 0) ) @@ -92,17 +110,14 @@ ) (i32.const 1) ) - (catch - (drop - (pop exnref) - ) + (catch_all (i32.const 3) ) ) ) (drop (i32.and - (local.get $x3) + (local.get $x4) (i32.const 7) ) ) diff --git a/test/passes/remove-unused-names_optimize-instructions_all-features.wast b/test/passes/remove-unused-names_optimize-instructions_all-features.wast index 7c75c2bcf..e08c42169 100644 --- a/test/passes/remove-unused-names_optimize-instructions_all-features.wast +++ b/test/passes/remove-unused-names_optimize-instructions_all-features.wast @@ -7,6 +7,7 @@ (local $x1 i32) (local $x2 i32) (local $x3 i32) + (local $x4 i32) ;; try - try body does not throw, can (local.set $x0 @@ -14,8 +15,7 @@ (do (i32.const 1) ) - (catch - (drop (pop exnref)) + (catch_all (i32.const 3) ) ) @@ -29,15 +29,15 @@ (call $dummy) (i32.const 1) ) - (catch - (drop (pop exnref)) + (catch_all (i32.const 3) ) ) ) (drop (i32.and (local.get $x1) (i32.const 7))) - ;; nested try - inner try may throw but will be caught by inner catch, can + ;; nested try - inner try may throw and may not be caught by inner catch, + ;; can't (local.set $x2 (try (result i32) (do @@ -45,39 +45,57 @@ (do (throw $e (i32.const 0)) ) - (catch - (drop (pop exnref)) + (catch $e + (drop (pop i32)) ) ) (i32.const 1) ) - (catch - (drop (pop exnref)) + (catch $e + (drop (pop i32)) (i32.const 3) ) ) ) (drop (i32.and (local.get $x2) (i32.const 7))) - ;; nested try - inner catch may throw, can't + ;; nested try - inner try may throw but will be caught by inner catch_all, + ;; can (local.set $x3 (try (result i32) (do (try - (do) - (catch - (drop (pop exnref)) + (do (throw $e (i32.const 0)) ) + (catch_all) ) (i32.const 1) ) - (catch - (drop (pop exnref)) + (catch_all (i32.const 3) ) ) ) (drop (i32.and (local.get $x3) (i32.const 7))) + + ;; nested try - inner catch_all may throw, can't + (local.set $x4 + (try (result i32) + (do + (try + (do) + (catch_all + (throw $e (i32.const 0)) + ) + ) + (i32.const 1) + ) + (catch_all + (i32.const 3) + ) + ) + ) + (drop (i32.and (local.get $x4) (i32.const 7))) ) ) diff --git a/test/passes/rse_all-features.txt b/test/passes/rse_all-features.txt index 95773bb23..8ad883d9f 100644 --- a/test/passes/rse_all-features.txt +++ b/test/passes/rse_all-features.txt @@ -3,7 +3,6 @@ (type $i32_=>_none (func (param i32))) (type $i32_i32_=>_none (func (param i32 i32))) (type $i32_f64_=>_none (func (param i32 f64))) - (event $e (attr 0) (param i32)) (func $basic (param $x i32) (param $y f64) (local $a f32) (local $b i64) @@ -475,136 +474,4 @@ ) ) ) - (func $try1 - (local $x i32) - (try - (do - (nop) - ) - (catch - (drop - (pop exnref) - ) - (local.set $x - (i32.const 1) - ) - ) - ) - (local.set $x - (i32.const 1) - ) - ) - (func $try2 - (local $x i32) - (try - (do - (throw $e - (i32.const 0) - ) - (local.set $x - (i32.const 1) - ) - ) - (catch - (drop - (pop exnref) - ) - ) - ) - (local.set $x - (i32.const 1) - ) - ) - (func $try3 - (local $x i32) - (try - (do - (throw $e - (i32.const 0) - ) - ) - (catch - (drop - (pop exnref) - ) - (local.set $x - (i32.const 1) - ) - ) - ) - (drop - (i32.const 1) - ) - ) - (func $foo - (nop) - ) - (func $try4 - (local $x i32) - (try - (do - (call $foo) - (local.set $x - (i32.const 1) - ) - ) - (catch - (drop - (pop exnref) - ) - ) - ) - (local.set $x - (i32.const 1) - ) - ) - (func $try5 - (local $x i32) - (try - (do - (local.set $x - (i32.const 1) - ) - (call $foo) - ) - (catch - (drop - (pop exnref) - ) - ) - ) - (drop - (i32.const 1) - ) - ) - (func $nested-try - (local $x i32) - (try - (do - (try - (do - (throw $e - (i32.const 0) - ) - ) - (catch - (rethrow - (pop exnref) - ) - ) - ) - ) - (catch - (drop - (pop exnref) - ) - (local.set $x - (i32.const 1) - ) - ) - ) - (drop - (i32.const 1) - ) - ) ) diff --git a/test/passes/rse_all-features.wast b/test/passes/rse_all-features.wast index d77dae379..94470ef53 100644 --- a/test/passes/rse_all-features.wast +++ b/test/passes/rse_all-features.wast @@ -287,89 +287,90 @@ ) ) - (event $e (attr 0) (param i32)) - (func $try1 - (local $x i32) - (try - (do) - (catch - (drop (pop exnref)) - (local.set $x (i32.const 1)) - ) - ) - (local.set $x (i32.const 1)) ;; should NOT be dropped - ) - (func $try2 - (local $x i32) - (try - (do - (throw $e (i32.const 0)) - (local.set $x (i32.const 1)) - ) - (catch - (drop (pop exnref)) - ) - ) - (local.set $x (i32.const 1)) ;; should NOT be dropped - ) - (func $try3 - (local $x i32) - (try - (do - (throw $e (i32.const 0)) - ) - (catch - (drop (pop exnref)) - (local.set $x (i32.const 1)) - ) - ) - (local.set $x (i32.const 1)) ;; should be dropped - ) - (func $foo) - (func $try4 - (local $x i32) - (try - (do - (call $foo) - (local.set $x (i32.const 1)) - ) - (catch - (drop (pop exnref)) - ) - ) - (local.set $x (i32.const 1)) ;; should NOT be dropped - ) - (func $try5 - (local $x i32) - (try - (do - (local.set $x (i32.const 1)) - (call $foo) - ) - (catch - (drop (pop exnref)) - ) - ) - (local.set $x (i32.const 1)) ;; should be dropped - ) - (func $nested-try - (local $x i32) - (try - (do - (try - (do - (throw $e (i32.const 0)) - ) - (catch - (rethrow (pop exnref)) - ) - ) - ) - (catch - (drop (pop exnref)) - (local.set $x (i32.const 1)) - ) - ) - (local.set $x (i32.const 1)) ;; should be dropped - ) +;; FIXME Reenable these tests after fixing CFG traversal for EH +;; (event $e (attr 0) (param i32)) +;; (func $try1 +;; (local $x i32) +;; (try +;; (do) +;; (catch +;; (drop (pop exnref)) +;; (local.set $x (i32.const 1)) +;; ) +;; ) +;; (local.set $x (i32.const 1)) ;; should NOT be dropped +;; ) +;; (func $try2 +;; (local $x i32) +;; (try +;; (do +;; (throw $e (i32.const 0)) +;; (local.set $x (i32.const 1)) +;; ) +;; (catch +;; (drop (pop exnref)) +;; ) +;; ) +;; (local.set $x (i32.const 1)) ;; should NOT be dropped +;; ) +;; (func $try3 +;; (local $x i32) +;; (try +;; (do +;; (throw $e (i32.const 0)) +;; ) +;; (catch +;; (drop (pop exnref)) +;; (local.set $x (i32.const 1)) +;; ) +;; ) +;; (local.set $x (i32.const 1)) ;; should be dropped +;; ) +;; (func $foo) +;; (func $try4 +;; (local $x i32) +;; (try +;; (do +;; (call $foo) +;; (local.set $x (i32.const 1)) +;; ) +;; (catch +;; (drop (pop exnref)) +;; ) +;; ) +;; (local.set $x (i32.const 1)) ;; should NOT be dropped +;; ) +;; (func $try5 +;; (local $x i32) +;; (try +;; (do +;; (local.set $x (i32.const 1)) +;; (call $foo) +;; ) +;; (catch +;; (drop (pop exnref)) +;; ) +;; ) +;; (local.set $x (i32.const 1)) ;; should be dropped +;; ) +;; (func $nested-try +;; (local $x i32) +;; (try +;; (do +;; (try +;; (do +;; (throw $e (i32.const 0)) +;; ) +;; (catch +;; (rethrow (pop exnref)) +;; ) +;; ) +;; ) +;; (catch +;; (drop (pop exnref)) +;; (local.set $x (i32.const 1)) +;; ) +;; ) +;; (local.set $x (i32.const 1)) ;; should be dropped +;; ) ) diff --git a/test/passes/simplify-locals_all-features.txt b/test/passes/simplify-locals_all-features.txt index 8587e115c..2604ad88d 100644 --- a/test/passes/simplify-locals_all-features.txt +++ b/test/passes/simplify-locals_all-features.txt @@ -1896,12 +1896,14 @@ ) (module (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) (type $exnref_=>_none (func (param exnref))) - (type $i32_exnref_=>_none (func (param i32 exnref))) + (type $i32_i32_=>_none (func (param i32 i32))) (type $none_=>_i32 (func (result i32))) (type $none_=>_exnref (func (result exnref))) (event $event$0 (attr 0) (param)) (event $event$1 (attr 0) (param exnref)) + (event $e-i32 (attr 0) (param i32)) (func $unoptimizable-br_on_exn-block (result exnref) (local $0 exnref) (block $label$0 @@ -1923,36 +1925,18 @@ ) ) ) - (func $rethrow-trap - (local $0 i32) - (drop - (block $label$1 (result i32) - (try - (do - (rethrow - (ref.null exn) - ) - ) - (catch - (nop) - ) - ) - (i32.const 0) - ) - ) - ) - (func $foo (param $0 i32) (param $1 exnref) + (func $foo (param $0 i32) (param $1 i32) (nop) ) (func $pop-cannot-be-sinked - (local $0 exnref) + (local $0 i32) (try (do (nop) ) - (catch + (catch $e-i32 (local.set $0 - (pop exnref) + (pop i32) ) (call $foo (i32.const 3) @@ -1962,21 +1946,21 @@ ) ) (func $pop-within-catch-can-be-sinked - (local $0 exnref) + (local $0 i32) (try (do (nop) ) - (catch + (catch_all (nop) (call $foo (i32.const 3) - (try (result exnref) + (try (result i32) (do - (ref.null exn) + (i32.const 0) ) - (catch - (pop exnref) + (catch $e-i32 + (pop i32) ) ) ) @@ -1997,9 +1981,9 @@ (local.get $0) ) ) - (catch + (catch $e-i32 (drop - (pop exnref) + (pop i32) ) ) ) @@ -2013,9 +1997,9 @@ (i32.const 3) ) ) - (catch + (catch $e-i32 (drop - (pop exnref) + (pop i32) ) ) ) diff --git a/test/passes/simplify-locals_all-features.wast b/test/passes/simplify-locals_all-features.wast index 61150edc1..13ff13679 100644 --- a/test/passes/simplify-locals_all-features.wast +++ b/test/passes/simplify-locals_all-features.wast @@ -1698,29 +1698,15 @@ ) ) - (func $rethrow-trap (local $0 i32) - ;; This dead local.set cannot be replaced with a nop because rethrow can - ;; trap. - (local.set $0 - (block $label$1 (result i32) - (try - (do (rethrow (ref.null exn))) - (catch) - ) - (i32.const 0) - ) - ) - ) - - (func $foo (param i32 exnref)) - (func $pop-cannot-be-sinked (local $0 exnref) + (event $e-i32 (attr 0) (param i32)) + (func $foo (param i32 i32)) + (func $pop-cannot-be-sinked (local $0 i32) (try (do) - (catch - ;; This (local.set $0) of (pop exnref) cannot be sinked to - ;; (local.get $0) below, because pop exnref should follow right after - ;; 'catch'. - (local.set $0 (pop exnref)) + (catch $e-i32 + ;; This (local.set $0) of (pop i32) cannot be sunk to (local.get $0) + ;; below, because the pop should follow right after 'catch'. + (local.set $0 (pop i32)) (call $foo (i32.const 3) (local.get $0) @@ -1729,17 +1715,17 @@ ) ) - (func $pop-within-catch-can-be-sinked (local $0 exnref) + (func $pop-within-catch-can-be-sinked (local $0 i32) (try (do) - (catch + (catch_all ;; This whole 'try' body can be sinked to eliminate local.set / ;; local.get. Even though it contains a pop, it is enclosed within ;; try-catch, so it is OK. (local.set $0 - (try (result exnref) - (do (ref.null exn)) - (catch (pop exnref)) + (try (result i32) + (do (i32.const 0)) + (catch $e-i32 (pop i32)) ) ) (call $foo @@ -1761,8 +1747,8 @@ (do (drop (local.get $0)) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) ) ) ) @@ -1776,8 +1762,8 @@ (do (drop (local.get $0)) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) ) ) ) diff --git a/test/passes/vacuum_all-features.txt b/test/passes/vacuum_all-features.txt index 0b9d70ca4..82fb7e506 100644 --- a/test/passes/vacuum_all-features.txt +++ b/test/passes/vacuum_all-features.txt @@ -438,10 +438,11 @@ (type $none_=>_none (func)) (type $i32_=>_none (func (param i32))) (event $e (attr 0) (param i32)) + (event $e2 (attr 0) (param i32)) (func $try-test (nop) ) - (func $inner-try-test + (func $inner-try-catch_all-test (local $0 i32) (try (do @@ -449,16 +450,40 @@ (i32.const 0) ) ) - (catch - (drop - (pop exnref) - ) + (catch_all (local.set $0 (i32.const 1) ) ) ) ) + (func $inner-try-catch-test + (local $0 i32) + (try + (do + (try + (do + (throw $e2 + (i32.const 0) + ) + ) + (catch $e + (drop + (pop i32) + ) + (local.set $0 + (i32.const 1) + ) + ) + ) + ) + (catch $e + (drop + (pop i32) + ) + ) + ) + ) (func $br-in-catch (unreachable) ) diff --git a/test/passes/vacuum_all-features.wast b/test/passes/vacuum_all-features.wast index 9eb13b55f..94f952f5d 100644 --- a/test/passes/vacuum_all-features.wast +++ b/test/passes/vacuum_all-features.wast @@ -798,35 +798,56 @@ (module (event $e (attr 0) (param i32)) + (event $e2 (attr 0) (param i32)) ;; When try body does not throw, try-body can be replaced with the try body (func $try-test (try (do (drop (i32.const 0)) ) - (catch - (drop (pop exnref)) + (catch $e + (drop (pop i32)) ) ) ) - ;; The exception thrown in the inner try is caught by the inner catch, so the - ;; outer try body does not throw and the outer try-catch can be removed - (func $inner-try-test (local $0 i32) + ;; The exception thrown in the inner try is caught by the inner catch_all, so + ;; the outer try body does not throw and the outer try-catch can be removed + (func $inner-try-catch_all-test (local $0 i32) (try (do (try (do (throw $e (i32.const 0)) ) - (catch - (drop (pop exnref)) + (catch_all (local.set $0 (i32.const 1)) ) ) ) - (catch - (drop (pop exnref)) + (catch $e + (drop (pop i32)) + ) + ) + ) + + ;; The exception thrown in the inner try will not be caught by the inner + ;; catch, so the outer try-catch cannot be removed + (func $inner-try-catch-test (local $0 i32) + (try + (do + (try + (do + (throw $e2 (i32.const 0)) + ) + (catch $e + (drop (pop i32)) + (local.set $0 (i32.const 1)) + ) + ) + ) + (catch $e + (drop (pop i32)) ) ) ) @@ -840,8 +861,8 @@ (do (unreachable) ) - (catch - (drop (pop exnref)) + (catch $e + (drop (pop i32)) (br $label$1) ) ) diff --git a/test/reference-types.wast b/test/reference-types.wast index ddc3550c5..bd19aa5c5 100644 --- a/test/reference-types.wast +++ b/test/reference-types.wast @@ -38,6 +38,8 @@ (global $global_anyref4 (mut anyref) (ref.func $foo)) (global $global_anyref5 (mut anyref) (ref.null exn)) + (event $e-i32 (attr 0) (param i32)) + (func $test (local $local_externref externref) (local $local_funcref funcref) @@ -462,8 +464,8 @@ (do (local.get $local_externref) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) (ref.null extern) ) ) @@ -473,8 +475,8 @@ (do (ref.func $foo) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) (ref.null func) ) ) @@ -484,8 +486,9 @@ (do (ref.null exn) ) - (catch - (pop exnref) + (catch $e-i32 + (drop (pop i32)) + (ref.null exn) ) ) ) @@ -496,8 +499,8 @@ (do (local.get $local_externref) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) (ref.func $foo) ) ) @@ -507,8 +510,9 @@ (do (local.get $local_externref) ) - (catch - (pop exnref) + (catch $e-i32 + (drop (pop i32)) + (local.get $local_exnref) ) ) ) @@ -517,8 +521,8 @@ (do (ref.func $foo) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) (local.get $local_externref) ) ) @@ -528,8 +532,9 @@ (do (ref.func $foo) ) - (catch - (pop exnref) + (catch $e-i32 + (drop (pop i32)) + (local.get $local_exnref) ) ) ) @@ -538,8 +543,8 @@ (do (ref.null exn) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) (local.get $local_externref) ) ) @@ -549,8 +554,8 @@ (do (ref.null exn) ) - (catch - (drop (pop exnref)) + (catch $e-i32 + (drop (pop i32)) (ref.func $foo) ) ) diff --git a/test/reference-types.wast.from-wast b/test/reference-types.wast.from-wast index 6a4bfede6..9deee6a15 100644 --- a/test/reference-types.wast.from-wast +++ b/test/reference-types.wast.from-wast @@ -8,6 +8,7 @@ (type $none_=>_externref (func (result externref))) (type $none_=>_exnref (func (result exnref))) (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) (type $externref_=>_funcref (func (param externref) (result funcref))) (import "env" "import_global" (global $import_global externref)) (import "env" "import_func" (func $import_func (param externref) (result funcref))) @@ -22,6 +23,7 @@ (global $global_anyref3 (mut anyref) (ref.null func)) (global $global_anyref4 (mut anyref) (ref.func $foo)) (global $global_anyref5 (mut anyref) (ref.null exn)) + (event $e-i32 (attr 0) (param i32)) (export "export_func" (func $import_func)) (export "export_global" (global $import_global)) (func $take_externref (param $0 externref) @@ -700,9 +702,9 @@ (do (local.get $local_externref) ) - (catch + (catch $e-i32 (drop - (pop exnref) + (pop i32) ) (ref.null extern) ) @@ -713,9 +715,9 @@ (do (ref.func $foo) ) - (catch + (catch $e-i32 (drop - (pop exnref) + (pop i32) ) (ref.null func) ) @@ -726,8 +728,11 @@ (do (ref.null exn) ) - (catch - (pop exnref) + (catch $e-i32 + (drop + (pop i32) + ) + (ref.null exn) ) ) ) @@ -736,9 +741,9 @@ (do (local.get $local_externref) ) - (catch + (catch $e-i32 (drop - (pop exnref) + (pop i32) ) (ref.func $foo) ) @@ -749,8 +754,11 @@ (do (local.get $local_externref) ) - (catch - (pop exnref) + (catch $e-i32 + (drop + (pop i32) + ) + (local.get $local_exnref) ) ) ) @@ -759,9 +767,9 @@ (do (ref.func $foo) ) - (catch + (catch $e-i32 (drop - (pop exnref) + (pop i32) ) (local.get $local_externref) ) @@ -772,8 +780,11 @@ (do (ref.func $foo) ) - (catch - (pop exnref) + (catch $e-i32 + (drop + (pop i32) + ) + (local.get $local_exnref) ) ) ) @@ -782,9 +793,9 @@ (do (ref.null exn) ) - (catch + (catch $e-i32 (drop - (pop exnref) + (pop i32) ) (local.get $local_externref) ) @@ -795,9 +806,9 @@ (do (ref.null exn) ) - (catch + (catch $e-i32 (drop - (pop exnref) + (pop i32) ) (ref.func $foo) ) diff --git a/test/reference-types.wast.fromBinary b/test/reference-types.wast.fromBinary index a540048f9..50d403caf 100644 --- a/test/reference-types.wast.fromBinary +++ b/test/reference-types.wast.fromBinary @@ -8,6 +8,7 @@ (type $none_=>_externref (func (result externref))) (type $none_=>_exnref (func (result exnref))) (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) (type $externref_=>_funcref (func (param externref) (result funcref))) (import "env" "import_global" (global $import_global externref)) (import "env" "import_func" (func $import_func (param externref) (result funcref))) @@ -22,6 +23,7 @@ (global $global_anyref3 (mut anyref) (ref.null func)) (global $global_anyref4 (mut anyref) (ref.func $foo)) (global $global_anyref5 (mut anyref) (ref.null exn)) + (event $event$0 (attr 0) (param i32)) (export "export_func" (func $import_func)) (export "export_global" (global $import_global)) (func $take_externref (param $0 externref) @@ -700,9 +702,9 @@ (do (local.get $local_funcref) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (ref.null extern) ) @@ -713,9 +715,9 @@ (do (ref.func $foo) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (ref.null func) ) @@ -726,8 +728,11 @@ (do (ref.null exn) ) - (catch - (pop exnref) + (catch $event$0 + (drop + (pop i32) + ) + (ref.null exn) ) ) ) @@ -736,9 +741,9 @@ (do (local.get $local_funcref) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (ref.func $foo) ) @@ -749,8 +754,11 @@ (do (local.get $local_funcref) ) - (catch - (pop exnref) + (catch $event$0 + (drop + (pop i32) + ) + (local.get $local_exnref) ) ) ) @@ -759,9 +767,9 @@ (do (ref.func $foo) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (local.get $local_funcref) ) @@ -772,8 +780,11 @@ (do (ref.func $foo) ) - (catch - (pop exnref) + (catch $event$0 + (drop + (pop i32) + ) + (local.get $local_exnref) ) ) ) @@ -782,9 +793,9 @@ (do (ref.null exn) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (local.get $local_funcref) ) @@ -795,9 +806,9 @@ (do (ref.null exn) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (ref.func $foo) ) diff --git a/test/reference-types.wast.fromBinary.noDebugInfo b/test/reference-types.wast.fromBinary.noDebugInfo index 9baf18af5..d60129e01 100644 --- a/test/reference-types.wast.fromBinary.noDebugInfo +++ b/test/reference-types.wast.fromBinary.noDebugInfo @@ -8,6 +8,7 @@ (type $none_=>_externref (func (result externref))) (type $none_=>_exnref (func (result exnref))) (type $none_=>_none (func)) + (type $i32_=>_none (func (param i32))) (type $externref_=>_funcref (func (param externref) (result funcref))) (import "env" "import_global" (global $gimport$0 externref)) (import "env" "import_func" (func $fimport$0 (param externref) (result funcref))) @@ -22,6 +23,7 @@ (global $global$6 (mut anyref) (ref.null func)) (global $global$7 (mut anyref) (ref.func $4)) (global $global$8 (mut anyref) (ref.null exn)) + (event $event$0 (attr 0) (param i32)) (export "export_func" (func $fimport$0)) (export "export_global" (global $gimport$0)) (func $0 (param $0 externref) @@ -700,9 +702,9 @@ (do (local.get $1) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (ref.null extern) ) @@ -713,9 +715,9 @@ (do (ref.func $4) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (ref.null func) ) @@ -726,8 +728,11 @@ (do (ref.null exn) ) - (catch - (pop exnref) + (catch $event$0 + (drop + (pop i32) + ) + (ref.null exn) ) ) ) @@ -736,9 +741,9 @@ (do (local.get $1) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (ref.func $4) ) @@ -749,8 +754,11 @@ (do (local.get $1) ) - (catch - (pop exnref) + (catch $event$0 + (drop + (pop i32) + ) + (local.get $2) ) ) ) @@ -759,9 +767,9 @@ (do (ref.func $4) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (local.get $1) ) @@ -772,8 +780,11 @@ (do (ref.func $4) ) - (catch - (pop exnref) + (catch $event$0 + (drop + (pop i32) + ) + (local.get $2) ) ) ) @@ -782,9 +793,9 @@ (do (ref.null exn) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (local.get $1) ) @@ -795,9 +806,9 @@ (do (ref.null exn) ) - (catch + (catch $event$0 (drop - (pop exnref) + (pop i32) ) (ref.func $4) ) |