From 0ff296647d3abd2388850dc8212c9c7becb8ff5a Mon Sep 17 00:00:00 2001 From: tsnobip Date: Sun, 20 Apr 2025 12:36:19 +0200 Subject: [PATCH] move Lazy module to Stdlib --- CHANGELOG.md | 1 + lib/es6/Stdlib.js | 5 +- lib/es6/{Lazy.js => Stdlib_Lazy.js} | 9 +++ lib/js/Stdlib.js | 5 +- lib/js/{Lazy.js => Stdlib_Lazy.js} | 9 +++ packages/artifacts.txt | 16 ++-- runtime/Lazy.resi | 41 ---------- runtime/Stdlib.res | 1 + runtime/{Lazy.res => Stdlib_Lazy.res} | 10 ++- runtime/Stdlib_Lazy.resi | 111 ++++++++++++++++++++++++++ tests/tests/src/gpr_3697_test.mjs | 8 +- tests/tests/src/lazy_demo.mjs | 12 +-- tests/tests/src/lazy_demo.res | 6 +- tests/tests/src/lazy_test.mjs | 52 ++++++------ tests/tests/src/lazy_test.res | 38 ++++----- tests/tests/src/mpr_6033_test.mjs | 10 +-- tests/tests/src/mpr_6033_test.res | 4 +- tests/tests/src/recursive_module.mjs | 16 ++-- tests/tests/src/recursive_module.res | 16 ++-- tests/tests/src/test_primitive.mjs | 4 +- tests/tests/src/test_primitive.res | 2 +- 21 files changed, 237 insertions(+), 139 deletions(-) rename lib/es6/{Lazy.js => Stdlib_Lazy.js} (73%) rename lib/js/{Lazy.js => Stdlib_Lazy.js} (72%) delete mode 100644 runtime/Lazy.resi rename runtime/{Lazy.res => Stdlib_Lazy.res} (71%) create mode 100644 runtime/Stdlib_Lazy.resi diff --git a/CHANGELOG.md b/CHANGELOG.md index 9f8c5ee864..e2d215b786 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ - 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 - Upgrade Flow parser to 0.267.0. https://github.com/rescript-lang/rescript/pull/7390 +- Move `Lazy` module to Stdlib. https://github.com/rescript-lang/rescript/pull/7399 # 12.0.0-alpha.11 diff --git a/lib/es6/Stdlib.js b/lib/es6/Stdlib.js index a2e96d79ef..3f545e797e 100644 --- a/lib/es6/Stdlib.js +++ b/lib/es6/Stdlib.js @@ -12,7 +12,7 @@ function assertEqual(a, b) { RE_EXN_ID: "Assert_failure", _1: [ "Stdlib.res", - 119, + 120, 4 ], Error: new Error() @@ -49,6 +49,8 @@ let $$Intl; let $$JSON; +let Lazy; + let List; let $$Math; @@ -133,6 +135,7 @@ export { Int, $$Intl, $$JSON, + Lazy, List, $$Math, Null, diff --git a/lib/es6/Lazy.js b/lib/es6/Stdlib_Lazy.js similarity index 73% rename from lib/es6/Lazy.js rename to lib/es6/Stdlib_Lazy.js index b3b7e7780a..211047999f 100644 --- a/lib/es6/Lazy.js +++ b/lib/es6/Stdlib_Lazy.js @@ -2,6 +2,12 @@ import * as Primitive_lazy from "./Primitive_lazy.js"; +let make = Primitive_lazy.from_fun; + +let get = Primitive_lazy.force; + +let isEvaluated = Primitive_lazy.is_val; + let Undefined = Primitive_lazy.Undefined; let force = Primitive_lazy.force; @@ -15,6 +21,9 @@ let from_val = Primitive_lazy.from_val; let is_val = Primitive_lazy.is_val; export { + make, + get, + isEvaluated, Undefined, force, force_val, diff --git a/lib/js/Stdlib.js b/lib/js/Stdlib.js index f7f38a6189..05e4d91e25 100644 --- a/lib/js/Stdlib.js +++ b/lib/js/Stdlib.js @@ -12,7 +12,7 @@ function assertEqual(a, b) { RE_EXN_ID: "Assert_failure", _1: [ "Stdlib.res", - 119, + 120, 4 ], Error: new Error() @@ -49,6 +49,8 @@ let $$Intl; let $$JSON; +let Lazy; + let List; let $$Math; @@ -132,6 +134,7 @@ exports.Float = Float; exports.Int = Int; exports.$$Intl = $$Intl; exports.$$JSON = $$JSON; +exports.Lazy = Lazy; exports.List = List; exports.$$Math = $$Math; exports.Null = Null; diff --git a/lib/js/Lazy.js b/lib/js/Stdlib_Lazy.js similarity index 72% rename from lib/js/Lazy.js rename to lib/js/Stdlib_Lazy.js index 171f0bfea0..48b7e8a581 100644 --- a/lib/js/Lazy.js +++ b/lib/js/Stdlib_Lazy.js @@ -2,6 +2,12 @@ let Primitive_lazy = require("./Primitive_lazy.js"); +let make = Primitive_lazy.from_fun; + +let get = Primitive_lazy.force; + +let isEvaluated = Primitive_lazy.is_val; + let Undefined = Primitive_lazy.Undefined; let force = Primitive_lazy.force; @@ -14,6 +20,9 @@ let from_val = Primitive_lazy.from_val; let is_val = Primitive_lazy.is_val; +exports.make = make; +exports.get = get; +exports.isEvaluated = isEvaluated; exports.Undefined = Undefined; exports.force = force; exports.force_val = force_val; diff --git a/packages/artifacts.txt b/packages/artifacts.txt index 33b36a6e86..adfa893f3b 100644 --- a/packages/artifacts.txt +++ b/packages/artifacts.txt @@ -114,7 +114,6 @@ lib/es6/Jsx.js lib/es6/JsxDOM.js lib/es6/JsxDOMStyle.js lib/es6/JsxEvent.js -lib/es6/Lazy.js lib/es6/Obj.js lib/es6/Pervasives.js lib/es6/Primitive_array.js @@ -178,6 +177,7 @@ lib/es6/Stdlib_Intl_Segmenter.js lib/es6/Stdlib_Intl_Segments.js lib/es6/Stdlib_Iterator.js lib/es6/Stdlib_JSON.js +lib/es6/Stdlib_Lazy.js lib/es6/Stdlib_List.js lib/es6/Stdlib_Map.js lib/es6/Stdlib_Math.js @@ -287,7 +287,6 @@ lib/js/Jsx.js lib/js/JsxDOM.js lib/js/JsxDOMStyle.js lib/js/JsxEvent.js -lib/js/Lazy.js lib/js/Obj.js lib/js/Pervasives.js lib/js/Primitive_array.js @@ -351,6 +350,7 @@ lib/js/Stdlib_Intl_Segmenter.js lib/js/Stdlib_Intl_Segments.js lib/js/Stdlib_Iterator.js lib/js/Stdlib_JSON.js +lib/js/Stdlib_Lazy.js lib/js/Stdlib_List.js lib/js/Stdlib_Map.js lib/js/Stdlib_Math.js @@ -809,12 +809,6 @@ lib/ocaml/JsxEvent.cmi lib/ocaml/JsxEvent.cmj lib/ocaml/JsxEvent.cmt lib/ocaml/JsxEvent.res -lib/ocaml/Lazy.cmi -lib/ocaml/Lazy.cmj -lib/ocaml/Lazy.cmt -lib/ocaml/Lazy.cmti -lib/ocaml/Lazy.res -lib/ocaml/Lazy.resi lib/ocaml/Obj.cmi lib/ocaml/Obj.cmj lib/ocaml/Obj.cmt @@ -1109,6 +1103,12 @@ lib/ocaml/Stdlib_JSON.cmt lib/ocaml/Stdlib_JSON.cmti lib/ocaml/Stdlib_JSON.res lib/ocaml/Stdlib_JSON.resi +lib/ocaml/Stdlib_Lazy.cmi +lib/ocaml/Stdlib_Lazy.cmj +lib/ocaml/Stdlib_Lazy.cmt +lib/ocaml/Stdlib_Lazy.cmti +lib/ocaml/Stdlib_Lazy.res +lib/ocaml/Stdlib_Lazy.resi lib/ocaml/Stdlib_List.cmi lib/ocaml/Stdlib_List.cmj lib/ocaml/Stdlib_List.cmt diff --git a/runtime/Lazy.resi b/runtime/Lazy.resi deleted file mode 100644 index 90e6a7e3bb..0000000000 --- a/runtime/Lazy.resi +++ /dev/null @@ -1,41 +0,0 @@ -type t<'a> = lazy_t<'a> - -exception Undefined - -/** [force x] forces the suspension [x] and returns its result. - If [x] has already been forced, [Lazy.force x] returns the - same value again without recomputing it. If it raised an exception, - the same exception is raised again. - Raise {!Undefined} if the forcing of [x] tries to force [x] itself - recursively. -*/ -let force: t<'a> => 'a - -/** [force_val x] forces the suspension [x] and returns its - result. If [x] has already been forced, [force_val x] - returns the same value again without recomputing it. - Raise {!Undefined} if the forcing of [x] tries to force [x] itself - recursively. - If the computation of [x] raises an exception, it is unspecified - whether [force_val x] raises the same exception or {!Undefined}. -*/ -let force_val: t<'a> => 'a - -/** [from_fun f] is the same as [lazy (f ())] but slightly more efficient. - - [from_fun] should only be used if the function [f] is already defined. - In particular it is always less efficient to write - [from_fun (fun () => expr)] than [lazy expr]. -*/ -let from_fun: (unit => 'a) => t<'a> - -/** [from_val v] returns an already-forced suspension of [v]. - This is for special purposes only and should not be confused with - [lazy (v)]. -*/ -let from_val: 'a => t<'a> - -/** [is_val x] returns [true] if [x] has already been forced and - did not raise an exception. -*/ -let is_val: t<'a> => bool diff --git a/runtime/Stdlib.res b/runtime/Stdlib.res index 8e18d33324..6c72f2b12d 100644 --- a/runtime/Stdlib.res +++ b/runtime/Stdlib.res @@ -13,6 +13,7 @@ module Float = Stdlib_Float module Int = Stdlib_Int module Intl = Stdlib_Intl module JSON = Stdlib_JSON +module Lazy = Stdlib_Lazy module List = Stdlib_List module Math = Stdlib_Math module Null = Stdlib_Null diff --git a/runtime/Lazy.res b/runtime/Stdlib_Lazy.res similarity index 71% rename from runtime/Lazy.res rename to runtime/Stdlib_Lazy.res index 7cefd00f12..d92a7b3b0c 100644 --- a/runtime/Lazy.res +++ b/runtime/Stdlib_Lazy.res @@ -1,11 +1,13 @@ -// FIXME: -// This exists for compatibility reason. -// Move this into Pervasives or Core - type t<'a> = lazy_t<'a> exception Undefined = Primitive_lazy.Undefined +let make = Primitive_lazy.from_fun + +let get = Primitive_lazy.force + +let isEvaluated = Primitive_lazy.is_val + let force = Primitive_lazy.force let force_val = Primitive_lazy.force_val diff --git a/runtime/Stdlib_Lazy.resi b/runtime/Stdlib_Lazy.resi new file mode 100644 index 0000000000..9c70483be6 --- /dev/null +++ b/runtime/Stdlib_Lazy.resi @@ -0,0 +1,111 @@ +/*** + This module provides a type `Lazy.t` and functions to create and + manipulate lazy values. A lazy value is a value that is not + computed until it is needed. This is useful for deferring + computations that may be expensive or unnecessary. + */ + +/** + The type of a lazy value. `Lazy.t<'a>` represents a lazy value + that will eventually yield a value of type `'a` when accessed. + The value is computed only once, and the result is cached for + subsequent accesses. If the computation raises an exception, + the same exception is raised again on subsequent accesses. + */ +type t<'a> = lazy_t<'a> + +/** + `Lazy.make(f)` creates a lazy value from `f` which is the + computation to be deferred of type `unit => 'a`. + The function returns a lazy value of type `Lazy.t<'a>`. + The computation is not executed until the lazy value is accessed. + + ## Examples + ```rescript + let lazyValue = Lazy.make(() => { + // Some expensive computation + Console.log("Computing...") + 42 + }); + lazyValue->Lazy.get->assertEqual(42) + ``` +*/ +let make: (unit => 'a) => t<'a> + +/** + `Lazy.get(x)` forces the suspension `x` and returns its result. + If `x` has already been forced, `Lazy.get(x)` returns the + same value again without recomputing it. If it raised an + exception, the same exception is raised again. + Raise `Undefined` if the forcing of `x` tries to force `x` itself + recursively. This is a runtime error. + */ +let get: t<'a> => 'a + +/** + `Lazy.isEvaluated(x)` returns `true` if the suspension `x` has + already been forced and did not raise an exception. Otherwise, + it returns `false`. This is useful for checking if a lazy value + has been computed before accessing it. + + ## Examples + ```rescript + let lazyValue = Lazy.make(() => { + // Some expensive computation + Console.log("Computing...") + 42 + }) + Lazy.isEvaluated(lazyValue)->assertEqual(false) + lazyValue->Lazy.get->assertEqual(42) + lazyValue->Lazy.isEvaluated->assertEqual(true) + ``` + */ +let isEvaluated: t<'a> => bool + +exception Undefined + +/** + `force(x)` forces the suspension `x` and returns its result. + If `x` has already been forced, `Lazy.force(x)` returns the + same value again without recomputing it. If it raised an exception, + the same exception is raised again. + Raise `Undefined` if the forcing of `x` tries to force `x` itself + recursively. +*/ +@deprecated("Use `Lazy.get` instead") +let force: t<'a> => 'a + +/** + `force_val(x)` forces the suspension `x` and returns its + result. If `x` has already been forced, `force_val(x)` + returns the same value again without recomputing it. + Raise `Undefined` if the forcing of `x` tries to force `x` itself + recursively. + If the computation of `x` raises an exception, it is unspecified + whether `force_val(x)` raises the same exception or `Undefined`. +*/ +@deprecated("Use `Lazy.get` instead") +let force_val: t<'a> => 'a + +/** + `Lazy.from_fun(f)` creates a lazy value from `f` which is the + computation to be deferred of type `unit => 'a`. + The function returns a lazy value of type `Lazy.t<'a>`. + The computation is not executed until the lazy value is accessed. +*/ +@deprecated("Use `Lazy.make` instead") +let from_fun: (unit => 'a) => t<'a> + +/** + `from_val(v)` returns an already-forced suspension of `v`. + This is for special purposes only. +*/ +@deprecated("Use `Lazy.make` instead") +let from_val: 'a => t<'a> + +/** + `is_val(x)` returns `true` if `x has already been forced and + did not raise an exception. +*/ +@deprecated("Use `Lazy.isEvaluated` instead") +let is_val: t<'a> => bool diff --git a/tests/tests/src/gpr_3697_test.mjs b/tests/tests/src/gpr_3697_test.mjs index c17da8ed66..79d0272225 100644 --- a/tests/tests/src/gpr_3697_test.mjs +++ b/tests/tests/src/gpr_3697_test.mjs @@ -1,18 +1,18 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Lazy from "rescript/lib/es6/Lazy.js"; +import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js"; function fix() { return { TAG: "Fix", - _0: Lazy.from_fun(fix) + _0: Stdlib_Lazy.from_fun(fix) }; } function unfixLeak(_f) { while (true) { let f = _f; - _f = Lazy.force(f._0); + _f = Stdlib_Lazy.force(f._0); continue; }; } @@ -20,7 +20,7 @@ function unfixLeak(_f) { function unfix(p) { while (true) { let h = p.contents; - p.contents = Lazy.force(h._0); + p.contents = Stdlib_Lazy.force(h._0); }; } diff --git a/tests/tests/src/lazy_demo.mjs b/tests/tests/src/lazy_demo.mjs index 494d3f3056..27eaac8217 100644 --- a/tests/tests/src/lazy_demo.mjs +++ b/tests/tests/src/lazy_demo.mjs @@ -1,19 +1,19 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Lazy from "rescript/lib/es6/Lazy.js"; +import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js"; -let lazy1 = Lazy.from_fun(() => { +let lazy1 = Stdlib_Lazy.make(() => { console.log("Hello, lazy"); return 1; }); -let lazy2 = Lazy.from_fun(() => 3); +let lazy2 = Stdlib_Lazy.make(() => 3); console.log(lazy1, lazy2); -let la = Lazy.force(lazy1); +let la = Stdlib_Lazy.get(lazy1); -let lb = Lazy.force(lazy2); +let lb = Stdlib_Lazy.get(lazy2); console.log(la, lb); @@ -23,4 +23,4 @@ export { la, lb, } -/* Not a pure module */ +/* lazy1 Not a pure module */ diff --git a/tests/tests/src/lazy_demo.res b/tests/tests/src/lazy_demo.res index c3e4abc3f1..8c54581145 100644 --- a/tests/tests/src/lazy_demo.res +++ b/tests/tests/src/lazy_demo.res @@ -1,13 +1,13 @@ -let lazy1 = Lazy.from_fun(() => { +let lazy1 = Lazy.make(() => { "Hello, lazy"->Js.log 1 }) -let lazy2 = Lazy.from_fun(() => 3) +let lazy2 = Lazy.make(() => 3) Js.log2(lazy1, lazy2) // can't destructure lazy values -let (la, lb) = (Lazy.force(lazy1), Lazy.force(lazy2)) +let (la, lb) = (Lazy.get(lazy1), Lazy.get(lazy2)) Js.log2(la, lb) diff --git a/tests/tests/src/lazy_test.mjs b/tests/tests/src/lazy_test.mjs index 3a783ea645..4f839dceb9 100644 --- a/tests/tests/src/lazy_test.mjs +++ b/tests/tests/src/lazy_test.mjs @@ -1,19 +1,19 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Mt from "./mt.mjs"; -import * as Lazy from "rescript/lib/es6/Lazy.js"; +import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js"; let u = { contents: 3 }; -let v = Lazy.from_fun(() => { +let v = Stdlib_Lazy.make(() => { u.contents = 32; }); function lazy_test() { let h = u.contents; - Lazy.force(v); + Stdlib_Lazy.get(v); let g = u.contents; return [ h, @@ -25,34 +25,34 @@ let u_v = { contents: 0 }; -let u$1 = Lazy.from_fun(() => { +let u$1 = Stdlib_Lazy.make(() => { u_v.contents = 2; }); -Lazy.force(u$1); +Stdlib_Lazy.get(u$1); -let exotic = Lazy.force; +let exotic = Stdlib_Lazy.get; -let l_from_fun = Lazy.from_fun(() => 3); +let l_from_fun = Stdlib_Lazy.make(() => 3); -let forward_test = Lazy.from_fun(() => { +let forward_test = Stdlib_Lazy.make(() => { let u = 3; u = u + 1 | 0; return u; }); -let f005 = Lazy.from_fun(() => 6); +let f005 = Stdlib_Lazy.make(() => 6); -let f006 = Lazy.from_fun(() => (() => 3)); +let f006 = Stdlib_Lazy.make(() => (() => 3)); -let f007 = Lazy.from_fun(() => { +let f007 = Stdlib_Lazy.make(() => { throw { RE_EXN_ID: "Not_found", Error: new Error() }; }); -let f008 = Lazy.from_fun(() => { +let f008 = Stdlib_Lazy.make(() => { console.log("hi"); throw { RE_EXN_ID: "Not_found", @@ -60,19 +60,19 @@ let f008 = Lazy.from_fun(() => { }; }); -let a2 = Lazy.from_val; +let a2 = Stdlib_Lazy.from_val; -let a3 = Lazy.from_val(3); +let a3 = Stdlib_Lazy.from_val(3); -let a4 = Lazy.from_val(3); +let a4 = Stdlib_Lazy.from_val(3); -let a5 = Lazy.from_val(undefined); +let a5 = Stdlib_Lazy.from_val(undefined); -let a6 = Lazy.from_val(); +let a6 = Stdlib_Lazy.from_val(); -let a7 = Lazy.force(a5); +let a7 = Stdlib_Lazy.get(a5); -let a8 = Lazy.force(a6); +let a8 = Stdlib_Lazy.get(a6); Mt.from_pair_suites("Lazy_test", { hd: [ @@ -100,7 +100,7 @@ Mt.from_pair_suites("Lazy_test", { "lazy_from_fun", () => ({ TAG: "Eq", - _0: Lazy.force(l_from_fun), + _0: Stdlib_Lazy.get(l_from_fun), _1: 3 }) ], @@ -109,7 +109,7 @@ Mt.from_pair_suites("Lazy_test", { "lazy_from_val", () => ({ TAG: "Eq", - _0: Lazy.force(Lazy.from_val(3)), + _0: Stdlib_Lazy.get(Stdlib_Lazy.from_val(3)), _1: 3 }) ], @@ -118,7 +118,7 @@ Mt.from_pair_suites("Lazy_test", { "lazy_from_val2", () => ({ TAG: "Eq", - _0: Lazy.force(Lazy.force(Lazy.from_val(Lazy.from_fun(() => 3)))), + _0: Stdlib_Lazy.get(Stdlib_Lazy.get(Stdlib_Lazy.from_val(Stdlib_Lazy.make(() => 3)))), _1: 3 }) ], @@ -129,7 +129,7 @@ Mt.from_pair_suites("Lazy_test", { debugger; return { TAG: "Eq", - _0: Lazy.force(Lazy.force(Lazy.from_val(forward_test))), + _0: Stdlib_Lazy.get(Stdlib_Lazy.get(Stdlib_Lazy.make(() => forward_test))), _1: 4 }; } @@ -166,7 +166,7 @@ Mt.from_pair_suites("Lazy_test", { "File \"lazy_test.res\", line 95, characters 7-14", () => ({ TAG: "Ok", - _0: Lazy.is_val(Lazy.from_val(3)) + _0: Stdlib_Lazy.isEvaluated(Stdlib_Lazy.from_val(3)) }) ], tl: { @@ -174,7 +174,7 @@ Mt.from_pair_suites("Lazy_test", { "File \"lazy_test.res\", line 96, characters 7-14", () => ({ TAG: "Ok", - _0: !Lazy.is_val(Lazy.from_fun(() => { + _0: !Stdlib_Lazy.isEvaluated(Stdlib_Lazy.make(() => { throw { RE_EXN_ID: "Not_found", Error: new Error() @@ -215,4 +215,4 @@ export { a7, a8, } -/* Not a pure module */ +/* v Not a pure module */ diff --git a/tests/tests/src/lazy_test.res b/tests/tests/src/lazy_test.res index d6c0f23079..a5a9d59c4b 100644 --- a/tests/tests/src/lazy_test.res +++ b/tests/tests/src/lazy_test.res @@ -1,10 +1,10 @@ let u = ref(3) -let v = Lazy.from_fun(() => u := 32) +let v = Lazy.make(() => u := 32) let lazy_test = () => { let h = u.contents let g = { - Lazy.force(v) + Lazy.get(v) u.contents } (h, g) @@ -24,36 +24,36 @@ let lazy_test = () => { // let set_false = lazy (s := None) let u_v = ref(0) -let u = Lazy.from_fun(() => u_v := 2) -let () = Lazy.force(u) +let u = Lazy.make(() => u_v := 2) +let () = Lazy.get(u) /* module Mt = Mock_mt */ let exotic = x => switch x { /* Lazy in a pattern. (used in advi) */ - | y => Lazy.force(y) + | y => Lazy.get(y) } /* let l_from_val = Lazy.from_val 3 */ -let l_from_fun = Lazy.from_fun(_ => 3) -let forward_test = Lazy.from_fun(() => { +let l_from_fun = Lazy.make(_ => 3) +let forward_test = Lazy.make(() => { let u = ref(3) incr(u) u.contents }) /* module Mt = Mock_mt */ -let f005 = Lazy.from_fun(() => 1 + 2 + 3) +let f005 = Lazy.make(() => 1 + 2 + 3) -let f006: Lazy.t int> = Lazy.from_fun(() => { +let f006: Lazy.t int> = Lazy.make(() => { let x = 3 _ => x }) -let f007 = Lazy.from_fun(() => raise(Not_found)) -let f008 = Lazy.from_fun(() => { +let f007 = Lazy.make(() => raise(Not_found)) +let f008 = Lazy.make(() => { Js.log("hi") raise(Not_found) }) @@ -65,8 +65,8 @@ let a4 = a2(3) let a5 = Lazy.from_val(None) let a6 = Lazy.from_val() -let a7 = Lazy.force(a5) -let a8 = Lazy.force(a6) +let a7 = Lazy.get(a5) +let a8 = Lazy.get(a6) Mt.from_pair_suites( __MODULE__, @@ -76,15 +76,15 @@ Mt.from_pair_suites( ("simple", _ => Eq(lazy_test(), (3, 32))), // ("lazy_match", _ => Eq(h, 2)), ("lazy_force", _ => Eq(u_v.contents, 2)), - ("lazy_from_fun", _ => Eq(Lazy.force(l_from_fun), 3)), - ("lazy_from_val", _ => Eq(Lazy.force(Lazy.from_val(3)), 3)), - ("lazy_from_val2", _ => Eq(Lazy.force(Lazy.force(Lazy.from_val(Lazy.from_fun(() => 3)))), 3)), + ("lazy_from_fun", _ => Eq(Lazy.get(l_from_fun), 3)), + ("lazy_from_val", _ => Eq(Lazy.get(Lazy.from_val(3)), 3)), + ("lazy_from_val2", _ => Eq(Lazy.get(Lazy.get(Lazy.from_val(Lazy.make(() => 3)))), 3)), ( "lazy_from_val3", _ => Eq( { %debugger - Lazy.force(Lazy.force(Lazy.from_val(forward_test))) + Lazy.get(Lazy.get(Lazy.make(() => forward_test))) }, 4, ), @@ -92,8 +92,8 @@ Mt.from_pair_suites( (__FILE__, _ => Eq(a3, a4)), (__FILE__, _ => Eq(a7, None)), (__FILE__, _ => Eq(a8, ())), - (__LOC__, _ => Ok(Lazy.is_val(Lazy.from_val(3)))), - (__LOC__, _ => Ok(!Lazy.is_val(Lazy.from_fun(() => raise(Not_found))))), + (__LOC__, _ => Ok(Lazy.isEvaluated(Lazy.from_val(3)))), + (__LOC__, _ => Ok(!Lazy.isEvaluated(Lazy.make(() => raise(Not_found))))), } }, ) diff --git a/tests/tests/src/mpr_6033_test.mjs b/tests/tests/src/mpr_6033_test.mjs index 70d3e5036c..d72f10e116 100644 --- a/tests/tests/src/mpr_6033_test.mjs +++ b/tests/tests/src/mpr_6033_test.mjs @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Mt from "./mt.mjs"; -import * as Lazy from "rescript/lib/es6/Lazy.js"; +import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js"; let suites = { contents: /* [] */0 @@ -27,14 +27,14 @@ function eq(loc, x, y) { } function f(x) { - return Lazy.force(x) + "abc"; + return Stdlib_Lazy.get(x) + "abc"; } -let x = Lazy.from_fun(() => "def"); +let x = Stdlib_Lazy.from_fun(() => "def"); -Lazy.force(x); +Stdlib_Lazy.get(x); -let u = Lazy.force(x) + "abc"; +let u = Stdlib_Lazy.get(x) + "abc"; eq("File \"mpr_6033_test.res\", line 23, characters 3-10", u, "defabc"); diff --git a/tests/tests/src/mpr_6033_test.res b/tests/tests/src/mpr_6033_test.res index dffaa74957..6a39e09a1a 100644 --- a/tests/tests/src/mpr_6033_test.res +++ b/tests/tests/src/mpr_6033_test.res @@ -11,12 +11,12 @@ let eq = (loc, x, y) => { let f = x => switch x { - | y => Lazy.force(y) ++ "abc" + | y => Lazy.get(y) ++ "abc" } let u = { let x = Lazy.from_fun(() => "def") - ignore(Lazy.force(x)) + ignore(Lazy.get(x)) f(x) } diff --git a/tests/tests/src/recursive_module.mjs b/tests/tests/src/recursive_module.mjs index e2bb2a6fb3..21bedb6ef6 100644 --- a/tests/tests/src/recursive_module.mjs +++ b/tests/tests/src/recursive_module.mjs @@ -1,7 +1,7 @@ // Generated by ReScript, PLEASE EDIT WITH CARE import * as Mt from "./mt.mjs"; -import * as Lazy from "rescript/lib/es6/Lazy.js"; +import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js"; import * as Primitive_module from "rescript/lib/es6/Primitive_module.js"; import * as Primitive_exceptions from "rescript/lib/es6/Primitive_exceptions.js"; @@ -65,7 +65,7 @@ let Intb = Primitive_module.init([ ]] }); -let a = Lazy.from_fun(() => Lazy.force(Intb.a)); +let a = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Intb.a)); Primitive_module.update({ TAG: "Module", @@ -77,7 +77,7 @@ Primitive_module.update({ a: a }); -let a$1 = Lazy.from_fun(() => Lazy.force(Inta.a) + 1 | 0); +let a$1 = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Inta.a) + 1 | 0); Primitive_module.update({ TAG: "Module", @@ -92,10 +92,10 @@ Primitive_module.update({ let tmp; try { - tmp = Lazy.force(Intb.a); + tmp = Stdlib_Lazy.get(Intb.a); } catch (raw_exn) { let exn = Primitive_exceptions.internalToException(raw_exn); - if (exn.RE_EXN_ID === Lazy.Undefined) { + if (exn.RE_EXN_ID === Stdlib_Lazy.Undefined) { tmp = -1; } else { throw exn; @@ -128,7 +128,7 @@ let Intb$1 = Primitive_module.init([ ]] }); -let a$2 = Lazy.from_fun(() => Lazy.force(Intb$1.a) + 1 | 0); +let a$2 = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Intb$1.a) + 1 | 0); Primitive_module.update({ TAG: "Module", @@ -140,7 +140,7 @@ Primitive_module.update({ a: a$2 }); -let a$3 = Lazy.from_fun(() => 2); +let a$3 = Stdlib_Lazy.make(() => 2); Primitive_module.update({ TAG: "Module", @@ -157,7 +157,7 @@ let A = { Intb: Intb$1 }; -eq("File \"recursive_module.res\", line 59, characters 3-10", Lazy.force(Inta$1.a), 3); +eq("File \"recursive_module.res\", line 59, characters 3-10", Stdlib_Lazy.get(Inta$1.a), 3); let tmp$1; diff --git a/tests/tests/src/recursive_module.res b/tests/tests/src/recursive_module.res index 4f7f941bea..53226f2f38 100644 --- a/tests/tests/src/recursive_module.res +++ b/tests/tests/src/recursive_module.res @@ -27,36 +27,36 @@ module rec Int3: { module rec Inta: { let a: Lazy.t } = { - let a = Lazy.from_fun(() => Lazy.force(Intb.a)) + let a = Lazy.make(() => Lazy.get(Intb.a)) } and Intb: { let a: Lazy.t } = { - let a = Lazy.from_fun(() => Lazy.force(Inta.a) + 1) + let a = Lazy.make(() => Lazy.get(Inta.a) + 1) } eq( __LOC__, -1, - try Lazy.force(Intb.a) catch { + try Lazy.get(Intb.a) catch { | Lazy.Undefined => -1 }, ) module A = { module rec Inta: { - let a: lazy_t + let a: Lazy.t } = { - let a = Lazy.from_fun(() => Lazy.force(Intb.a) + 1) + let a = Lazy.make(() => Lazy.get(Intb.a) + 1) } and Intb: { - let a: lazy_t + let a: Lazy.t } = { - let a = Lazy.from_fun(() => 2) + let a = Lazy.make(() => 2) } } -eq(__LOC__, Lazy.force(A.Inta.a), 3) +eq(__LOC__, Lazy.get(A.Inta.a), 3) /* expect raise Undefined_recursive_module */ eq( __LOC__, diff --git a/tests/tests/src/test_primitive.mjs b/tests/tests/src/test_primitive.mjs index c5788bdeb9..ee482e3817 100644 --- a/tests/tests/src/test_primitive.mjs +++ b/tests/tests/src/test_primitive.mjs @@ -1,6 +1,6 @@ // Generated by ReScript, PLEASE EDIT WITH CARE -import * as Lazy from "rescript/lib/es6/Lazy.js"; +import * as Stdlib_Lazy from "rescript/lib/es6/Stdlib_Lazy.js"; function a4(prim) { return [ @@ -69,7 +69,7 @@ function f(x) { return x.length; } -let is_lazy_force = Lazy.force; +let is_lazy_force = Stdlib_Lazy.get; function fib(n) { if (n === 0 || n === 1) { diff --git a/tests/tests/src/test_primitive.res b/tests/tests/src/test_primitive.res index 0e39ee35a7..0dbf11eb84 100644 --- a/tests/tests/src/test_primitive.res +++ b/tests/tests/src/test_primitive.res @@ -85,7 +85,7 @@ let gg = x => x.u = 0. let f = (x: string) => String.length(x) -let is_lazy_force = x => Lazy.force(x) +let is_lazy_force = x => Lazy.get(x) let rec fib = (n: int) => switch n {