js_of_ocaml icon indicating copy to clipboard operation
js_of_ocaml copied to clipboard

[BUG] Uncaught TypeError: runtime.caml_thread_initialize is not a function

Open toots opened this issue 1 year ago • 1 comments

We're seeing this error when switching our code to use effects.

Some screenshots:

Screenshot 2024-02-24 at 7 15 56 PM Screenshot 2024-02-24 at 7 16 07 PM

Here's a link to the compiled file: https://www.dropbox.com/scl/fi/9l8hcrlhk73ue9lx5hys6/interactive_with_effects_js.bc.js?rlkey=58xnqq9hxvnoh76uh0x7k4qjx&dl=0

toots avatar Feb 25 '24 01:02 toots

Looking at your CI building the js file, I see

(cd _build/default/src/js && /home/opam/.opam/4.14.1/bin/js_of_ocaml -o interactive_js.bc.js filesystem.js interactive_js.bc-for-jsoo)
Warning: your program contains effect handlers; you should probably run js_of_ocaml with option '--enable=effects'
There are some missing primitives
Dummy implementations (raising 'Failure' exception) will be used if they are not available at runtime.
You can prevent the generation of dummy implementations with the commandline option '--disable genprim'
Missing primitives:
  caml_thread_initialize

which indicate you're using ocaml 4.14.1.

Looking at the diff in the PR, I see you're adding a dependency on saturn_lockfree, which depends on threads.posix for ocaml < 5. (see https://github.com/ocaml-multicore/saturn/blob/main/src_lockfree/dune). threads.posix is not supported by jsoo.

hhugo avatar Feb 25 '24 08:02 hhugo

The "4.14.1" path fragment was misleading. I can see the compiler is upgraded to 5.1.1 before. Looking again, saturn_lockfree depends on domain_shims which unconditionally depends on threads (see https://gitlab.com/gasche/domain-shims/-/blob/trunk/lib/dune?ref_type=heads). I think we should somehow remove the threads dep from domain_shims on ocaml5. (cc @gasche)

hhugo avatar Feb 25 '24 14:02 hhugo

Great catch on the threads hard dep, thanks. That fixes it. I'll follow-up there.

toots avatar Feb 25 '24 17:02 toots