diff --git a/compiler/tests-ocaml/lib-effects/assume_no_perform.ml b/compiler/tests-ocaml/lib-effects/assume_no_perform.ml index 5808e584c5..61cada4703 100644 --- a/compiler/tests-ocaml/lib-effects/assume_no_perform.ml +++ b/compiler/tests-ocaml/lib-effects/assume_no_perform.ml @@ -136,7 +136,7 @@ let () = (* The code below should be called in direct style despite the installed effect handler *) - Jsoo_runtime.Effect.assume_no_perform (fun () -> + Js_of_ocaml.Effect_js.assume_no_perform (fun () -> let m, sd = benchmark iter_fun 5 in let () = printf "Iter: mean = %f, sd = %f\n%!" m sd in diff --git a/compiler/tests-ocaml/lib-effects/assume_no_perform_nested_handler.ml b/compiler/tests-ocaml/lib-effects/assume_no_perform_nested_handler.ml index 25f152ee82..5d8ca5f52b 100644 --- a/compiler/tests-ocaml/lib-effects/assume_no_perform_nested_handler.ml +++ b/compiler/tests-ocaml/lib-effects/assume_no_perform_nested_handler.ml @@ -7,7 +7,7 @@ type _ Effect.t += Dummy : unit t let () = try_with (fun () -> - Jsoo_runtime.Effect.assume_no_perform (fun () -> + Js_of_ocaml.Effect_js.assume_no_perform (fun () -> try_with (fun () -> ()) () diff --git a/compiler/tests-ocaml/lib-effects/assume_no_perform_unhandled.ml b/compiler/tests-ocaml/lib-effects/assume_no_perform_unhandled.ml index a6ff920bdf..a0f52daf88 100644 --- a/compiler/tests-ocaml/lib-effects/assume_no_perform_unhandled.ml +++ b/compiler/tests-ocaml/lib-effects/assume_no_perform_unhandled.ml @@ -7,7 +7,7 @@ type _ Effect.t += Dummy : unit t let must_raise () = try_with (fun () -> - Jsoo_runtime.Effect.assume_no_perform (fun () -> + Js_of_ocaml.Effect_js.assume_no_perform (fun () -> (* Should raise [Effect.Unhandled] despite the installed handler *) perform Dummy ) diff --git a/lib/js_of_ocaml/dune b/lib/js_of_ocaml/dune index 9dc2c3cfe1..df22bcb59a 100644 --- a/lib/js_of_ocaml/dune +++ b/lib/js_of_ocaml/dune @@ -1,8 +1,7 @@ (library (name js_of_ocaml) (public_name js_of_ocaml) - (libraries - (re_export js_of_ocaml-compiler.runtime)) + (libraries js_of_ocaml-compiler.runtime) (foreign_stubs (language c) (names js_of_ocaml_stubs)) diff --git a/lib/js_of_ocaml/effect_js.ml b/lib/js_of_ocaml/effect_js.ml new file mode 100644 index 0000000000..1401eaa015 --- /dev/null +++ b/lib/js_of_ocaml/effect_js.ml @@ -0,0 +1,20 @@ +(* Js_of_ocaml library + * http://www.ocsigen.org/js_of_ocaml/ + * Copyright (C) 2024 Olivier Nicole + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, with linking exception; + * either version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *) + +external assume_no_perform : (unit -> 'a) -> 'a = "caml_assume_no_perform" diff --git a/lib/js_of_ocaml/effect_js.mli b/lib/js_of_ocaml/effect_js.mli new file mode 100644 index 0000000000..0ab148da25 --- /dev/null +++ b/lib/js_of_ocaml/effect_js.mli @@ -0,0 +1,31 @@ +(* Js_of_ocaml library + * http://www.ocsigen.org/js_of_ocaml/ + * Copyright (C) 2024 Olivier Nicole + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, with linking exception; + * either version 2.1 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + *) + +(** Javascript-specific effect functions. *) + +external assume_no_perform : (unit -> 'a) -> 'a = "caml_assume_no_perform" +(** Passing a function [f] as argument of `assume_no_perform` guarantees that, + when compiling with `--effects=double-translation`, the direct-style + version of [f] is called, which is faster than the CPS version. As a + consequence, performing an effect in a transitive callee of [f] will raise + `Effect.Unhandled`, regardless of any effect handlers installed before the + call to `assume_no_perform`, unless a new effect handler was installed in + the meantime. + + This behaviour is the same when double translation is disabled. *) diff --git a/lib/js_of_ocaml/js_of_ocaml.ml b/lib/js_of_ocaml/js_of_ocaml.ml index dfd7799a2c..a0cdd5f30e 100644 --- a/lib/js_of_ocaml/js_of_ocaml.ml +++ b/lib/js_of_ocaml/js_of_ocaml.ml @@ -22,6 +22,7 @@ module Dom = Dom module Dom_events = Dom_events module Dom_html = Dom_html module Dom_svg = Dom_svg +module Effect_js = Effect_js module EventSource = EventSource module File = File module Firebug = Firebug