Skip to content
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

Merge wasm_of_ocaml #1724

Merged
merged 569 commits into from
Dec 4, 2024
Merged

Merge wasm_of_ocaml #1724

merged 569 commits into from
Dec 4, 2024

Conversation

OlivierNicole
Copy link
Contributor

@OlivierNicole OlivierNicole commented Oct 31, 2024

This aims to merge wasm_of_ocaml, currently hosted at https://github.com/ocaml-wasm/wasm_of_ocaml, back into this repo.

This is pending on Dune support ocaml/dune#11029. For now, Dune is pinned for the CI jobs.

vouillon and others added 30 commits September 3, 2024 16:43
* Support for dialogElement

* Added cancel and close events

---------

Co-authored-by: Hugo Heuzard <[email protected]>
* Compiler: fix free variable for classes
…ith OCaml libraries

Use: js_of_ocaml --toplevel --no-runtime runtime.js library.cma
Integrate "added 'ellipse' method to canvasRenderingContext2D" (ocsigen#1555)
@hhugo
Copy link
Member

hhugo commented Dec 4, 2024

@vouillon, I'm testing 9b964d9 in #1757

@hhugo
Copy link
Member

hhugo commented Dec 4, 2024

@vouillon, I'm testing 9b964d9 in #1757

I think you should cherry-pick cf96d62

compiler/lib/flow.ml Outdated Show resolved Hide resolved
runtime/wasm/runtime.js Outdated Show resolved Hide resolved
@hhugo hhugo merged commit 9cfbfc4 into ocsigen:master Dec 4, 2024
27 checks passed
@hhugo
Copy link
Member

hhugo commented Dec 4, 2024

Thanks for all the hard work

@dbuenzli
Copy link
Contributor

dbuenzli commented Dec 4, 2024

Bravo! Is there some high level docs on how to use the stuff ?

@vouillon
Copy link
Member

vouillon commented Dec 4, 2024

Bravo! Is there some high level docs on how to use the stuff ?

There is a short README_wasm_of_ocaml.md. But I still need to write some documentation...

@rickyvetter
Copy link
Contributor

Incredible! This is awesome.

@dbuenzli
Copy link
Contributor

dbuenzli commented Dec 4, 2024

There is a short README_wasm_of_ocaml.md.

This looks to good to be true :–) The browsers APIs can be used as is ?

However it is possible to make it work over the file:// protocol ? And what's the story with webworkers ?

I have a number crunching app (computing thousands of polygon intersections) that I distribute as a single double-clickable .html file. It would be interesting to see the gains there. However it uses extremely dirty tricks to make webworkers work out of a single js_of_ocaml compiled file with code paths differentiated in the main via Worker.ami.

@vouillon
Copy link
Member

vouillon commented Dec 4, 2024

The browsers APIs can be used as is ?

Right.

However it is possible to make it work over the file:// protocol ?

Not at the moment. Source Phase Imports might make it possible at some point. Or maybe we could have an option to somehow embed the Wasm code in the JavaScript code.

And what's the story with webworkers ?

I'm not sure. What problem could there be?

I have a number crunching app (computing thousands of polygon intersections) that I distribute as a single double-clickable .html file. It would be interesting to see the gains there. However it uses extremely dirty tricks to make webworkers work out of a single js_of_ocaml compiled file with code paths differentiated in the main via Worker.ami.

This might just work if we embed the Wasm code.

@dbuenzli
Copy link
Contributor

dbuenzli commented Dec 4, 2024

I'm not sure. What problem could there be?

I'm concerned about data transfers. With webworkers you are supposed to transfer JavaScript values that that go through the structured clone algorithm.

As we once discussed that worked relatively flawlessly with js_of_ocaml's encoding of OCaml values encoded as JavaScript values.

Now I don't know how OCaml values are represented in wasm_of_ocaml, but in the webworker work queue I linked to I'm basically using Obj.magic on OCaml values to transfer work items but if those are no longer represented as JavaScript values then I expect kaboom.

@vouillon
Copy link
Member

vouillon commented Dec 5, 2024

OCaml values are represented using Wasm GC values, so indeed the structured clone algorithm will not work on them. You have to serialize them somehow. You can try Marshal which works much better than with Js_of_ocaml (integers and floats do not share the same representation).

I have some experimental code to embed the Wasm code within the JavaScript code. Maybe you could give it a try.

@micahcantor
Copy link
Contributor

Congrats @vouillon @OlivierNicole @hhugo 🎉 !

Leonidas-from-XIV added a commit to Leonidas-from-XIV/dune that referenced this pull request Dec 5, 2024
The attempts to update the workflow as Wasm_of_ocaml has been merged
upstream in ocsigen/js_of_ocaml#1724 and the
wasm-dune branch is gone.

Signed-off-by: Marek Kubica <[email protected]>
Leonidas-from-XIV added a commit to ocaml/dune that referenced this pull request Dec 6, 2024
The attempts to update the workflow as Wasm_of_ocaml has been merged
upstream in ocsigen/js_of_ocaml#1724 and the
wasm-dune branch is gone.

Signed-off-by: Marek Kubica <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.