Skip to content

Commit

Permalink
do not use exception runtime when using multi-return, fix segfault in
Browse files Browse the repository at this point in the history
node by setting stack size and ulimit correctly
  • Loading branch information
zapashcanon committed Oct 17, 2024
1 parent 4d446c5 commit c222176
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
1 change: 1 addition & 0 deletions wasm/emit_wat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions wasm/link_wat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions wasm/runtime.wat
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
(type $Array (sub (array (mut (ref eq)))))
(type $FloatArray (sub (array (mut f64))))
(type $Gen_block (sub (array (mut (ref eq)))))
(import "exn_tag" "exc" (tag $exc (param (ref eq))))
;; TODO: re-enable exception
;;(import "exn_tag" "exc" (tag $exc (param (ref eq))))

;; ==========
;; Exceptions
Expand Down Expand Up @@ -216,11 +217,15 @@
(ref.cast (ref $String) (local.get $arr))
(local.get $field))))
(else
(throw $exc
unreachable
;; TODO: re-enable exception
(;(throw $exc
(array.new_fixed $Gen_block 3
(ref.i31 (i32.const 0))
(global.get $invalid_argument)
(global.get $index_out_of_bound_string)))))
(global.get $index_out_of_bound_string)))
;)
))
)

(func $string_eq (param $a (ref $String)) (param $b (ref $String)) (result i32)
Expand Down
8 changes: 6 additions & 2 deletions wasm/test/test_node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand Down
5 changes: 4 additions & 1 deletion wasm/wat.ml
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,10 @@ module C = struct
(node "tag" [ !$"exc"; node "param" [ node "ref" [ atom "eq" ] ] ])

let module_ m =
let m = import_tag :: m in
let m = match Wstate.exception_repr with
| Native_exceptions -> import_tag :: m
| Multi_return -> m
in
nodev "module" m

end

0 comments on commit c222176

Please sign in to comment.