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

Adapt JSOO rules for new --effects= option #11222

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

OlivierNicole
Copy link

This takes into account the new js_of_ocaml --effects={cps,double-translation} flag, introduced in ocsigen/js_of_ocaml#1461.

List.filter_opt
[ (match t.toplevel with Some true -> Some "--toplevel" | _ -> None)
; (match t.effects with
| Some backend -> Some ("--effects=" ^ string_of_effects backend) | None -> None)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we need to remember if effect was set with --enable effects and use the same flag here otherwise we loose backward compatibility.

Copy link
Member

Choose a reason for hiding this comment

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

I would select the flags based on jsoo version:

let to_flag ~recent =
  [...]
       | Some backend ->
           Some (if recent then "--effects=" ^ string_of_effects backend else "--enable=effects")
       | None -> None)
  [...]

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@OlivierNicole
Copy link
Author

Note: I have used failwith when a dune rule is asking to pass --effects=double-translation with a version of jsoo/wasmoo that doesn’t support it, because I don’t know what the proper way of erroring in this code path is.

@vouillon
Copy link
Member

Note: I have used failwith when a dune rule is asking to pass --effects=double-translation with a version of jsoo/wasmoo that doesn’t support it, because I don’t know what the proper way of erroring in this code path is.

I think you can just use --enable=effects in that case, and let the invocations of js_of_ocaml --effects=double-translation fail.

@OlivierNicole OlivierNicole force-pushed the jsoo-effects branch 3 times, most recently from 9501684 to 00390c3 Compare December 20, 2024 10:31
Signed-off-by: Olivier Nicole <olivier@chnik.fr>
Signed-off-by: Olivier Nicole <olivier@chnik.fr>
Signed-off-by: Olivier Nicole <olivier@chnik.fr>
Signed-off-by: Olivier Nicole <olivier@chnik.fr>
Signed-off-by: Olivier Nicole <olivier@chnik.fr>
@OlivierNicole
Copy link
Author

I’m not sure to understand where the last CI failure comes from.

| None, None -> set acc name `True
| None, Some backend ->
(match effects_of_string backend with
| Some backend -> set acc name (`Effects backend)
Copy link
Member

Choose a reason for hiding this comment

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

name is not right.

Suggested change
| Some backend -> set acc name (`Effects backend)
| Some backend -> set acc "effects" (`Effects backend)

or

Suggested change
| Some backend -> set acc name (`Effects backend)
| Some backend -> { acc with effects = Some backend }

Comment on lines 44 to 99
module Version = struct
type t = int * int

let of_string s : t option =
let s =
match
String.findi s ~f:(function
| '+' | '-' | '~' -> true
| _ -> false)
with
| None -> s
| Some i -> String.take s i
in
try
match String.split s ~on:'.' with
| [] -> None
| [ major ] -> Some (int_of_string major, 0)
| major :: minor :: _ -> Some (int_of_string major, int_of_string minor)
with
| _ -> None
;;

let compare (ma1, mi1) (ma2, mi2) =
match Int.compare ma1 ma2 with
| Eq -> Int.compare mi1 mi2
| n -> n
;;

let impl_version bin =
let* _ = Build_system.build_file bin in
Memo.of_reproducible_fiber
@@ Process.run_capture_line ~display:Quiet Strict bin [ "--version" ]
|> Memo.map ~f:of_string
;;

let version_memo = Memo.create "jsoo-version" ~input:(module Path) impl_version

let jsoo_version jsoo =
match jsoo with
| Ok jsoo_path -> Memo.exec version_memo jsoo_path
| Error e -> Action.Prog.Not_found.raise e
;;
end

let install_jsoo_hint = "opam install js_of_ocaml-compiler"

let jsoo ~dir sctx =
Super_context.resolve_program
sctx
~dir
~loc:None
~where:Original_path
~hint:install_jsoo_hint
"js_of_ocaml"
;;

Copy link
Member

Choose a reason for hiding this comment

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

You don't need to move this.


let effects_of_string = function
| "cps" -> Some Cps
| "double-translation" -> Some Cps
Copy link
Collaborator

Choose a reason for hiding this comment

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

This isn't right

@OlivierNicole OlivierNicole marked this pull request as ready for review December 20, 2024 14:04
Signed-off-by: Olivier Nicole <olivier@chnik.fr>
Signed-off-by: Olivier Nicole <olivier@chnik.fr>
end = struct
type effects_backend =
| Cps
| Double_translation
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should add Native and JSPI so that we don't have to modify dune if we add support for native effects in wasm_of_ocaml.

Copy link
Author

Choose a reason for hiding this comment

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

So dune would support an --effects=native flag for wasm_of_ocaml which may one day be supported by wsoo itself?

Copy link
Member

Choose a reason for hiding this comment

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

Right

Copy link
Collaborator

Choose a reason for hiding this comment

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

The downside is that it increases the number of dune rules registered in dune. One rule per lib per config in Config.all. We currently have 27 config on master. Having cps, double_translate, jspi, and native (what is native btw ?) and "none" would result in 45 configs. I really which we eventually come up with a better design with lazy loading of rules. That would unblock #7389.

Copy link
Member

Choose a reason for hiding this comment

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

We can wait, then.

There is a proposal to add stack switching instructions in Wasm. I started to write a implementation of effect handlers based on this proposal. There is some experiments in some Wasm engines (Wasmtime, for instance), but not yet in V8.

let* jsoo = jsoo in
Action_builder.of_memo (Version.jsoo_version jsoo)
in
let recent =
Copy link
Collaborator

Choose a reason for hiding this comment

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

The name recent does not say much . I think I would rather pass the version down and compare against it when needed.

Comment on lines +76 to +89
match name, v with
| "use-js-string", `True -> { acc with js_string = Some true }
| "use-js-string", `False -> { acc with js_string = Some false }
| "effects", `Effects backend -> { acc with effects = Some backend }
| "effects", `False ->
(* [--disable effects] *)
{ acc with effects = None }
| "effects", `True ->
(* [--enable effects], used alone, implies [--effects=cps] *)
(match acc.effects with
| None -> { acc with effects = Some Cps }
| Some _ -> acc)
| "toplevel", `True -> { acc with toplevel = Some true }
| "toplevel", `False -> { acc with toplevel = Some false }
Copy link
Member

Choose a reason for hiding this comment

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

It would be simpler to have two set functions. One for --enable/--disable and one for --effects.

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.

3 participants