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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

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/config.mli 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/eval.ml Outdated Show resolved Hide resolved
| "caml_int_of_float", [ Float f ] -> Some (Int (Int32.of_float f))
| "caml_int_of_float", [ Float f ] ->
Some
(Int (Int32.of_float f |> Int.of_int32_warning_on_overflow |> Int.to_int32))
| "to_int", [ Float f ] -> Some (Int (Int32.of_float f))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Int32 -> Int ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Int constructor takes an int32, to be able to hold both JavaScript 32-bit integers and Wasm int31s

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

I just pushed a commit that fixes Flow.constant_identical with with Wasm backend.

compiler/lib/config.ml Outdated Show resolved Hide resolved
compiler/lib/config.ml Outdated Show resolved Hide resolved
@OlivierNicole OlivierNicole force-pushed the converge-jsoo-tip-07 branch 4 times, most recently from 05e6198 to b32eb93 Compare September 22, 2024 09:38
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