ocsigen / js_of_ocaml

Compiler from OCaml to Javascript.
http://ocsigen.org/js_of_ocaml/
Other
960 stars 188 forks source link

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

Closed toots closed 8 months ago

toots commented 8 months ago

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

hhugo commented 8 months ago

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 commented 8 months ago

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)

toots commented 8 months ago

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