Skip to content

Try to run the tests with jsc #1991

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 35 additions & 19 deletions .github/workflows/build-wasm_of_ocaml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
os:
- ubuntu-latest
ocaml-compiler:
- "4.14"
- "5.0"
- "5.1"
# - "4.14"
# - "5.0"
# - "5.1"
- "5.3"
separate_compilation:
- true
Expand All @@ -33,21 +33,21 @@ jobs:
separate_compilation: true
jane_street_tests: false
all_jane_street_tests: false
- os: windows-latest
ocaml-compiler: "5.2"
separate_compilation: true
jane_street_tests: true
all_jane_street_tests: true
- os: ubuntu-latest
ocaml-compiler: "5.2"
separate_compilation: true
jane_street_tests: true
all_jane_street_tests: true
- os: ubuntu-latest
ocaml-compiler: "5.2"
separate_compilation: false
jane_street_tests: true
all_jane_street_tests: false
# - os: windows-latest
# ocaml-compiler: "5.2"
# separate_compilation: true
# jane_street_tests: true
# all_jane_street_tests: true
# - os: ubuntu-latest
# ocaml-compiler: "5.2"
# separate_compilation: true
# jane_street_tests: true
# all_jane_street_tests: true
# - os: ubuntu-latest
# ocaml-compiler: "5.2"
# separate_compilation: false
# jane_street_tests: true
# all_jane_street_tests: false

runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -77,6 +77,20 @@ jobs:
with:
node-version: latest

- name: Install jsvu
run: npm install jsvu -g

- name: Install jsc
run: |
jsvu --os=default --engines=javascriptcore
echo $HOME/.jsvu/bin >> $GITHUB_PATH

- name: Test jsc
run: |
ls $HOME/.jsvu
ls $HOME/.jsvu/bin
jsc -e 'print("test")'

- name: Set-up OCaml ${{ matrix.ocaml-compiler }}
uses: ocaml/setup-ocaml@v3
with:
Expand Down Expand Up @@ -131,7 +145,9 @@ jobs:
- name: Run tests
if: ${{ matrix.separate_compilation }}
working-directory: ./wasm_of_ocaml
run: opam exec -- dune build @runtest-wasm
env:
WASM_ENGINE: jsc
run: opam exec -- dune build @runtest-wasm --profile release

# we continue-on-error on windows because we seem to often hit
# an internal assert inside libuv.
Expand Down
4 changes: 2 additions & 2 deletions runtime/wasm/jsstring.wat
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
(func $compare_strings (param externref externref) (result i32)))
(import "wasm:js-string" "test"
(func $is_string (param externref) (result i32)))
(import "wasm:js-string" "hash"
(func $hash_string (param i32) (param anyref) (result i32)))
(import "wasm:js-string" "fromCharCodeArray"
(func $fromCharCodeArray
(param (ref null $wstring)) (param i32) (param i32)
Expand All @@ -35,6 +33,8 @@
(func $encodeStringToUTF8Array
(param externref) (result (ref $bytes))))

(import "bindings" "hash_string"
(func $hash_string (param i32) (param anyref) (result i32)))
(import "bindings" "read_string"
(func $read_string (param i32) (result anyref)))
(import "bindings" "read_string_stream"
Expand Down
39 changes: 30 additions & 9 deletions runtime/wasm/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
const { link, src, generated } = args;

const isNode = globalThis.process?.versions?.node;
const isShell = !globalThis.TextDecoder;

const math = {
cos: Math.cos,
Expand Down Expand Up @@ -127,8 +128,8 @@
return WebAssembly?.promising && f ? WebAssembly.promising(f) : f;
}

const decoder = new TextDecoder("utf-8", { ignoreBOM: 1 });
const encoder = new TextEncoder();
const decoder = isShell || new TextDecoder("utf-8", { ignoreBOM: 1 });
const encoder = isShell || new TextEncoder();

function hash_int(h, d) {
d = Math.imul(d, 0xcc9e2d51 | 0);
Expand Down Expand Up @@ -219,11 +220,21 @@
array_length: (a) => a.length,
array_get: (a, i) => a[i],
array_set: (a, i, v) => (a[i] = v),
read_string: (l) => decoder.decode(new Uint8Array(buffer, 0, l)),
read_string: (l) =>
isShell
? decodeURIComponent(
escape(String.fromCharCode(...new Uint8Array(buffer, 0, l))),
)
: decoder.decode(new Uint8Array(buffer, 0, l)),
read_string_stream: (l, stream) =>
decoder.decode(new Uint8Array(buffer, 0, l), { stream }),
append_string: (s1, s2) => s1 + s2,
write_string: (s) => {
if (isShell) {
s = unescape(encodeURIComponent(s));
for (let i = 0; i < s.length; ++i) out_buffer[i] = s.charCodeAt(i);
return s.length;
}
var start = 0,
len = s.length;
for (;;) {
Expand Down Expand Up @@ -458,8 +469,14 @@
write: (fd, b, o, l, p) =>
fs
? fs.writeSync(fd, b, o, l, p === null ? p : Number(p))
: (console[fd === 2 ? "error" : "log"](
typeof b === "string" ? b : decoder.decode(b.slice(o, o + l)),
: ((isShell ? globalThis.print : console[fd === 2 ? "error" : "log"])(
typeof b === "string"
? b
: isShell
? decodeURIComponent(
escape(String.fromCharCode(...b.slice(o, o + l))),
)
: decoder.decode(b.slice(o, o + l)),
),
l),
read: (fd, b, o, l, p) => fs.readSync(fd, b, o, l, p),
Expand Down Expand Up @@ -504,7 +521,7 @@
fstat: (fd, l) => alloc_stat(fs.fstatSync(fd), l),
chmod: (p, perms) => fs.chmodSync(p, perms),
fchmod: (p, perms) => fs.fchmodSync(p, perms),
file_exists: (p) => +fs.existsSync(p),
file_exists: (p) => (isShell ? 0 : +fs.existsSync(p)),
is_directory: (p) => +fs.lstatSync(p).isDirectory(),
is_file: (p) => +fs.lstatSync(p).isFile(),
utimes: (p, a, m) => fs.utimesSync(p, a, m),
Expand Down Expand Up @@ -552,12 +569,12 @@
},
map_set: (m, x, v) => m.set(x, v),
map_delete: (m, x) => m.delete(x),
hash_string,
log: (x) => console.log(x),
};
const string_ops = {
test: (v) => +(typeof v === "string"),
compare: (s1, s2) => (s1 < s2 ? -1 : +(s1 > s2)),
hash: hash_string,
decodeStringFromUTF8Array: () => "",
encodeStringToUTF8Array: () => 0,
fromCharCodeArray: () => "",
Expand Down Expand Up @@ -586,9 +603,13 @@
const url = fetchBase ? new URL(src, fetchBase) : src;
return fetch(url);
}
const loadCode = isNode ? loadRelative : fetchRelative;
const loadCode = isNode
? loadRelative
: isShell
? (s) => globalThis.read(s, "binary")
: fetchRelative;
async function instantiateModule(code) {
return isNode
return isNode || isShell
? WebAssembly.instantiate(await code, imports, options)
: WebAssembly.instantiateStreaming(code, imports, options);
}
Expand Down
1 change: 1 addition & 0 deletions tools/ci_setup.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ let node_wrapper =
(name node_wrapper)
(libraries unix))|} )
; "node_wrapper/node_wrapper_per_profile.ml", {|let args = []|}
; "node_wrapper/node_wrapper_per_engine.ml", {|let engine = "node"|}
; "node_wrapper/dune-project", "(lang dune 3.17)"
; "node_wrapper/node_wrapper.opam", ""
]
Expand Down
11 changes: 10 additions & 1 deletion tools/dune
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
(executable
(name node_wrapper)
(modules node_wrapper)
(link_deps
(env_var WASM_ENGINE))
(modules node_wrapper node_wrapper_per_engine)
(libraries unix))

(rule
(target node_wrapper_per_engine.ml)
(action
(with-stdout-to
%{target}
(run echo "let engine = \"%{env:WASM_ENGINE=node}\""))))

(executable
(name ci_setup)
(modules ci_setup)
Expand Down
47 changes: 40 additions & 7 deletions tools/node_wrapper.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
let wizard_args =
[ "-ext:stack-switching"; "-ext:legacy-eh"; "-stack-size=2M"; "--dir=."; "--dir=/tmp" ]

let wasmtime_args =
[ (* "-C"; "collector=null"; *) "-W=all-proposals=y"; "--dir=."; "--dir=/tmp" ]

let wasmedge_args =
[ "--enable-gc"
; "--enable-exception-handling"
; "--enable-tail-call"
; "--dir=."
; "--dir=/tmp"
]

let extra_args_for_wasoo =
[ "--experimental-wasm-imported-strings"
; "--experimental-wasm-stack-switching"
; "--experimental-wasm-exnref"
; "--stack-size=10000"
]

Expand All @@ -23,16 +38,34 @@ let env =
else e)
env

let args =
let environment_args () =
List.filter
(fun e -> not (String.contains e ','))
(Array.to_list (Array.map (fun e -> "--env=" ^ e) env))

let wasm_file file =
Filename.concat (Filename.chop_extension file ^ ".assets") "code.wasm"

let common_args file argv = environment_args () @ (wasm_file file :: List.tl argv)

let exe, args =
match Array.to_list Sys.argv with
| exe :: argv ->
let argv =
let exe', argv =
match argv with
| file :: _ when Filename.check_suffix file ".wasm.js" ->
extra_args_for_wasoo @ argv
| _ -> extra_args_for_jsoo @ argv
| file :: _ when Filename.check_suffix file ".wasm.js" -> (
match Node_wrapper_per_engine.engine with
| "wizard" -> "wizeng.x86-linux", wizard_args @ common_args file argv
| "wizard-fast" -> "wizeng.x86-64-linux", wizard_args @ common_args file argv
| "wasmtime" -> "wasmtime", wasmtime_args @ common_args file argv
| "wasmedge" -> "wasmedge", wasmedge_args @ common_args file argv
| "jsc" -> "jsc", argv
| "d8" -> "d8", argv
| "sm" -> "sm", argv
| _ -> "node", extra_args_for_wasoo @ argv)
| _ -> "node", extra_args_for_jsoo @ argv
in
Array.of_list (exe :: argv)
exe', Array.of_list (exe :: argv)
| [] -> assert false

let () =
Expand All @@ -45,4 +78,4 @@ let () =
| _, WEXITED n -> exit n
| _, WSIGNALED _ -> exit 9
| _, WSTOPPED _ -> exit 9
else Unix.execvpe "node" args env
else Unix.execvpe exe args env
Loading