From 7bb6b4c377226fab91a7abbd6895151a95eb5932 Mon Sep 17 00:00:00 2001 From: zapashcanon Date: Thu, 17 Oct 2024 18:25:03 +0200 Subject: [PATCH] do not use exception runtime when using multi-return, fix segfault in node by setting stack size and ulimit correctly --- wasm/emit_wat.ml | 1 + wasm/link_wat.ml | 10 +++++++--- wasm/test/test_node.sh | 8 ++++++-- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/wasm/emit_wat.ml b/wasm/emit_wat.ml index a27ca4b0f..6f19062b7 100644 --- a/wasm/emit_wat.ml +++ b/wasm/emit_wat.ml @@ -492,6 +492,7 @@ module Conv = struct match e with | Var _ | I32 _ | I64 _ | F64 _ | Global_get _ -> true | Unop (I31_new, e) -> expr_is_pure e + | Let2 { defining_expr; body; _ } | Let { defining_expr; body } -> expr_is_pure defining_expr && expr_is_pure body | _ -> false diff --git a/wasm/link_wat.ml b/wasm/link_wat.ml index 7c319e277..ea7fc7e7a 100644 --- a/wasm/link_wat.ml +++ b/wasm/link_wat.ml @@ -29,13 +29,17 @@ let options = [ "--enable-multivalue" ; "--enable-gc" ; "--enable-reference-types" - ; "--enable-exception-handling" ; "--enable-tail-call" - ] + ] @ match Wstate.exception_repr with + | Native_exceptions -> [ "--enable-exception-handling" ] + | Multi_return -> [] let wasm_merge = "wasm-merge" -let runtime = [ "exn_tag"; "runtime"; "imports" ] +let runtime = [ "runtime"; "imports" ] + @ match Wstate.exception_repr with + | Native_exceptions -> [ "exn_tag" ] + | Multi_return -> [] let merge_files ~runtime_dir ~text files output = let text = if text then [ emit_text ] else [] in diff --git a/wasm/test/test_node.sh b/wasm/test/test_node.sh index 9651b305a..b3ae5323e 100755 --- a/wasm/test/test_node.sh +++ b/wasm/test/test_node.sh @@ -4,14 +4,18 @@ set -eu alias time='/usr/bin/time -f"real %e user %U sys %S"' -NODE='node-canary --stack-size=10000' +ULIMIT_STACK_SIZE=20000 +STACK_SIZE=10000 +NODE="node-canary --stack-size=${STACK_SIZE}" + +ulimit -s $ULIMIT_STACK_SIZE bench() { echo "*** Running ${1}" echo -n "Wasocaml (node): " ../../ocamlopt -O3 ./${2}.ml > /dev/null time $NODE ./main_node.mjs > /dev/null - wasm-opt --enable-gc --enable-reference-types --enable-exception-handling --enable-multivalue --enable-tail-call a.out.wasm -o a.out.wasm -O3 + wasm-opt --enable-gc --enable-reference-types --enable-multivalue --enable-tail-call a.out.wasm -o a.out.wasm -O3 echo -n "Wasocaml + wasm-opt (node): " time $NODE ./main_node.mjs > /dev/null echo -n "OCaml native: "