Skip to content

lazy_t cleanup part 2 #7484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions compiler/ml/predef.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the difference: type lazy_t<+'a> with the +: covariant.

}
and decl_promise =
let tvar = newgenvar () in
{
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions compiler/ml/predef.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
10 changes: 0 additions & 10 deletions compiler/ml/transl_recmodule.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Copy link
Collaborator

@cristianoc cristianoc May 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what would cause the recursive module test to fail.
I think that's fine, unless the recursive module example - with lazy - pattern is important to support.

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
Expand Down
2 changes: 1 addition & 1 deletion compiler/ml/typeopt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 0 additions & 74 deletions lib/es6/Primitive_lazy.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/es6/Stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function assertEqual(a, b) {
RE_EXN_ID: "Assert_failure",
_1: [
"Stdlib.res",
122,
124,
4
],
Error: new Error()
Expand Down
69 changes: 59 additions & 10 deletions lib/es6/Stdlib_Lazy.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
72 changes: 0 additions & 72 deletions lib/js/Primitive_lazy.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/js/Stdlib.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function assertEqual(a, b) {
RE_EXN_ID: "Assert_failure",
_1: [
"Stdlib.res",
122,
124,
4
],
Error: new Error()
Expand Down
Loading