Skip to content

Commit 974674e

Browse files
authoredApr 23, 2025··
move Lazy module to Stdlib (#7399)
1 parent 72d534a commit 974674e

21 files changed

+237
-139
lines changed
 

‎CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
- Improve error message for missing value when the identifier is also the name of a module in scope. https://github.com/rescript-lang/rescript/pull/7384
3939
- Upgrade Flow parser to 0.267.0. https://github.com/rescript-lang/rescript/pull/7390
40+
- Move `Lazy` module to Stdlib. https://github.com/rescript-lang/rescript/pull/7399
4041

4142
# 12.0.0-alpha.11
4243

‎lib/es6/Stdlib.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID: "Assert_failure",
1313
_1: [
1414
"Stdlib.res",
15-
119,
15+
120,
1616
4
1717
],
1818
Error: new Error()
@@ -49,6 +49,8 @@ let $$Intl;
4949

5050
let $$JSON;
5151

52+
let Lazy;
53+
5254
let List;
5355

5456
let $$Math;
@@ -133,6 +135,7 @@ export {
133135
Int,
134136
$$Intl,
135137
$$JSON,
138+
Lazy,
136139
List,
137140
$$Math,
138141
Null,

‎lib/es6/Lazy.js renamed to ‎lib/es6/Stdlib_Lazy.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
import * as Primitive_lazy from "./Primitive_lazy.js";
44

5+
let make = Primitive_lazy.from_fun;
6+
7+
let get = Primitive_lazy.force;
8+
9+
let isEvaluated = Primitive_lazy.is_val;
10+
511
let Undefined = Primitive_lazy.Undefined;
612

713
let force = Primitive_lazy.force;
@@ -15,6 +21,9 @@ let from_val = Primitive_lazy.from_val;
1521
let is_val = Primitive_lazy.is_val;
1622

1723
export {
24+
make,
25+
get,
26+
isEvaluated,
1827
Undefined,
1928
force,
2029
force_val,

‎lib/js/Stdlib.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function assertEqual(a, b) {
1212
RE_EXN_ID: "Assert_failure",
1313
_1: [
1414
"Stdlib.res",
15-
119,
15+
120,
1616
4
1717
],
1818
Error: new Error()
@@ -49,6 +49,8 @@ let $$Intl;
4949

5050
let $$JSON;
5151

52+
let Lazy;
53+
5254
let List;
5355

5456
let $$Math;
@@ -132,6 +134,7 @@ exports.Float = Float;
132134
exports.Int = Int;
133135
exports.$$Intl = $$Intl;
134136
exports.$$JSON = $$JSON;
137+
exports.Lazy = Lazy;
135138
exports.List = List;
136139
exports.$$Math = $$Math;
137140
exports.Null = Null;

‎lib/js/Lazy.js renamed to ‎lib/js/Stdlib_Lazy.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
let Primitive_lazy = require("./Primitive_lazy.js");
44

5+
let make = Primitive_lazy.from_fun;
6+
7+
let get = Primitive_lazy.force;
8+
9+
let isEvaluated = Primitive_lazy.is_val;
10+
511
let Undefined = Primitive_lazy.Undefined;
612

713
let force = Primitive_lazy.force;
@@ -14,6 +20,9 @@ let from_val = Primitive_lazy.from_val;
1420

1521
let is_val = Primitive_lazy.is_val;
1622

23+
exports.make = make;
24+
exports.get = get;
25+
exports.isEvaluated = isEvaluated;
1726
exports.Undefined = Undefined;
1827
exports.force = force;
1928
exports.force_val = force_val;

‎packages/artifacts.txt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ lib/es6/Jsx.js
114114
lib/es6/JsxDOM.js
115115
lib/es6/JsxDOMStyle.js
116116
lib/es6/JsxEvent.js
117-
lib/es6/Lazy.js
118117
lib/es6/Obj.js
119118
lib/es6/Pervasives.js
120119
lib/es6/Primitive_array.js
@@ -178,6 +177,7 @@ lib/es6/Stdlib_Intl_Segmenter.js
178177
lib/es6/Stdlib_Intl_Segments.js
179178
lib/es6/Stdlib_Iterator.js
180179
lib/es6/Stdlib_JSON.js
180+
lib/es6/Stdlib_Lazy.js
181181
lib/es6/Stdlib_List.js
182182
lib/es6/Stdlib_Map.js
183183
lib/es6/Stdlib_Math.js
@@ -287,7 +287,6 @@ lib/js/Jsx.js
287287
lib/js/JsxDOM.js
288288
lib/js/JsxDOMStyle.js
289289
lib/js/JsxEvent.js
290-
lib/js/Lazy.js
291290
lib/js/Obj.js
292291
lib/js/Pervasives.js
293292
lib/js/Primitive_array.js
@@ -351,6 +350,7 @@ lib/js/Stdlib_Intl_Segmenter.js
351350
lib/js/Stdlib_Intl_Segments.js
352351
lib/js/Stdlib_Iterator.js
353352
lib/js/Stdlib_JSON.js
353+
lib/js/Stdlib_Lazy.js
354354
lib/js/Stdlib_List.js
355355
lib/js/Stdlib_Map.js
356356
lib/js/Stdlib_Math.js
@@ -809,12 +809,6 @@ lib/ocaml/JsxEvent.cmi
809809
lib/ocaml/JsxEvent.cmj
810810
lib/ocaml/JsxEvent.cmt
811811
lib/ocaml/JsxEvent.res
812-
lib/ocaml/Lazy.cmi
813-
lib/ocaml/Lazy.cmj
814-
lib/ocaml/Lazy.cmt
815-
lib/ocaml/Lazy.cmti
816-
lib/ocaml/Lazy.res
817-
lib/ocaml/Lazy.resi
818812
lib/ocaml/Obj.cmi
819813
lib/ocaml/Obj.cmj
820814
lib/ocaml/Obj.cmt
@@ -1109,6 +1103,12 @@ lib/ocaml/Stdlib_JSON.cmt
11091103
lib/ocaml/Stdlib_JSON.cmti
11101104
lib/ocaml/Stdlib_JSON.res
11111105
lib/ocaml/Stdlib_JSON.resi
1106+
lib/ocaml/Stdlib_Lazy.cmi
1107+
lib/ocaml/Stdlib_Lazy.cmj
1108+
lib/ocaml/Stdlib_Lazy.cmt
1109+
lib/ocaml/Stdlib_Lazy.cmti
1110+
lib/ocaml/Stdlib_Lazy.res
1111+
lib/ocaml/Stdlib_Lazy.resi
11121112
lib/ocaml/Stdlib_List.cmi
11131113
lib/ocaml/Stdlib_List.cmj
11141114
lib/ocaml/Stdlib_List.cmt

‎runtime/Lazy.resi

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

‎runtime/Stdlib.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Float = Stdlib_Float
1313
module Int = Stdlib_Int
1414
module Intl = Stdlib_Intl
1515
module JSON = Stdlib_JSON
16+
module Lazy = Stdlib_Lazy
1617
module List = Stdlib_List
1718
module Math = Stdlib_Math
1819
module Null = Stdlib_Null

‎runtime/Lazy.res renamed to ‎runtime/Stdlib_Lazy.res

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
// FIXME:
2-
// This exists for compatibility reason.
3-
// Move this into Pervasives or Core
4-
51
type t<'a> = lazy_t<'a>
62

73
exception Undefined = Primitive_lazy.Undefined
84

5+
let make = Primitive_lazy.from_fun
6+
7+
let get = Primitive_lazy.force
8+
9+
let isEvaluated = Primitive_lazy.is_val
10+
911
let force = Primitive_lazy.force
1012

1113
let force_val = Primitive_lazy.force_val

‎runtime/Stdlib_Lazy.resi

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/***
2+
This module provides a type `Lazy.t` and functions to create and
3+
manipulate lazy values. A lazy value is a value that is not
4+
computed until it is needed. This is useful for deferring
5+
computations that may be expensive or unnecessary.
6+
*/
7+
8+
/**
9+
The type of a lazy value. `Lazy.t<'a>` represents a lazy value
10+
that will eventually yield a value of type `'a` when accessed.
11+
The value is computed only once, and the result is cached for
12+
subsequent accesses. If the computation raises an exception,
13+
the same exception is raised again on subsequent accesses.
14+
*/
15+
type t<'a> = lazy_t<'a>
16+
17+
/**
18+
`Lazy.make(f)` creates a lazy value from `f` which is the
19+
computation to be deferred of type `unit => 'a`.
20+
The function returns a lazy value of type `Lazy.t<'a>`.
21+
The computation is not executed until the lazy value is accessed.
22+
23+
## Examples
24+
```rescript
25+
let lazyValue = Lazy.make(() => {
26+
// Some expensive computation
27+
Console.log("Computing...")
28+
42
29+
});
30+
lazyValue->Lazy.get->assertEqual(42)
31+
```
32+
*/
33+
let make: (unit => 'a) => t<'a>
34+
35+
/**
36+
`Lazy.get(x)` forces the suspension `x` and returns its result.
37+
If `x` has already been forced, `Lazy.get(x)` returns the
38+
same value again without recomputing it. If it raised an
39+
exception, the same exception is raised again.
40+
Raise `Undefined` if the forcing of `x` tries to force `x` itself
41+
recursively. This is a runtime error.
42+
*/
43+
let get: t<'a> => 'a
44+
45+
/**
46+
`Lazy.isEvaluated(x)` returns `true` if the suspension `x` has
47+
already been forced and did not raise an exception. Otherwise,
48+
it returns `false`. This is useful for checking if a lazy value
49+
has been computed before accessing it.
50+
51+
## Examples
52+
```rescript
53+
let lazyValue = Lazy.make(() => {
54+
// Some expensive computation
55+
Console.log("Computing...")
56+
42
57+
})
58+
Lazy.isEvaluated(lazyValue)->assertEqual(false)
59+
lazyValue->Lazy.get->assertEqual(42)
60+
lazyValue->Lazy.isEvaluated->assertEqual(true)
61+
```
62+
*/
63+
let isEvaluated: t<'a> => bool
64+
65+
exception Undefined
66+
67+
/**
68+
`force(x)` forces the suspension `x` and returns its result.
69+
If `x` has already been forced, `Lazy.force(x)` returns the
70+
same value again without recomputing it. If it raised an exception,
71+
the same exception is raised again.
72+
Raise `Undefined` if the forcing of `x` tries to force `x` itself
73+
recursively.
74+
*/
75+
@deprecated("Use `Lazy.get` instead")
76+
let force: t<'a> => 'a
77+
78+
/**
79+
`force_val(x)` forces the suspension `x` and returns its
80+
result. If `x` has already been forced, `force_val(x)`
81+
returns the same value again without recomputing it.
82+
Raise `Undefined` if the forcing of `x` tries to force `x` itself
83+
recursively.
84+
If the computation of `x` raises an exception, it is unspecified
85+
whether `force_val(x)` raises the same exception or `Undefined`.
86+
*/
87+
@deprecated("Use `Lazy.get` instead")
88+
let force_val: t<'a> => 'a
89+
90+
/**
91+
`Lazy.from_fun(f)` creates a lazy value from `f` which is the
92+
computation to be deferred of type `unit => 'a`.
93+
The function returns a lazy value of type `Lazy.t<'a>`.
94+
The computation is not executed until the lazy value is accessed.
95+
*/
96+
@deprecated("Use `Lazy.make` instead")
97+
let from_fun: (unit => 'a) => t<'a>
98+
99+
/**
100+
`from_val(v)` returns an already-forced suspension of `v`.
101+
This is for special purposes only.
102+
*/
103+
@deprecated("Use `Lazy.make` instead")
104+
let from_val: 'a => t<'a>
105+
106+
/**
107+
`is_val(x)` returns `true` if `x has already been forced and
108+
did not raise an exception.
109+
*/
110+
@deprecated("Use `Lazy.isEvaluated` instead")
111+
let is_val: t<'a> => bool

‎tests/tests/src/gpr_3697_test.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3-
import * as Lazy from "rescript/lib/es6/Lazy.js";
3+
import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js";
44

55
function fix() {
66
return {
77
TAG: "Fix",
8-
_0: Lazy.from_fun(fix)
8+
_0: Stdlib_Lazy.from_fun(fix)
99
};
1010
}
1111

1212
function unfixLeak(_f) {
1313
while (true) {
1414
let f = _f;
15-
_f = Lazy.force(f._0);
15+
_f = Stdlib_Lazy.force(f._0);
1616
continue;
1717
};
1818
}
1919

2020
function unfix(p) {
2121
while (true) {
2222
let h = p.contents;
23-
p.contents = Lazy.force(h._0);
23+
p.contents = Stdlib_Lazy.force(h._0);
2424
};
2525
}
2626

‎tests/tests/src/lazy_demo.mjs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3-
import * as Lazy from "rescript/lib/es6/Lazy.js";
3+
import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js";
44

5-
let lazy1 = Lazy.from_fun(() => {
5+
let lazy1 = Stdlib_Lazy.make(() => {
66
console.log("Hello, lazy");
77
return 1;
88
});
99

10-
let lazy2 = Lazy.from_fun(() => 3);
10+
let lazy2 = Stdlib_Lazy.make(() => 3);
1111

1212
console.log(lazy1, lazy2);
1313

14-
let la = Lazy.force(lazy1);
14+
let la = Stdlib_Lazy.get(lazy1);
1515

16-
let lb = Lazy.force(lazy2);
16+
let lb = Stdlib_Lazy.get(lazy2);
1717

1818
console.log(la, lb);
1919

@@ -23,4 +23,4 @@ export {
2323
la,
2424
lb,
2525
}
26-
/* Not a pure module */
26+
/* lazy1 Not a pure module */

‎tests/tests/src/lazy_demo.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
let lazy1 = Lazy.from_fun(() => {
1+
let lazy1 = Lazy.make(() => {
22
"Hello, lazy"->Js.log
33
1
44
})
55

6-
let lazy2 = Lazy.from_fun(() => 3)
6+
let lazy2 = Lazy.make(() => 3)
77

88
Js.log2(lazy1, lazy2)
99

1010
// can't destructure lazy values
11-
let (la, lb) = (Lazy.force(lazy1), Lazy.force(lazy2))
11+
let (la, lb) = (Lazy.get(lazy1), Lazy.get(lazy2))
1212

1313
Js.log2(la, lb)

‎tests/tests/src/lazy_test.mjs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

33
import * as Mt from "./mt.mjs";
4-
import * as Lazy from "rescript/lib/es6/Lazy.js";
4+
import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js";
55

66
let u = {
77
contents: 3
88
};
99

10-
let v = Lazy.from_fun(() => {
10+
let v = Stdlib_Lazy.make(() => {
1111
u.contents = 32;
1212
});
1313

1414
function lazy_test() {
1515
let h = u.contents;
16-
Lazy.force(v);
16+
Stdlib_Lazy.get(v);
1717
let g = u.contents;
1818
return [
1919
h,
@@ -25,54 +25,54 @@ let u_v = {
2525
contents: 0
2626
};
2727

28-
let u$1 = Lazy.from_fun(() => {
28+
let u$1 = Stdlib_Lazy.make(() => {
2929
u_v.contents = 2;
3030
});
3131

32-
Lazy.force(u$1);
32+
Stdlib_Lazy.get(u$1);
3333

34-
let exotic = Lazy.force;
34+
let exotic = Stdlib_Lazy.get;
3535

36-
let l_from_fun = Lazy.from_fun(() => 3);
36+
let l_from_fun = Stdlib_Lazy.make(() => 3);
3737

38-
let forward_test = Lazy.from_fun(() => {
38+
let forward_test = Stdlib_Lazy.make(() => {
3939
let u = 3;
4040
u = u + 1 | 0;
4141
return u;
4242
});
4343

44-
let f005 = Lazy.from_fun(() => 6);
44+
let f005 = Stdlib_Lazy.make(() => 6);
4545

46-
let f006 = Lazy.from_fun(() => (() => 3));
46+
let f006 = Stdlib_Lazy.make(() => (() => 3));
4747

48-
let f007 = Lazy.from_fun(() => {
48+
let f007 = Stdlib_Lazy.make(() => {
4949
throw {
5050
RE_EXN_ID: "Not_found",
5151
Error: new Error()
5252
};
5353
});
5454

55-
let f008 = Lazy.from_fun(() => {
55+
let f008 = Stdlib_Lazy.make(() => {
5656
console.log("hi");
5757
throw {
5858
RE_EXN_ID: "Not_found",
5959
Error: new Error()
6060
};
6161
});
6262

63-
let a2 = Lazy.from_val;
63+
let a2 = Stdlib_Lazy.from_val;
6464

65-
let a3 = Lazy.from_val(3);
65+
let a3 = Stdlib_Lazy.from_val(3);
6666

67-
let a4 = Lazy.from_val(3);
67+
let a4 = Stdlib_Lazy.from_val(3);
6868

69-
let a5 = Lazy.from_val(undefined);
69+
let a5 = Stdlib_Lazy.from_val(undefined);
7070

71-
let a6 = Lazy.from_val();
71+
let a6 = Stdlib_Lazy.from_val();
7272

73-
let a7 = Lazy.force(a5);
73+
let a7 = Stdlib_Lazy.get(a5);
7474

75-
let a8 = Lazy.force(a6);
75+
let a8 = Stdlib_Lazy.get(a6);
7676

7777
Mt.from_pair_suites("Lazy_test", {
7878
hd: [
@@ -100,7 +100,7 @@ Mt.from_pair_suites("Lazy_test", {
100100
"lazy_from_fun",
101101
() => ({
102102
TAG: "Eq",
103-
_0: Lazy.force(l_from_fun),
103+
_0: Stdlib_Lazy.get(l_from_fun),
104104
_1: 3
105105
})
106106
],
@@ -109,7 +109,7 @@ Mt.from_pair_suites("Lazy_test", {
109109
"lazy_from_val",
110110
() => ({
111111
TAG: "Eq",
112-
_0: Lazy.force(Lazy.from_val(3)),
112+
_0: Stdlib_Lazy.get(Stdlib_Lazy.from_val(3)),
113113
_1: 3
114114
})
115115
],
@@ -118,7 +118,7 @@ Mt.from_pair_suites("Lazy_test", {
118118
"lazy_from_val2",
119119
() => ({
120120
TAG: "Eq",
121-
_0: Lazy.force(Lazy.force(Lazy.from_val(Lazy.from_fun(() => 3)))),
121+
_0: Stdlib_Lazy.get(Stdlib_Lazy.get(Stdlib_Lazy.from_val(Stdlib_Lazy.make(() => 3)))),
122122
_1: 3
123123
})
124124
],
@@ -129,7 +129,7 @@ Mt.from_pair_suites("Lazy_test", {
129129
debugger;
130130
return {
131131
TAG: "Eq",
132-
_0: Lazy.force(Lazy.force(Lazy.from_val(forward_test))),
132+
_0: Stdlib_Lazy.get(Stdlib_Lazy.get(Stdlib_Lazy.make(() => forward_test))),
133133
_1: 4
134134
};
135135
}
@@ -166,15 +166,15 @@ Mt.from_pair_suites("Lazy_test", {
166166
"File \"lazy_test.res\", line 95, characters 7-14",
167167
() => ({
168168
TAG: "Ok",
169-
_0: Lazy.is_val(Lazy.from_val(3))
169+
_0: Stdlib_Lazy.isEvaluated(Stdlib_Lazy.from_val(3))
170170
})
171171
],
172172
tl: {
173173
hd: [
174174
"File \"lazy_test.res\", line 96, characters 7-14",
175175
() => ({
176176
TAG: "Ok",
177-
_0: !Lazy.is_val(Lazy.from_fun(() => {
177+
_0: !Stdlib_Lazy.isEvaluated(Stdlib_Lazy.make(() => {
178178
throw {
179179
RE_EXN_ID: "Not_found",
180180
Error: new Error()
@@ -215,4 +215,4 @@ export {
215215
a7,
216216
a8,
217217
}
218-
/* Not a pure module */
218+
/* v Not a pure module */

‎tests/tests/src/lazy_test.res

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
let u = ref(3)
2-
let v = Lazy.from_fun(() => u := 32)
2+
let v = Lazy.make(() => u := 32)
33

44
let lazy_test = () => {
55
let h = u.contents
66
let g = {
7-
Lazy.force(v)
7+
Lazy.get(v)
88
u.contents
99
}
1010
(h, g)
@@ -24,36 +24,36 @@ let lazy_test = () => {
2424
// let set_false = lazy (s := None)
2525

2626
let u_v = ref(0)
27-
let u = Lazy.from_fun(() => u_v := 2)
28-
let () = Lazy.force(u)
27+
let u = Lazy.make(() => u_v := 2)
28+
let () = Lazy.get(u)
2929

3030
/* module Mt = Mock_mt */
3131

3232
let exotic = x =>
3333
switch x {
3434
/* Lazy in a pattern. (used in advi) */
35-
| y => Lazy.force(y)
35+
| y => Lazy.get(y)
3636
}
3737

3838
/* let l_from_val = Lazy.from_val 3 */
3939

40-
let l_from_fun = Lazy.from_fun(_ => 3)
41-
let forward_test = Lazy.from_fun(() => {
40+
let l_from_fun = Lazy.make(_ => 3)
41+
let forward_test = Lazy.make(() => {
4242
let u = ref(3)
4343
incr(u)
4444
u.contents
4545
})
4646
/* module Mt = Mock_mt */
4747

48-
let f005 = Lazy.from_fun(() => 1 + 2 + 3)
48+
let f005 = Lazy.make(() => 1 + 2 + 3)
4949

50-
let f006: Lazy.t<unit => int> = Lazy.from_fun(() => {
50+
let f006: Lazy.t<unit => int> = Lazy.make(() => {
5151
let x = 3
5252
_ => x
5353
})
5454

55-
let f007 = Lazy.from_fun(() => raise(Not_found))
56-
let f008 = Lazy.from_fun(() => {
55+
let f007 = Lazy.make(() => raise(Not_found))
56+
let f008 = Lazy.make(() => {
5757
Js.log("hi")
5858
raise(Not_found)
5959
})
@@ -65,8 +65,8 @@ let a4 = a2(3)
6565
let a5 = Lazy.from_val(None)
6666
let a6 = Lazy.from_val()
6767

68-
let a7 = Lazy.force(a5)
69-
let a8 = Lazy.force(a6)
68+
let a7 = Lazy.get(a5)
69+
let a8 = Lazy.get(a6)
7070

7171
Mt.from_pair_suites(
7272
__MODULE__,
@@ -76,24 +76,24 @@ Mt.from_pair_suites(
7676
("simple", _ => Eq(lazy_test(), (3, 32))),
7777
// ("lazy_match", _ => Eq(h, 2)),
7878
("lazy_force", _ => Eq(u_v.contents, 2)),
79-
("lazy_from_fun", _ => Eq(Lazy.force(l_from_fun), 3)),
80-
("lazy_from_val", _ => Eq(Lazy.force(Lazy.from_val(3)), 3)),
81-
("lazy_from_val2", _ => Eq(Lazy.force(Lazy.force(Lazy.from_val(Lazy.from_fun(() => 3)))), 3)),
79+
("lazy_from_fun", _ => Eq(Lazy.get(l_from_fun), 3)),
80+
("lazy_from_val", _ => Eq(Lazy.get(Lazy.from_val(3)), 3)),
81+
("lazy_from_val2", _ => Eq(Lazy.get(Lazy.get(Lazy.from_val(Lazy.make(() => 3)))), 3)),
8282
(
8383
"lazy_from_val3",
8484
_ => Eq(
8585
{
8686
%debugger
87-
Lazy.force(Lazy.force(Lazy.from_val(forward_test)))
87+
Lazy.get(Lazy.get(Lazy.make(() => forward_test)))
8888
},
8989
4,
9090
),
9191
),
9292
(__FILE__, _ => Eq(a3, a4)),
9393
(__FILE__, _ => Eq(a7, None)),
9494
(__FILE__, _ => Eq(a8, ())),
95-
(__LOC__, _ => Ok(Lazy.is_val(Lazy.from_val(3)))),
96-
(__LOC__, _ => Ok(!Lazy.is_val(Lazy.from_fun(() => raise(Not_found))))),
95+
(__LOC__, _ => Ok(Lazy.isEvaluated(Lazy.from_val(3)))),
96+
(__LOC__, _ => Ok(!Lazy.isEvaluated(Lazy.make(() => raise(Not_found))))),
9797
}
9898
},
9999
)

‎tests/tests/src/mpr_6033_test.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

33
import * as Mt from "./mt.mjs";
4-
import * as Lazy from "rescript/lib/es6/Lazy.js";
4+
import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js";
55

66
let suites = {
77
contents: /* [] */0
@@ -27,14 +27,14 @@ function eq(loc, x, y) {
2727
}
2828

2929
function f(x) {
30-
return Lazy.force(x) + "abc";
30+
return Stdlib_Lazy.get(x) + "abc";
3131
}
3232

33-
let x = Lazy.from_fun(() => "def");
33+
let x = Stdlib_Lazy.from_fun(() => "def");
3434

35-
Lazy.force(x);
35+
Stdlib_Lazy.get(x);
3636

37-
let u = Lazy.force(x) + "abc";
37+
let u = Stdlib_Lazy.get(x) + "abc";
3838

3939
eq("File \"mpr_6033_test.res\", line 23, characters 3-10", u, "defabc");
4040

‎tests/tests/src/mpr_6033_test.res

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ let eq = (loc, x, y) => {
1111

1212
let f = x =>
1313
switch x {
14-
| y => Lazy.force(y) ++ "abc"
14+
| y => Lazy.get(y) ++ "abc"
1515
}
1616

1717
let u = {
1818
let x = Lazy.from_fun(() => "def")
19-
ignore(Lazy.force(x))
19+
ignore(Lazy.get(x))
2020
f(x)
2121
}
2222

‎tests/tests/src/recursive_module.mjs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

33
import * as Mt from "./mt.mjs";
4-
import * as Lazy from "rescript/lib/es6/Lazy.js";
4+
import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js";
55
import * as Primitive_module from "rescript/lib/es6/Primitive_module.js";
66
import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js";
77

@@ -65,7 +65,7 @@ let Intb = Primitive_module.init([
6565
]]
6666
});
6767

68-
let a = Lazy.from_fun(() => Lazy.force(Intb.a));
68+
let a = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Intb.a));
6969

7070
Primitive_module.update({
7171
TAG: "Module",
@@ -77,7 +77,7 @@ Primitive_module.update({
7777
a: a
7878
});
7979

80-
let a$1 = Lazy.from_fun(() => Lazy.force(Inta.a) + 1 | 0);
80+
let a$1 = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Inta.a) + 1 | 0);
8181

8282
Primitive_module.update({
8383
TAG: "Module",
@@ -92,10 +92,10 @@ Primitive_module.update({
9292
let tmp;
9393

9494
try {
95-
tmp = Lazy.force(Intb.a);
95+
tmp = Stdlib_Lazy.get(Intb.a);
9696
} catch (raw_exn) {
9797
let exn = Primitive_exceptions.internalToException(raw_exn);
98-
if (exn.RE_EXN_ID === Lazy.Undefined) {
98+
if (exn.RE_EXN_ID === Stdlib_Lazy.Undefined) {
9999
tmp = -1;
100100
} else {
101101
throw exn;
@@ -128,7 +128,7 @@ let Intb$1 = Primitive_module.init([
128128
]]
129129
});
130130

131-
let a$2 = Lazy.from_fun(() => Lazy.force(Intb$1.a) + 1 | 0);
131+
let a$2 = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Intb$1.a) + 1 | 0);
132132

133133
Primitive_module.update({
134134
TAG: "Module",
@@ -140,7 +140,7 @@ Primitive_module.update({
140140
a: a$2
141141
});
142142

143-
let a$3 = Lazy.from_fun(() => 2);
143+
let a$3 = Stdlib_Lazy.make(() => 2);
144144

145145
Primitive_module.update({
146146
TAG: "Module",
@@ -157,7 +157,7 @@ let A = {
157157
Intb: Intb$1
158158
};
159159

160-
eq("File \"recursive_module.res\", line 59, characters 3-10", Lazy.force(Inta$1.a), 3);
160+
eq("File \"recursive_module.res\", line 59, characters 3-10", Stdlib_Lazy.get(Inta$1.a), 3);
161161

162162
let tmp$1;
163163

‎tests/tests/src/recursive_module.res

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,36 +27,36 @@ module rec Int3: {
2727
module rec Inta: {
2828
let a: Lazy.t<int>
2929
} = {
30-
let a = Lazy.from_fun(() => Lazy.force(Intb.a))
30+
let a = Lazy.make(() => Lazy.get(Intb.a))
3131
}
3232
and Intb: {
3333
let a: Lazy.t<int>
3434
} = {
35-
let a = Lazy.from_fun(() => Lazy.force(Inta.a) + 1)
35+
let a = Lazy.make(() => Lazy.get(Inta.a) + 1)
3636
}
3737

3838
eq(
3939
__LOC__,
4040
-1,
41-
try Lazy.force(Intb.a) catch {
41+
try Lazy.get(Intb.a) catch {
4242
| Lazy.Undefined => -1
4343
},
4444
)
4545

4646
module A = {
4747
module rec Inta: {
48-
let a: lazy_t<int>
48+
let a: Lazy.t<int>
4949
} = {
50-
let a = Lazy.from_fun(() => Lazy.force(Intb.a) + 1)
50+
let a = Lazy.make(() => Lazy.get(Intb.a) + 1)
5151
}
5252
and Intb: {
53-
let a: lazy_t<int>
53+
let a: Lazy.t<int>
5454
} = {
55-
let a = Lazy.from_fun(() => 2)
55+
let a = Lazy.make(() => 2)
5656
}
5757
}
5858

59-
eq(__LOC__, Lazy.force(A.Inta.a), 3)
59+
eq(__LOC__, Lazy.get(A.Inta.a), 3)
6060
/* expect raise Undefined_recursive_module */
6161
eq(
6262
__LOC__,

‎tests/tests/src/test_primitive.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Generated by ReScript, PLEASE EDIT WITH CARE
22

3-
import * as Lazy from "rescript/lib/es6/Lazy.js";
3+
import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js";
44

55
function a4(prim) {
66
return [
@@ -69,7 +69,7 @@ function f(x) {
6969
return x.length;
7070
}
7171

72-
let is_lazy_force = Lazy.force;
72+
let is_lazy_force = Stdlib_Lazy.get;
7373

7474
function fib(n) {
7575
if (n === 0 || n === 1) {

‎tests/tests/src/test_primitive.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ let gg = x => x.u = 0.
8585

8686
let f = (x: string) => String.length(x)
8787

88-
let is_lazy_force = x => Lazy.force(x)
88+
let is_lazy_force = x => Lazy.get(x)
8989

9090
let rec fib = (n: int) =>
9191
switch n {

0 commit comments

Comments
 (0)
Please sign in to comment.