-
Notifications
You must be signed in to change notification settings - Fork 413
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
base: main
Are you sure you want to change the base?
Conversation
src/dune_rules/jsoo/jsoo_rules.ml
Outdated
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
[...]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Note: I have used |
I think you can just use |
9501684
to
00390c3
Compare
Signed-off-by: Olivier Nicole <olivier@chnik.fr>
Signed-off-by: Olivier Nicole <olivier@chnik.fr>
Signed-off-by: Olivier Nicole <olivier@chnik.fr>
I’m not sure to understand where the last CI failure comes from. |
00390c3
to
1ec1bd3
Compare
src/dune_rules/jsoo/jsoo_rules.ml
Outdated
| None, None -> set acc name `True | ||
| None, Some backend -> | ||
(match effects_of_string backend with | ||
| Some backend -> set acc name (`Effects backend) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name
is not right.
| Some backend -> set acc name (`Effects backend) | |
| Some backend -> set acc "effects" (`Effects backend) |
or
| Some backend -> set acc name (`Effects backend) | |
| Some backend -> { acc with effects = Some backend } |
src/dune_rules/jsoo/jsoo_rules.ml
Outdated
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" | ||
;; | ||
|
There was a problem hiding this comment.
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.
src/dune_rules/jsoo/jsoo_rules.ml
Outdated
|
||
let effects_of_string = function | ||
| "cps" -> Some Cps | ||
| "double-translation" -> Some Cps |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't right
Signed-off-by: Olivier Nicole <olivier@chnik.fr>
76cc225
to
88be4f4
Compare
end = struct | ||
type effects_backend = | ||
| Cps | ||
| Double_translation |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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.
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 } |
There was a problem hiding this comment.
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
.
This takes into account the new js_of_ocaml
--effects={cps,double-translation}
flag, introduced in ocsigen/js_of_ocaml#1461.