diff --git a/compiler/ml/predef.ml b/compiler/ml/predef.ml
index 4f23f6b02b..5913791eff 100644
--- a/compiler/ml/predef.ml
+++ b/compiler/ml/predef.ml
@@ -53,8 +53,6 @@ and ident_dict = ident_create "dict"
and ident_bigint = ident_create "bigint"
-and ident_lazy_t = ident_create "lazy_t"
-
and ident_string = ident_create "string"
and ident_extension_constructor = ident_create "extension_constructor"
@@ -98,8 +96,6 @@ and path_dict = Pident ident_dict
and path_bigint = Pident ident_bigint
-and path_lazy_t = Pident ident_lazy_t
-
and path_string = Pident ident_string
and path_unkonwn = Pident ident_unknown
@@ -132,8 +128,6 @@ and type_dict t = newgenty (Tconstr (path_dict, [t], ref Mnil))
and type_bigint = newgenty (Tconstr (path_bigint, [], ref Mnil))
-and type_lazy_t t = newgenty (Tconstr (path_lazy_t, [t], ref Mnil))
-
and type_string = newgenty (Tconstr (path_string, [], ref Mnil))
and type_unknown = newgenty (Tconstr (path_unkonwn, [], ref Mnil))
@@ -332,14 +326,6 @@ let common_initial_env add_type add_extension empty_env =
];
type_unboxed = Types.unboxed_true_default_false;
}
- and decl_lazy_t =
- let tvar = newgenvar () in
- {
- decl_abstr with
- type_params = [tvar];
- type_arity = 1;
- type_variance = [Variance.covariant];
- }
and decl_promise =
let tvar = newgenvar () in
{
@@ -381,7 +367,6 @@ let common_initial_env add_type add_extension empty_env =
|> add_type ident_exn decl_exn
|> add_type ident_option decl_option
|> add_type ident_result decl_result
- |> add_type ident_lazy_t decl_lazy_t
|> add_type ident_promise decl_promise
|> add_type ident_array decl_array
|> add_type ident_list decl_list
diff --git a/compiler/ml/predef.mli b/compiler/ml/predef.mli
index 7fc7243f72..8e3330fe43 100644
--- a/compiler/ml/predef.mli
+++ b/compiler/ml/predef.mli
@@ -31,7 +31,6 @@ val type_result : type_expr -> type_expr -> type_expr
val type_dict : type_expr -> type_expr
val type_bigint : type_expr
-val type_lazy_t : type_expr -> type_expr
val type_extension_constructor : type_expr
val path_int : Path.t
@@ -48,7 +47,6 @@ val path_result : Path.t
val path_dict : Path.t
val path_bigint : Path.t
-val path_lazy_t : Path.t
val path_extension_constructor : Path.t
val path_promise : Path.t
diff --git a/compiler/ml/transl_recmodule.ml b/compiler/ml/transl_recmodule.ml
index 17aa511aa2..6b89d29bb7 100644
--- a/compiler/ml/transl_recmodule.ml
+++ b/compiler/ml/transl_recmodule.ml
@@ -66,16 +66,6 @@ let init_shape modl =
non_const = cstr_non_const;
attrs = [];
} )
- | {desc = Tconstr (p, _, _)} when Path.same p Predef.path_lazy_t ->
- Const_pointer
- ( 1,
- Pt_constructor
- {
- name = "Lazy";
- const = cstr_const;
- non_const = cstr_non_const;
- attrs = [];
- } )
| _ -> raise Not_found
in
add_name init_v id :: init_shape_struct env rem
diff --git a/compiler/ml/typeopt.ml b/compiler/ml/typeopt.ml
index a1e5e4fabd..0118d6e4d4 100644
--- a/compiler/ml/typeopt.ml
+++ b/compiler/ml/typeopt.ml
@@ -42,7 +42,7 @@ let rec type_cannot_contain_undefined (typ : Types.type_expr) (env : Env.t) =
| Tconstr (p, _, _) -> (
(* all built in types could not inhabit none-like values:
int, char, float, bool, unit, exn, array, list, nativeint,
- int32, int64, lazy_t, bytes
+ int32, int64, bytes
*)
match Predef.type_is_builtin_path_but_option p with
| For_sure_yes -> true
diff --git a/lib/es6/Primitive_lazy.js b/lib/es6/Primitive_lazy.js
deleted file mode 100644
index ce26b62bf1..0000000000
--- a/lib/es6/Primitive_lazy.js
+++ /dev/null
@@ -1,74 +0,0 @@
-
-
-import * as Primitive_exceptions from "./Primitive_exceptions.js";
-
-function is_val(l) {
- return l.LAZY_DONE;
-}
-
-let Undefined = /* @__PURE__ */Primitive_exceptions.create("Primitive_lazy.Undefined");
-
-function forward_with_closure(blk, closure) {
- let result = closure();
- blk.VAL = result;
- blk.LAZY_DONE = true;
- return result;
-}
-
-function raise_undefined() {
- throw {
- RE_EXN_ID: Undefined,
- Error: new Error()
- };
-}
-
-function force(lzv) {
- if (lzv.LAZY_DONE) {
- return lzv.VAL;
- } else {
- let closure = lzv.VAL;
- lzv.VAL = raise_undefined;
- try {
- return forward_with_closure(lzv, closure);
- } catch (e) {
- lzv.VAL = () => {
- throw e;
- };
- throw e;
- }
- }
-}
-
-function force_val(lzv) {
- if (lzv.LAZY_DONE) {
- return lzv.VAL;
- } else {
- let closure = lzv.VAL;
- lzv.VAL = raise_undefined;
- return forward_with_closure(lzv, closure);
- }
-}
-
-function from_fun(closure) {
- return {
- LAZY_DONE: false,
- VAL: closure
- };
-}
-
-function from_val(value) {
- return {
- LAZY_DONE: true,
- VAL: value
- };
-}
-
-export {
- Undefined,
- force,
- force_val,
- from_fun,
- from_val,
- is_val,
-}
-/* No side effect */
diff --git a/lib/es6/Stdlib.js b/lib/es6/Stdlib.js
index bbb1fc648d..8eb78b0f8b 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",
- 122,
+ 124,
4
],
Error: new Error()
diff --git a/lib/es6/Stdlib_Lazy.js b/lib/es6/Stdlib_Lazy.js
index 211047999f..cc92e4c606 100644
--- a/lib/es6/Stdlib_Lazy.js
+++ b/lib/es6/Stdlib_Lazy.js
@@ -1,24 +1,73 @@
-import * as Primitive_lazy from "./Primitive_lazy.js";
+import * as Primitive_exceptions from "./Primitive_exceptions.js";
-let make = Primitive_lazy.from_fun;
+function is_val(l) {
+ return l.LAZY_DONE;
+}
-let get = Primitive_lazy.force;
+let Undefined = /* @__PURE__ */Primitive_exceptions.create("Stdlib_Lazy.Undefined");
-let isEvaluated = Primitive_lazy.is_val;
+function forward_with_closure(blk, closure) {
+ let result = closure();
+ blk.VAL = result;
+ blk.LAZY_DONE = true;
+ return result;
+}
-let Undefined = Primitive_lazy.Undefined;
+function raise_undefined() {
+ throw {
+ RE_EXN_ID: Undefined,
+ Error: new Error()
+ };
+}
-let force = Primitive_lazy.force;
+function force(lzv) {
+ if (lzv.LAZY_DONE) {
+ return lzv.VAL;
+ } else {
+ let closure = lzv.VAL;
+ lzv.VAL = raise_undefined;
+ try {
+ return forward_with_closure(lzv, closure);
+ } catch (e) {
+ lzv.VAL = () => {
+ throw e;
+ };
+ throw e;
+ }
+ }
+}
-let force_val = Primitive_lazy.force_val;
+function force_val(lzv) {
+ if (lzv.LAZY_DONE) {
+ return lzv.VAL;
+ } else {
+ let closure = lzv.VAL;
+ lzv.VAL = raise_undefined;
+ return forward_with_closure(lzv, closure);
+ }
+}
+
+function from_fun(closure) {
+ return {
+ LAZY_DONE: false,
+ VAL: closure
+ };
+}
+
+function from_val(value) {
+ return {
+ LAZY_DONE: true,
+ VAL: value
+ };
+}
-let from_fun = Primitive_lazy.from_fun;
+let make = from_fun;
-let from_val = Primitive_lazy.from_val;
+let get = force;
-let is_val = Primitive_lazy.is_val;
+let isEvaluated = is_val;
export {
make,
diff --git a/lib/js/Primitive_lazy.js b/lib/js/Primitive_lazy.js
deleted file mode 100644
index 960a752a87..0000000000
--- a/lib/js/Primitive_lazy.js
+++ /dev/null
@@ -1,72 +0,0 @@
-'use strict';
-
-let Primitive_exceptions = require("./Primitive_exceptions.js");
-
-function is_val(l) {
- return l.LAZY_DONE;
-}
-
-let Undefined = /* @__PURE__ */Primitive_exceptions.create("Primitive_lazy.Undefined");
-
-function forward_with_closure(blk, closure) {
- let result = closure();
- blk.VAL = result;
- blk.LAZY_DONE = true;
- return result;
-}
-
-function raise_undefined() {
- throw {
- RE_EXN_ID: Undefined,
- Error: new Error()
- };
-}
-
-function force(lzv) {
- if (lzv.LAZY_DONE) {
- return lzv.VAL;
- } else {
- let closure = lzv.VAL;
- lzv.VAL = raise_undefined;
- try {
- return forward_with_closure(lzv, closure);
- } catch (e) {
- lzv.VAL = () => {
- throw e;
- };
- throw e;
- }
- }
-}
-
-function force_val(lzv) {
- if (lzv.LAZY_DONE) {
- return lzv.VAL;
- } else {
- let closure = lzv.VAL;
- lzv.VAL = raise_undefined;
- return forward_with_closure(lzv, closure);
- }
-}
-
-function from_fun(closure) {
- return {
- LAZY_DONE: false,
- VAL: closure
- };
-}
-
-function from_val(value) {
- return {
- LAZY_DONE: true,
- VAL: value
- };
-}
-
-exports.Undefined = Undefined;
-exports.force = force;
-exports.force_val = force_val;
-exports.from_fun = from_fun;
-exports.from_val = from_val;
-exports.is_val = is_val;
-/* No side effect */
diff --git a/lib/js/Stdlib.js b/lib/js/Stdlib.js
index 283c1d3303..7f7d377f06 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",
- 122,
+ 124,
4
],
Error: new Error()
diff --git a/lib/js/Stdlib_Lazy.js b/lib/js/Stdlib_Lazy.js
index 48b7e8a581..1164f09627 100644
--- a/lib/js/Stdlib_Lazy.js
+++ b/lib/js/Stdlib_Lazy.js
@@ -1,24 +1,73 @@
'use strict';
-let Primitive_lazy = require("./Primitive_lazy.js");
+let Primitive_exceptions = require("./Primitive_exceptions.js");
-let make = Primitive_lazy.from_fun;
+function is_val(l) {
+ return l.LAZY_DONE;
+}
-let get = Primitive_lazy.force;
+let Undefined = /* @__PURE__ */Primitive_exceptions.create("Stdlib_Lazy.Undefined");
-let isEvaluated = Primitive_lazy.is_val;
+function forward_with_closure(blk, closure) {
+ let result = closure();
+ blk.VAL = result;
+ blk.LAZY_DONE = true;
+ return result;
+}
-let Undefined = Primitive_lazy.Undefined;
+function raise_undefined() {
+ throw {
+ RE_EXN_ID: Undefined,
+ Error: new Error()
+ };
+}
-let force = Primitive_lazy.force;
+function force(lzv) {
+ if (lzv.LAZY_DONE) {
+ return lzv.VAL;
+ } else {
+ let closure = lzv.VAL;
+ lzv.VAL = raise_undefined;
+ try {
+ return forward_with_closure(lzv, closure);
+ } catch (e) {
+ lzv.VAL = () => {
+ throw e;
+ };
+ throw e;
+ }
+ }
+}
-let force_val = Primitive_lazy.force_val;
+function force_val(lzv) {
+ if (lzv.LAZY_DONE) {
+ return lzv.VAL;
+ } else {
+ let closure = lzv.VAL;
+ lzv.VAL = raise_undefined;
+ return forward_with_closure(lzv, closure);
+ }
+}
-let from_fun = Primitive_lazy.from_fun;
+function from_fun(closure) {
+ return {
+ LAZY_DONE: false,
+ VAL: closure
+ };
+}
-let from_val = Primitive_lazy.from_val;
+function from_val(value) {
+ return {
+ LAZY_DONE: true,
+ VAL: value
+ };
+}
-let is_val = Primitive_lazy.is_val;
+let make = from_fun;
+
+let get = force;
+
+let isEvaluated = is_val;
exports.make = make;
exports.get = get;
diff --git a/packages/artifacts.txt b/packages/artifacts.txt
index c7f9d8eeca..387548ef0c 100644
--- a/packages/artifacts.txt
+++ b/packages/artifacts.txt
@@ -116,7 +116,6 @@ lib/es6/Primitive_hash.js
lib/es6/Primitive_int.js
lib/es6/Primitive_int_extern.js
lib/es6/Primitive_js_extern.js
-lib/es6/Primitive_lazy.js
lib/es6/Primitive_module.js
lib/es6/Primitive_object.js
lib/es6/Primitive_object_extern.js
@@ -291,7 +290,6 @@ lib/js/Primitive_hash.js
lib/js/Primitive_int.js
lib/js/Primitive_int_extern.js
lib/js/Primitive_js_extern.js
-lib/js/Primitive_lazy.js
lib/js/Primitive_module.js
lib/js/Primitive_object.js
lib/js/Primitive_object_extern.js
@@ -869,12 +867,6 @@ lib/ocaml/Primitive_js_extern.cmi
lib/ocaml/Primitive_js_extern.cmj
lib/ocaml/Primitive_js_extern.cmt
lib/ocaml/Primitive_js_extern.res
-lib/ocaml/Primitive_lazy.cmi
-lib/ocaml/Primitive_lazy.cmj
-lib/ocaml/Primitive_lazy.cmt
-lib/ocaml/Primitive_lazy.cmti
-lib/ocaml/Primitive_lazy.res
-lib/ocaml/Primitive_lazy.resi
lib/ocaml/Primitive_module.cmi
lib/ocaml/Primitive_module.cmj
lib/ocaml/Primitive_module.cmt
diff --git a/runtime/Primitive_lazy.res b/runtime/Primitive_lazy.res
deleted file mode 100644
index f77595bb1f..0000000000
--- a/runtime/Primitive_lazy.res
+++ /dev/null
@@ -1,109 +0,0 @@
-/* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript
- *
- * 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, either version 3 of the License, or
- * (at your option) any later version.
- *
- * In addition to the permissions granted to you by the LGPL, you may combine
- * or link a "work that uses the Library" with a publicly distributed version
- * of this file to produce a combined library or application, then distribute
- * that combined work under the terms of your choosing, with no requirement
- * to comply with the obligations normally placed on you by section 4 of the
- * LGPL version 3 (or the corresponding section of a later version of the LGPL
- * should you choose to use a 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. */
-
-@@config({flags: ["-bs-no-cross-module-opt"]})
-
-/* Internals of forcing lazy values. */
-type t<'a> = {
- @as("LAZY_DONE") mutable tag: bool,
- /* Invariant: name */
- @as("VAL") mutable value: 'a,
- /* its type is ['a] or [unit -> 'a ] */
-}
-
-%%private(external fnToVal: (unit => 'a) => 'a = "%identity")
-%%private(external valToFn: 'a => unit => 'a = "%identity")
-%%private(external castToConcrete: lazy_t<'a> => t<'a> = "%identity")
-%%private(external castFromConcrete: t<'a> => lazy_t<'a> = "%identity")
-
-let is_val = (type a, l: lazy_t): bool => castToConcrete(l).tag
-
-exception Undefined
-
-%%private(
- let forward_with_closure = (type a, blk: t, closure: unit => a): a => {
- let result = closure()
- blk.value = result
- blk.tag = true
- result
- }
-)
-
-%%private(let raise_undefined = () => throw(Undefined))
-
-/* Assume [blk] is a block with tag lazy */
-%%private(
- let force_lazy_block = (type a, blk: t): a => {
- let closure = valToFn(blk.value)
- blk.value = fnToVal(raise_undefined)
- try forward_with_closure(blk, closure) catch {
- | e =>
- blk.value = fnToVal(() => throw(e))
- throw(e)
- }
- }
-)
-
-/* Assume [blk] is a block with tag lazy */
-%%private(
- let force_val_lazy_block = (type a, blk: t): a => {
- let closure = valToFn(blk.value)
- blk.value = fnToVal(raise_undefined)
- forward_with_closure(blk, closure)
- }
-)
-
-let force = (type a, lzv: lazy_t): a => {
- let lzv: t<_> = castToConcrete(lzv)
- if lzv.tag {
- lzv.value
- } else {
- force_lazy_block(lzv)
- }
-}
-
-let force_val = (type a, lzv: lazy_t): a => {
- let lzv: t<_> = castToConcrete(lzv)
- if lzv.tag {
- lzv.value
- } else {
- force_val_lazy_block(lzv)
- }
-}
-
-let from_fun = (type a, closure: unit => a): lazy_t => {
- let blk = {
- tag: false,
- value: fnToVal(closure),
- }
- castFromConcrete(blk)
-}
-
-let from_val = (type a, value: a): lazy_t => {
- let blk = {
- tag: true,
- value,
- }
- castFromConcrete(blk)
-}
diff --git a/runtime/Primitive_lazy.resi b/runtime/Primitive_lazy.resi
deleted file mode 100644
index bfcd2fa211..0000000000
--- a/runtime/Primitive_lazy.resi
+++ /dev/null
@@ -1,39 +0,0 @@
-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: lazy_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: lazy_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) => lazy_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 => lazy_t<'a>
-
-/** [is_val x] returns [true] if [x] has already been forced and
- did not raise an exception.
-*/
-let is_val: lazy_t<'a> => bool
diff --git a/runtime/Stdlib.res b/runtime/Stdlib.res
index f020f0d5aa..d13d57685d 100644
--- a/runtime/Stdlib.res
+++ b/runtime/Stdlib.res
@@ -57,6 +57,8 @@ type date = Date.t
type null<+'a> = Primitive_js_extern.null<'a>
type undefined<+'a> = Primitive_js_extern.undefined<'a>
type nullable<+'a> = Primitive_js_extern.nullable<'a>
+@deprecated("Use Lazy.t instead")
+type lazy_t<+'a> = Lazy.t<'a>
@deprecated("Use rescript-webapi instead") @val external window: Dom.window = "window"
@deprecated("Use rescript-webapi instead") @val external document: Dom.document = "document"
diff --git a/runtime/Stdlib_Lazy.res b/runtime/Stdlib_Lazy.res
index d92a7b3b0c..084241c967 100644
--- a/runtime/Stdlib_Lazy.res
+++ b/runtime/Stdlib_Lazy.res
@@ -1,19 +1,107 @@
-type t<'a> = lazy_t<'a>
+/* Copyright (C) 2017 Hongbo Zhang, Authors of ReScript
+ *
+ * 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, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * In addition to the permissions granted to you by the LGPL, you may combine
+ * or link a "work that uses the Library" with a publicly distributed version
+ * of this file to produce a combined library or application, then distribute
+ * that combined work under the terms of your choosing, with no requirement
+ * to comply with the obligations normally placed on you by section 4 of the
+ * LGPL version 3 (or the corresponding section of a later version of the LGPL
+ * should you choose to use a 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. */
-exception Undefined = Primitive_lazy.Undefined
+type t<+'a>
-let make = Primitive_lazy.from_fun
+/* Internals of forcing lazy values. */
+type internal<'a> = {
+ @as("LAZY_DONE") mutable tag: bool,
+ /* Invariant: name */
+ @as("VAL") mutable value: 'a,
+ /* its type is ['a] or [unit -> 'a ] */
+}
-let get = Primitive_lazy.force
+external fnToVal: (unit => 'a) => 'a = "%identity"
+external valToFn: 'a => unit => 'a = "%identity"
+external castToConcrete: t<'a> => internal<'a> = "%identity"
+external castFromConcrete: internal<'a> => t<'a> = "%identity"
-let isEvaluated = Primitive_lazy.is_val
+let is_val = (type a, l: t): bool => castToConcrete(l).tag
-let force = Primitive_lazy.force
+exception Undefined
-let force_val = Primitive_lazy.force_val
+let forward_with_closure = (type a, blk: internal, closure: unit => a): a => {
+ let result = closure()
+ blk.value = result
+ blk.tag = true
+ result
+}
-let from_fun = Primitive_lazy.from_fun
+let raise_undefined = () => throw(Undefined)
-let from_val = Primitive_lazy.from_val
+/* Assume [blk] is a block with tag lazy */
+let force_lazy_block = (type a, blk: internal): a => {
+ let closure = valToFn(blk.value)
+ blk.value = fnToVal(raise_undefined)
+ try forward_with_closure(blk, closure) catch {
+ | e =>
+ blk.value = fnToVal(() => throw(e))
+ throw(e)
+ }
+}
-let is_val = Primitive_lazy.is_val
+/* Assume [blk] is a block with tag lazy */
+let force_val_lazy_block = (type a, blk: internal): a => {
+ let closure = valToFn(blk.value)
+ blk.value = fnToVal(raise_undefined)
+ forward_with_closure(blk, closure)
+}
+
+let force = (type a, lzv: t): a => {
+ let lzv: internal<_> = castToConcrete(lzv)
+ if lzv.tag {
+ lzv.value
+ } else {
+ force_lazy_block(lzv)
+ }
+}
+
+let force_val = (type a, lzv: t): a => {
+ let lzv: internal<_> = castToConcrete(lzv)
+ if lzv.tag {
+ lzv.value
+ } else {
+ force_val_lazy_block(lzv)
+ }
+}
+
+let from_fun = (type a, closure: unit => a): t => {
+ let blk = {
+ tag: false,
+ value: fnToVal(closure),
+ }
+ castFromConcrete(blk)
+}
+
+let from_val = (type a, value: a): t => {
+ let blk = {
+ tag: true,
+ value,
+ }
+ castFromConcrete(blk)
+}
+
+let make = from_fun
+let get = force
+let isEvaluated = is_val
diff --git a/runtime/Stdlib_Lazy.resi b/runtime/Stdlib_Lazy.resi
index 9c70483be6..624a39441c 100644
--- a/runtime/Stdlib_Lazy.resi
+++ b/runtime/Stdlib_Lazy.resi
@@ -12,7 +12,8 @@
subsequent accesses. If the computation raises an exception,
the same exception is raised again on subsequent accesses.
*/
-type t<'a> = lazy_t<'a>
+@notUndefined
+type t<+'a>
/**
`Lazy.make(f)` creates a lazy value from `f` which is the
diff --git a/tests/tests/src/recursive_module.mjs b/tests/tests/src/recursive_module.mjs
index 21bedb6ef6..59014aca93 100644
--- a/tests/tests/src/recursive_module.mjs
+++ b/tests/tests/src/recursive_module.mjs
@@ -41,139 +41,40 @@ Primitive_module.update({
]]
}, Int3, Int3);
-let Inta = Primitive_module.init([
- "recursive_module.res",
- 29,
- 4
-], {
- TAG: "Module",
- _0: [[
- "Lazy",
- "a"
- ]]
-});
-
-let Intb = Primitive_module.init([
- "recursive_module.res",
- 34,
- 4
-], {
- TAG: "Module",
- _0: [[
- "Lazy",
- "a"
- ]]
-});
-
-let a = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Intb.a));
+let a = Stdlib_Lazy.make(() => 2);
-Primitive_module.update({
- TAG: "Module",
- _0: [[
- "Lazy",
- "a"
- ]]
-}, Inta, {
+let Intb = {
a: a
-});
+};
-let a$1 = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Inta.a) + 1 | 0);
+let a$1 = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Intb.a) + 1 | 0);
-Primitive_module.update({
- TAG: "Module",
- _0: [[
- "Lazy",
- "a"
- ]]
-}, Intb, {
+let Inta = {
a: a$1
-});
-
-let tmp;
-
-try {
- tmp = Stdlib_Lazy.get(Intb.a);
-} catch (raw_exn) {
- let exn = Primitive_exceptions.internalToException(raw_exn);
- if (exn.RE_EXN_ID === Stdlib_Lazy.Undefined) {
- tmp = -1;
- } else {
- throw exn;
- }
-}
-
-eq("File \"recursive_module.res\", line 39, characters 2-9", -1, tmp);
-
-let Inta$1 = Primitive_module.init([
- "recursive_module.res",
- 49,
- 6
-], {
- TAG: "Module",
- _0: [[
- "Lazy",
- "a"
- ]]
-});
-
-let Intb$1 = Primitive_module.init([
- "recursive_module.res",
- 54,
- 6
-], {
- TAG: "Module",
- _0: [[
- "Lazy",
- "a"
- ]]
-});
-
-let a$2 = Stdlib_Lazy.make(() => Stdlib_Lazy.get(Intb$1.a) + 1 | 0);
-
-Primitive_module.update({
- TAG: "Module",
- _0: [[
- "Lazy",
- "a"
- ]]
-}, Inta$1, {
- a: a$2
-});
-
-let a$3 = Stdlib_Lazy.make(() => 2);
-
-Primitive_module.update({
- TAG: "Module",
- _0: [[
- "Lazy",
- "a"
- ]]
-}, Intb$1, {
- a: a$3
-});
+};
let A = {
- Inta: Inta$1,
- Intb: Intb$1
+ Inta: Inta,
+ Intb: Intb
};
-eq("File \"recursive_module.res\", line 59, characters 3-10", Stdlib_Lazy.get(Inta$1.a), 3);
+eq("File \"recursive_module.res\", line 40, characters 3-10", Stdlib_Lazy.get(a$1), 3);
-let tmp$1;
+let tmp;
try {
Int3.u(3);
- tmp$1 = 3;
-} catch (raw_exn$1) {
- let exn$1 = Primitive_exceptions.internalToException(raw_exn$1);
- if (exn$1.RE_EXN_ID === "Undefined_recursive_module") {
- tmp$1 = 4;
+ tmp = 3;
+} catch (raw_exn) {
+ let exn = Primitive_exceptions.internalToException(raw_exn);
+ if (exn.RE_EXN_ID === "Undefined_recursive_module") {
+ tmp = 4;
} else {
- throw exn$1;
+ throw exn;
}
}
-eq("File \"recursive_module.res\", line 62, characters 2-9", 4, tmp$1);
+eq("File \"recursive_module.res\", line 43, characters 2-9", 4, tmp);
Mt.from_pair_suites("Recursive_module", suites.contents);
@@ -189,8 +90,6 @@ export {
Xx,
uuu,
Int3,
- Inta,
- Intb,
A,
}
/* Int3 Not a pure module */
diff --git a/tests/tests/src/recursive_module.res b/tests/tests/src/recursive_module.res
index 53226f2f38..90e8eb215e 100644
--- a/tests/tests/src/recursive_module.res
+++ b/tests/tests/src/recursive_module.res
@@ -24,25 +24,6 @@ module rec Int3: {
let u: int => int
} = Int3
-module rec Inta: {
- let a: Lazy.t
-} = {
- let a = Lazy.make(() => Lazy.get(Intb.a))
-}
-and Intb: {
- let a: Lazy.t
-} = {
- let a = Lazy.make(() => Lazy.get(Inta.a) + 1)
-}
-
-eq(
- __LOC__,
- -1,
- try Lazy.get(Intb.a) catch {
- | Lazy.Undefined => -1
- },
-)
-
module A = {
module rec Inta: {
let a: Lazy.t