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

Target-specific code #1655

Merged
merged 33 commits into from
Sep 27, 2024
Merged

Target-specific code #1655

merged 33 commits into from
Sep 27, 2024

Conversation

OlivierNicole
Copy link
Contributor

@OlivierNicole OlivierNicole commented Jul 30, 2024

Note: This PR depends on #1649 and #1654 and is based on top of them. The proposed feature is contained only in the last commit. edit: These PRs have been merged.

This PR contains @vouillon's work to have two distinct targets: Javascript and WebAssembly.

Dune support for the new Wasm backend has been proposed at ocaml/dune#10695.

This is part of a series of PRs intending to reduce the diff between js_of_ocaml and wasm_of_ocaml (see ocaml-wasm/wasm_of_ocaml#47).

@hhugo
Copy link
Member

hhugo commented Jul 30, 2024

Turning into a draft until underlying PRs are merged

@hhugo
Copy link
Member

hhugo commented Aug 30, 2024

@OlivierNicole, can you rebase, fix and undraft this PR

@OlivierNicole
Copy link
Contributor Author

@OlivierNicole, can you rebase, fix and undraft this PR

Done.

compiler/lib/eval.ml Outdated Show resolved Hide resolved
compiler/lib/eval.ml Outdated Show resolved Hide resolved
compiler/lib/eval.ml Outdated Show resolved Hide resolved
compiler/lib/linker.ml Outdated Show resolved Hide resolved
@hhugo
Copy link
Member

hhugo commented Sep 4, 2024

Do we really need to pass target around ? It creates a lot of noise for few uses only. It could be turned into an global config like use_js_string or effect. Alternatively, we could move all configs into a single config value and pass it around explicitly.

@OlivierNicole
Copy link
Contributor Author

What I like about passing target around is that it makes it explicit in the type of functions that they depend on the target, and which backends they support.

The readability does not seem too much impaired to me, but it’s not a strong opinion, if there’s opposition to it I’m OK with a global config parameter, since it’s not a value that is expected to change during a run.

@hhugo
Copy link
Member

hhugo commented Sep 9, 2024

Looking at the diff, I find it hard to extract where the behavior depend on the target because there are so many targets passed around. I like that values are explicitly passed but I don't see a reason to treat backends differently from other "config" (e.g. use_js_string).

  • I would use a global to flag for now, making the diff much smaller.
  • We could revisit the global state logic later and try to pass some config around.

@TyOverby
Copy link
Collaborator

Wouldn’t a global flag make it harder to use the jsoo compiler as a library, which could be invoked many times with different targets?

@TyOverby
Copy link
Collaborator

TyOverby commented Sep 10, 2024

For example, an online ocaml repl, or a “godbolt explorer” output visualizer

@hhugo
Copy link
Member

hhugo commented Sep 10, 2024

Wouldn’t a global flag make it harder to use the jsoo compiler as a library, which could be invoked many times with different targets?

Sure, but we already have that issue with other flags, in particular, effects.

compiler/lib/eval.ml Outdated Show resolved Hide resolved
compiler/lib/eval.ml Outdated Show resolved Hide resolved
@OlivierNicole
Copy link
Contributor Author

  • I would use a global to flag for now, making the diff much smaller.

Done.

@hhugo
Copy link
Member

hhugo commented Sep 13, 2024

@OlivierNicole, the CI is unhappy, and the diff has extra lines because of formatting. Can you run dune fmt ?

@OlivierNicole OlivierNicole force-pushed the converge-jsoo-tip-07 branch 3 times, most recently from 0a92618 to 5a9d1d2 Compare September 13, 2024 18:44
@OlivierNicole
Copy link
Contributor Author

There was a subtyping relation not being automatically used under 4.12. The CI should be happy now.

compiler/lib/stdlib.ml Outdated Show resolved Hide resolved
@hhugo
Copy link
Member

hhugo commented Sep 26, 2024

What's the semantics of nativeInt with the wasm backend?

@OlivierNicole
Copy link
Contributor Author

They’re on 32 bits.

@hhugo
Copy link
Member

hhugo commented Sep 26, 2024

Then we should use | NativeInt of Int32.t

@OlivierNicole
Copy link
Contributor Author

OlivierNicole commented Sep 27, 2024

Done. (Edit: and well spotted!)

@hhugo
Copy link
Member

hhugo commented Sep 27, 2024

@OlivierNicole, @vouillon, I'm tempted to introduce a dedicated type & module for target int. What do you think ?
See #1693

@OlivierNicole
Copy link
Contributor Author

Is the idea to have Targetint.t be an int31 in Wasm and int32 in JavaScript?

Sure, it sounds better, but IMO this looks like an improvement over the present PR that could be merged separately.

@hhugo hhugo merged commit 6226949 into ocsigen:master Sep 27, 2024
18 checks passed
@vouillon
Copy link
Member

That's a good idea, indeed.

@hhugo
Copy link
Member

hhugo commented Sep 27, 2024

@OlivierNicole @vouillon I've rebased and adapted #1693.

@OlivierNicole OlivierNicole deleted the converge-jsoo-tip-07 branch September 27, 2024 15:23
@OlivierNicole
Copy link
Contributor Author

Thank you for the exceptional review work.

@hhugo
Copy link
Member

hhugo commented Sep 27, 2024

@OlivierNicole, what's the next step for ocaml-wasm/wasm_of_ocaml#47

ejgallego added a commit to ejgallego/js_of_ocaml that referenced this pull request Sep 28, 2024
Regression from ocsigen#1655 .

Not sure if `Config.target` should be better handled as a parameter?
@OlivierNicole
Copy link
Contributor Author

I am in the process of merging the JSOO master into WSOO cleanly. Once that is done, my hope is to merge WSOO main into this repo as soon as possible, to avoid a new divergence and the amount of work involved in resorbing it. But that last step is blocked on ocaml/dune#10695.

hhugo pushed a commit that referenced this pull request Sep 30, 2024
Regression from #1655 .

Not sure if `Config.target` should be better handled as a parameter?
OlivierNicole added a commit to OlivierNicole/wasm_of_ocaml that referenced this pull request Oct 1, 2024
This is the wasm_of_ocaml-side adaptations after
ocsigen/js_of_ocaml#1655.
vouillon added a commit to ocaml-wasm/wasm_of_ocaml that referenced this pull request Oct 2, 2024
vouillon added a commit that referenced this pull request Oct 29, 2024
Co-authored-by: Olivier Nicole <[email protected]>
Co-authored-by: Jérôme Vouillon <[email protected]>
Co-authored-by: Hugo Heuzard <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants