Skip to content

Commit 59f4237

Browse files
cknittcristianoc
andauthored
lazy_t cleanup part 2 (#7484)
* quick lazy * cleanup 1 * Cleanup 2 * Add Stdlib.lazy_t for compatibility * Remove -bs-no-cross-module-opt * Remove %%private as there is a .resi anyway * Get rid of Primitive_lazy * update artifacts --------- Co-authored-by: Cristiano Calcagno <[email protected]>
1 parent ac36283 commit 59f4237

18 files changed

+240
-500
lines changed

compiler/ml/predef.ml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ and ident_dict = ident_create "dict"
5353

5454
and ident_bigint = ident_create "bigint"
5555

56-
and ident_lazy_t = ident_create "lazy_t"
57-
5856
and ident_string = ident_create "string"
5957

6058
and ident_extension_constructor = ident_create "extension_constructor"
@@ -98,8 +96,6 @@ and path_dict = Pident ident_dict
9896

9997
and path_bigint = Pident ident_bigint
10098

101-
and path_lazy_t = Pident ident_lazy_t
102-
10399
and path_string = Pident ident_string
104100

105101
and path_unkonwn = Pident ident_unknown
@@ -132,8 +128,6 @@ and type_dict t = newgenty (Tconstr (path_dict, [t], ref Mnil))
132128

133129
and type_bigint = newgenty (Tconstr (path_bigint, [], ref Mnil))
134130

135-
and type_lazy_t t = newgenty (Tconstr (path_lazy_t, [t], ref Mnil))
136-
137131
and type_string = newgenty (Tconstr (path_string, [], ref Mnil))
138132

139133
and type_unknown = newgenty (Tconstr (path_unkonwn, [], ref Mnil))
@@ -332,14 +326,6 @@ let common_initial_env add_type add_extension empty_env =
332326
];
333327
type_unboxed = Types.unboxed_true_default_false;
334328
}
335-
and decl_lazy_t =
336-
let tvar = newgenvar () in
337-
{
338-
decl_abstr with
339-
type_params = [tvar];
340-
type_arity = 1;
341-
type_variance = [Variance.covariant];
342-
}
343329
and decl_promise =
344330
let tvar = newgenvar () in
345331
{
@@ -381,7 +367,6 @@ let common_initial_env add_type add_extension empty_env =
381367
|> add_type ident_exn decl_exn
382368
|> add_type ident_option decl_option
383369
|> add_type ident_result decl_result
384-
|> add_type ident_lazy_t decl_lazy_t
385370
|> add_type ident_promise decl_promise
386371
|> add_type ident_array decl_array
387372
|> add_type ident_list decl_list

compiler/ml/predef.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ val type_result : type_expr -> type_expr -> type_expr
3131
val type_dict : type_expr -> type_expr
3232

3333
val type_bigint : type_expr
34-
val type_lazy_t : type_expr -> type_expr
3534
val type_extension_constructor : type_expr
3635

3736
val path_int : Path.t
@@ -48,7 +47,6 @@ val path_result : Path.t
4847
val path_dict : Path.t
4948

5049
val path_bigint : Path.t
51-
val path_lazy_t : Path.t
5250
val path_extension_constructor : Path.t
5351
val path_promise : Path.t
5452

compiler/ml/transl_recmodule.ml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@ let init_shape modl =
6666
non_const = cstr_non_const;
6767
attrs = [];
6868
} )
69-
| {desc = Tconstr (p, _, _)} when Path.same p Predef.path_lazy_t ->
70-
Const_pointer
71-
( 1,
72-
Pt_constructor
73-
{
74-
name = "Lazy";
75-
const = cstr_const;
76-
non_const = cstr_non_const;
77-
attrs = [];
78-
} )
7969
| _ -> raise Not_found
8070
in
8171
add_name init_v id :: init_shape_struct env rem

compiler/ml/typeopt.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let rec type_cannot_contain_undefined (typ : Types.type_expr) (env : Env.t) =
4242
| Tconstr (p, _, _) -> (
4343
(* all built in types could not inhabit none-like values:
4444
int, char, float, bool, unit, exn, array, list, nativeint,
45-
int32, int64, lazy_t, bytes
45+
int32, int64, bytes
4646
*)
4747
match Predef.type_is_builtin_path_but_option p with
4848
| For_sure_yes -> true

lib/es6/Primitive_lazy.js

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

lib/es6/Stdlib.js

Lines changed: 1 addition & 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-
122,
15+
124,
1616
4
1717
],
1818
Error: new Error()

lib/es6/Stdlib_Lazy.js

Lines changed: 59 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,73 @@
11

22

3-
import * as Primitive_lazy from "./Primitive_lazy.js";
3+
import * as Primitive_exceptions from "./Primitive_exceptions.js";
44

5-
let make = Primitive_lazy.from_fun;
5+
function is_val(l) {
6+
return l.LAZY_DONE;
7+
}
68

7-
let get = Primitive_lazy.force;
9+
let Undefined = /* @__PURE__ */Primitive_exceptions.create("Stdlib_Lazy.Undefined");
810

9-
let isEvaluated = Primitive_lazy.is_val;
11+
function forward_with_closure(blk, closure) {
12+
let result = closure();
13+
blk.VAL = result;
14+
blk.LAZY_DONE = true;
15+
return result;
16+
}
1017

11-
let Undefined = Primitive_lazy.Undefined;
18+
function raise_undefined() {
19+
throw {
20+
RE_EXN_ID: Undefined,
21+
Error: new Error()
22+
};
23+
}
1224

13-
let force = Primitive_lazy.force;
25+
function force(lzv) {
26+
if (lzv.LAZY_DONE) {
27+
return lzv.VAL;
28+
} else {
29+
let closure = lzv.VAL;
30+
lzv.VAL = raise_undefined;
31+
try {
32+
return forward_with_closure(lzv, closure);
33+
} catch (e) {
34+
lzv.VAL = () => {
35+
throw e;
36+
};
37+
throw e;
38+
}
39+
}
40+
}
1441

15-
let force_val = Primitive_lazy.force_val;
42+
function force_val(lzv) {
43+
if (lzv.LAZY_DONE) {
44+
return lzv.VAL;
45+
} else {
46+
let closure = lzv.VAL;
47+
lzv.VAL = raise_undefined;
48+
return forward_with_closure(lzv, closure);
49+
}
50+
}
51+
52+
function from_fun(closure) {
53+
return {
54+
LAZY_DONE: false,
55+
VAL: closure
56+
};
57+
}
58+
59+
function from_val(value) {
60+
return {
61+
LAZY_DONE: true,
62+
VAL: value
63+
};
64+
}
1665

17-
let from_fun = Primitive_lazy.from_fun;
66+
let make = from_fun;
1867

19-
let from_val = Primitive_lazy.from_val;
68+
let get = force;
2069

21-
let is_val = Primitive_lazy.is_val;
70+
let isEvaluated = is_val;
2271

2372
export {
2473
make,

lib/js/Primitive_lazy.js

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

lib/js/Stdlib.js

Lines changed: 1 addition & 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-
122,
15+
124,
1616
4
1717
],
1818
Error: new Error()

0 commit comments

Comments
 (0)