Skip to content

Commit 3cb8b0a

Browse files
committed
Drop %lazy_force primitive
1 parent 43ad467 commit 3cb8b0a

25 files changed

+183
-301
lines changed

jscomp/ext/js_runtime_modules.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ let promise = "Primitive_promise"
3838

3939
let module_ = "Primitive_module"
4040

41+
let lazy_ = "Primitive_lazy"
42+
4143
let deriving = "Runtime_deriving"
4244

4345
let astExtensions = "Runtime_ast_extensions"

jscomp/ml/matching.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ let get_mod_field modname field =
14981498

14991499

15001500
let code_force =
1501-
get_mod_field "CamlinternalLazy" "force"
1501+
get_mod_field Js_runtime_modules.lazy_ "force"
15021502
;;
15031503

15041504
(* inline_lazy_force inlines the beginning of the code of Lazy.force. When

jscomp/ml/translcore.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ let primitives_table =
356356
("%await", Pawait);
357357

358358
(* etc, depreacted *)
359-
("%lazy_force", Plazyforce);
360359
("%intoffloat", Pintoffloat);
361360
("%floatofint", Pfloatofint);
362361
|]

jscomp/runtime/lazy.res

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
type t<'a> = lazy_t<'a>
2+
3+
exception Undefined = Primitive_lazy.Undefined
4+
5+
let force = Primitive_lazy.force
6+
7+
let force_val = Primitive_lazy.force_val
8+
9+
let from_fun = Primitive_lazy.from_fun
10+
11+
let from_val = Primitive_lazy.from_val
12+
13+
let is_val = Primitive_lazy.is_val

jscomp/runtime/lazy.resi

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
type t<'a> = lazy_t<'a>
2+
3+
exception Undefined
4+
5+
/** [force x] forces the suspension [x] and returns its result.
6+
If [x] has already been forced, [Lazy.force x] returns the
7+
same value again without recomputing it. If it raised an exception,
8+
the same exception is raised again.
9+
Raise {!Undefined} if the forcing of [x] tries to force [x] itself
10+
recursively.
11+
*/
12+
let force: t<'a> => 'a
13+
14+
/** [force_val x] forces the suspension [x] and returns its
15+
result. If [x] has already been forced, [force_val x]
16+
returns the same value again without recomputing it.
17+
Raise {!Undefined} if the forcing of [x] tries to force [x] itself
18+
recursively.
19+
If the computation of [x] raises an exception, it is unspecified
20+
whether [force_val x] raises the same exception or {!Undefined}.
21+
*/
22+
let force_val: t<'a> => 'a
23+
24+
/** [from_fun f] is the same as [lazy (f ())] but slightly more efficient.
25+
26+
[from_fun] should only be used if the function [f] is already defined.
27+
In particular it is always less efficient to write
28+
[from_fun (fun () => expr)] than [lazy expr].
29+
*/
30+
let from_fun: (unit => 'a) => t<'a>
31+
32+
/** [from_val v] returns an already-forced suspension of [v].
33+
This is for special purposes only and should not be confused with
34+
[lazy (v)].
35+
*/
36+
let from_val: 'a => t<'a>
37+
38+
/** [is_val x] returns [true] if [x] has already been forced and
39+
did not raise an exception.
40+
*/
41+
let is_val: t<'a> => bool

jscomp/stdlib-406/camlinternalLazy.res renamed to jscomp/runtime/primitive_lazy.res

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type t<'a> = {
3232
/* its type is ['a] or [unit -> 'a ] */
3333
}
3434

35-
%%private(external fnToVal: ((. unit) => 'a) => 'a = "%identity")
36-
%%private(external valToFn: 'a => (. unit) => 'a = "%identity")
35+
%%private(external fnToVal: (unit => 'a) => 'a = "%identity")
36+
%%private(external valToFn: 'a => unit => 'a = "%identity")
3737
%%private(external castToConcrete: lazy_t<'a> => t<'a> = "%identity")
3838
%%private(external castFromConcrete: t<'a> => lazy_t<'a> = "%identity")
3939

@@ -42,15 +42,15 @@ let is_val = (type a, l: lazy_t<a>): bool => castToConcrete(l).tag
4242
exception Undefined
4343

4444
%%private(
45-
let forward_with_closure = (type a, blk: t<a>, closure: (. unit) => a): a => {
46-
let result = closure(.)
45+
let forward_with_closure = (type a, blk: t<a>, closure: unit => a): a => {
46+
let result = closure()
4747
blk.value = result
4848
blk.tag = true
4949
result
5050
}
5151
)
5252

53-
%%private(let raise_undefined = (. ()) => raise(Undefined))
53+
%%private(let raise_undefined = () => raise(Undefined))
5454

5555
/* Assume [blk] is a block with tag lazy */
5656
%%private(
@@ -59,7 +59,7 @@ exception Undefined
5959
blk.value = fnToVal(raise_undefined)
6060
try forward_with_closure(blk, closure) catch {
6161
| e =>
62-
blk.value = fnToVal((. ()) => raise(e))
62+
blk.value = fnToVal(() => raise(e))
6363
raise(e)
6464
}
6565
}
@@ -92,7 +92,7 @@ let force_val = (type a, lzv: lazy_t<a>): a => {
9292
}
9393
}
9494

95-
let from_fun = (type a, closure: (. unit) => a): lazy_t<a> => {
95+
let from_fun = (type a, closure: unit => a): lazy_t<a> => {
9696
let blk = {
9797
tag: false,
9898
value: fnToVal(closure),
@@ -103,7 +103,7 @@ let from_fun = (type a, closure: (. unit) => a): lazy_t<a> => {
103103
let from_val = (type a, value: a): lazy_t<a> => {
104104
let blk = {
105105
tag: true,
106-
value: value,
106+
value,
107107
}
108108
castFromConcrete(blk)
109109
}

jscomp/runtime/primitive_lazy.resi

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
exception Undefined
2+
3+
/** [force x] forces the suspension [x] and returns its result.
4+
If [x] has already been forced, [Lazy.force x] returns the
5+
same value again without recomputing it. If it raised an exception,
6+
the same exception is raised again.
7+
Raise {!Undefined} if the forcing of [x] tries to force [x] itself
8+
recursively.
9+
*/
10+
let force: lazy_t<'a> => 'a
11+
12+
/** [force_val x] forces the suspension [x] and returns its
13+
result. If [x] has already been forced, [force_val x]
14+
returns the same value again without recomputing it.
15+
Raise {!Undefined} if the forcing of [x] tries to force [x] itself
16+
recursively.
17+
If the computation of [x] raises an exception, it is unspecified
18+
whether [force_val x] raises the same exception or {!Undefined}.
19+
*/
20+
let force_val: lazy_t<'a> => 'a
21+
22+
/** [from_fun f] is the same as [lazy (f ())] but slightly more efficient.
23+
24+
[from_fun] should only be used if the function [f] is already defined.
25+
In particular it is always less efficient to write
26+
[from_fun (fun () => expr)] than [lazy expr].
27+
*/
28+
let from_fun: (unit => 'a) => lazy_t<'a>
29+
30+
/** [from_val v] returns an already-forced suspension of [v].
31+
This is for special purposes only and should not be confused with
32+
[lazy (v)].
33+
*/
34+
let from_val: 'a => lazy_t<'a>
35+
36+
/** [is_val x] returns [true] if [x] has already been forced and
37+
did not raise an exception.
38+
*/
39+
let is_val: lazy_t<'a> => bool

jscomp/runtime/release.ninja

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ o runtime/caml_option.cmj : cc_cmi runtime/caml_option.res | runtime/caml_option
2525
o runtime/caml_option.cmi : cc runtime/caml_option.resi | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj
2626
o runtime/caml_splice_call.cmj : cc_cmi runtime/caml_splice_call.res | runtime/caml_splice_call.cmi
2727
o runtime/caml_splice_call.cmi : cc runtime/caml_splice_call.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
28-
o runtime/primitive_module.cmj : cc_cmi runtime/primitive_module.res | runtime/caml_obj.cmj runtime/primitive_module.cmi
28+
o runtime/lazy.cmj : cc_cmi runtime/lazy.res | runtime/lazy.cmi runtime/primitive_lazy.cmj
29+
o runtime/lazy.cmi : cc runtime/lazy.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
30+
o runtime/primitive_lazy.cmj : cc_cmi runtime/primitive_lazy.res | runtime/caml_exceptions.cmj runtime/primitive_lazy.cmi
31+
o runtime/primitive_lazy.cmi : cc runtime/primitive_lazy.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
32+
o runtime/primitive_module.cmj : cc_cmi runtime/primitive_module.res | runtime/caml_obj.cmj runtime/lazy.cmj runtime/primitive_module.cmi
2933
o runtime/primitive_module.cmi : cc runtime/primitive_module.resi | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3034
o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.res | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/caml_option.cmj runtime/js.cmi runtime/js.cmj
3135
o runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
@@ -39,4 +43,4 @@ o runtime/primitive_int.cmi runtime/primitive_int.cmj : cc runtime/primitive_int
3943
o runtime/primitive_promise.cmi runtime/primitive_promise.cmj : cc runtime/primitive_promise.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
4044
o runtime/primitive_string.cmi runtime/primitive_string.cmj : cc runtime/primitive_string.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj runtime/primitive_string_extern.cmj
4145
o runtime/primitive_string_extern.cmi runtime/primitive_string_extern.cmj : cc runtime/primitive_string_extern.res | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
42-
o runtime : phony runtime/bs_stdlib_mini.cmi runtime/js.cmj runtime/js.cmi runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj runtime/caml_hash.cmi runtime/caml_hash.cmj runtime/caml_hash_primitive.cmi runtime/caml_hash_primitive.cmj runtime/caml_obj.cmi runtime/caml_obj.cmj runtime/caml_option.cmi runtime/caml_option.cmj runtime/caml_splice_call.cmi runtime/caml_splice_call.cmj runtime/primitive_module.cmi runtime/primitive_module.cmj runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj runtime/curry.cmi runtime/curry.cmj runtime/primitive_array.cmi runtime/primitive_array.cmj runtime/primitive_bigint.cmi runtime/primitive_bigint.cmj runtime/primitive_bool.cmi runtime/primitive_bool.cmj runtime/primitive_float.cmi runtime/primitive_float.cmj runtime/primitive_float_extern.cmi runtime/primitive_float_extern.cmj runtime/primitive_int.cmi runtime/primitive_int.cmj runtime/primitive_promise.cmi runtime/primitive_promise.cmj runtime/primitive_string.cmi runtime/primitive_string.cmj runtime/primitive_string_extern.cmi runtime/primitive_string_extern.cmj
46+
o runtime : phony runtime/bs_stdlib_mini.cmi runtime/js.cmj runtime/js.cmi runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj runtime/caml_hash.cmi runtime/caml_hash.cmj runtime/caml_hash_primitive.cmi runtime/caml_hash_primitive.cmj runtime/caml_obj.cmi runtime/caml_obj.cmj runtime/caml_option.cmi runtime/caml_option.cmj runtime/caml_splice_call.cmi runtime/caml_splice_call.cmj runtime/lazy.cmi runtime/lazy.cmj runtime/primitive_lazy.cmi runtime/primitive_lazy.cmj runtime/primitive_module.cmi runtime/primitive_module.cmj runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj runtime/curry.cmi runtime/curry.cmj runtime/primitive_array.cmi runtime/primitive_array.cmj runtime/primitive_bigint.cmi runtime/primitive_bigint.cmj runtime/primitive_bool.cmi runtime/primitive_bool.cmj runtime/primitive_float.cmi runtime/primitive_float.cmj runtime/primitive_float_extern.cmi runtime/primitive_float_extern.cmj runtime/primitive_int.cmi runtime/primitive_int.cmj runtime/primitive_promise.cmi runtime/primitive_promise.cmj runtime/primitive_string.cmi runtime/primitive_string.cmj runtime/primitive_string_extern.cmi runtime/primitive_string_extern.cmj

jscomp/stdlib-406/camlinternalLazy.resi

Lines changed: 0 additions & 31 deletions
This file was deleted.

jscomp/stdlib-406/lazy.res

Lines changed: 0 additions & 68 deletions
This file was deleted.

jscomp/stdlib-406/lazy.resi

Lines changed: 0 additions & 91 deletions
This file was deleted.

0 commit comments

Comments
 (0)