Skip to content

Commit 7da8859

Browse files
committed
lazy_t cleanup part 2
1 parent ac36283 commit 7da8859

File tree

12 files changed

+40
-61
lines changed

12 files changed

+40
-61
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/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/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()

runtime/Primitive_lazy.res

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ type t<'a> = {
3434

3535
%%private(external fnToVal: (unit => 'a) => 'a = "%identity")
3636
%%private(external valToFn: 'a => unit => 'a = "%identity")
37-
%%private(external castToConcrete: lazy_t<'a> => t<'a> = "%identity")
38-
%%private(external castFromConcrete: t<'a> => lazy_t<'a> = "%identity")
37+
%%private(external castToConcrete: t<'a> => t<'a> = "%identity")
38+
%%private(external castFromConcrete: t<'a> => t<'a> = "%identity")
3939

40-
let is_val = (type a, l: lazy_t<a>): bool => castToConcrete(l).tag
40+
let is_val = (type a, l: t<a>): bool => castToConcrete(l).tag
4141

4242
exception Undefined
4343

@@ -74,7 +74,7 @@ exception Undefined
7474
}
7575
)
7676

77-
let force = (type a, lzv: lazy_t<a>): a => {
77+
let force = (type a, lzv: t<a>): a => {
7878
let lzv: t<_> = castToConcrete(lzv)
7979
if lzv.tag {
8080
lzv.value
@@ -83,7 +83,7 @@ let force = (type a, lzv: lazy_t<a>): a => {
8383
}
8484
}
8585

86-
let force_val = (type a, lzv: lazy_t<a>): a => {
86+
let force_val = (type a, lzv: t<a>): a => {
8787
let lzv: t<_> = castToConcrete(lzv)
8888
if lzv.tag {
8989
lzv.value
@@ -92,15 +92,15 @@ let force_val = (type a, lzv: lazy_t<a>): a => {
9292
}
9393
}
9494

95-
let from_fun = (type a, closure: unit => a): lazy_t<a> => {
95+
let from_fun = (type a, closure: unit => a): t<a> => {
9696
let blk = {
9797
tag: false,
9898
value: fnToVal(closure),
9999
}
100100
castFromConcrete(blk)
101101
}
102102

103-
let from_val = (type a, value: a): lazy_t<a> => {
103+
let from_val = (type a, value: a): t<a> => {
104104
let blk = {
105105
tag: true,
106106
value,

runtime/Primitive_lazy.resi

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
exception Undefined
22

3+
@notUndefined
4+
type t<'a>
5+
36
/** [force x] forces the suspension [x] and returns its result.
47
If [x] has already been forced, [Lazy.force x] returns the
58
same value again without recomputing it. If it raised an exception,
69
the same exception is raised again.
710
Raise {!Undefined} if the forcing of [x] tries to force [x] itself
811
recursively.
912
*/
10-
let force: lazy_t<'a> => 'a
13+
let force: t<'a> => 'a
1114

1215
/** [force_val x] forces the suspension [x] and returns its
1316
result. If [x] has already been forced, [force_val x]
@@ -17,23 +20,23 @@ let force: lazy_t<'a> => 'a
1720
If the computation of [x] raises an exception, it is unspecified
1821
whether [force_val x] raises the same exception or {!Undefined}.
1922
*/
20-
let force_val: lazy_t<'a> => 'a
23+
let force_val: t<'a> => 'a
2124

2225
/** [from_fun f] is the same as [lazy (f ())] but slightly more efficient.
2326
2427
[from_fun] should only be used if the function [f] is already defined.
2528
In particular it is always less efficient to write
2629
[from_fun (fun () => expr)] than [lazy expr].
2730
*/
28-
let from_fun: (unit => 'a) => lazy_t<'a>
31+
let from_fun: (unit => 'a) => t<'a>
2932

3033
/** [from_val v] returns an already-forced suspension of [v].
3134
This is for special purposes only and should not be confused with
3235
[lazy (v)].
3336
*/
34-
let from_val: 'a => lazy_t<'a>
37+
let from_val: 'a => t<'a>
3538

3639
/** [is_val x] returns [true] if [x] has already been forced and
3740
did not raise an exception.
3841
*/
39-
let is_val: lazy_t<'a> => bool
42+
let is_val: t<'a> => bool

runtime/Stdlib.res

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type date = Date.t
5757
type null<+'a> = Primitive_js_extern.null<'a>
5858
type undefined<+'a> = Primitive_js_extern.undefined<'a>
5959
type nullable<+'a> = Primitive_js_extern.nullable<'a>
60+
@deprecated("Use Lazy.t instead")
61+
type lazy_t<'a> = Lazy.t<'a>
6062

6163
@deprecated("Use rescript-webapi instead") @val external window: Dom.window = "window"
6264
@deprecated("Use rescript-webapi instead") @val external document: Dom.document = "document"

runtime/Stdlib_Lazy.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
type t<'a> = lazy_t<'a>
1+
type t<'a> = Primitive_lazy.t<'a>
22

33
exception Undefined = Primitive_lazy.Undefined
44

runtime/Stdlib_Lazy.resi

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,17 @@
1212
subsequent accesses. If the computation raises an exception,
1313
the same exception is raised again on subsequent accesses.
1414
*/
15-
type t<'a> = lazy_t<'a>
15+
@notUndefined
16+
type t<'a>
1617

17-
/**
18+
/**
1819
`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>`.
20+
computation to be deferred of type `unit => 'a`.
21+
The function returns a lazy value of type `Lazy.t<'a>`.
2122
The computation is not executed until the lazy value is accessed.
2223
23-
## Examples
24-
```rescript
24+
## Examples
25+
```rescript
2526
let lazyValue = Lazy.make(() => {
2627
// Some expensive computation
2728
Console.log("Computing...")
@@ -44,12 +45,12 @@ let get: t<'a> => 'a
4445

4546
/**
4647
`Lazy.isEvaluated(x)` returns `true` if the suspension `x` has
47-
already been forced and did not raise an exception. Otherwise,
48+
already been forced and did not raise an exception. Otherwise,
4849
it returns `false`. This is useful for checking if a lazy value
4950
has been computed before accessing it.
5051
5152
## Examples
52-
```rescript
53+
```rescript
5354
let lazyValue = Lazy.make(() => {
5455
// Some expensive computation
5556
Console.log("Computing...")
@@ -64,7 +65,7 @@ let isEvaluated: t<'a> => bool
6465

6566
exception Undefined
6667

67-
/**
68+
/**
6869
`force(x)` forces the suspension `x` and returns its result.
6970
If `x` has already been forced, `Lazy.force(x)` returns the
7071
same value again without recomputing it. If it raised an exception,
@@ -75,7 +76,7 @@ exception Undefined
7576
@deprecated("Use `Lazy.get` instead")
7677
let force: t<'a> => 'a
7778

78-
/**
79+
/**
7980
`force_val(x)` forces the suspension `x` and returns its
8081
result. If `x` has already been forced, `force_val(x)`
8182
returns the same value again without recomputing it.
@@ -87,23 +88,23 @@ let force: t<'a> => 'a
8788
@deprecated("Use `Lazy.get` instead")
8889
let force_val: t<'a> => 'a
8990

90-
/**
91+
/**
9192
`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>`.
93+
computation to be deferred of type `unit => 'a`.
94+
The function returns a lazy value of type `Lazy.t<'a>`.
9495
The computation is not executed until the lazy value is accessed.
9596
*/
9697
@deprecated("Use `Lazy.make` instead")
9798
let from_fun: (unit => 'a) => t<'a>
9899

99-
/**
100+
/**
100101
`from_val(v)` returns an already-forced suspension of `v`.
101102
This is for special purposes only.
102103
*/
103104
@deprecated("Use `Lazy.make` instead")
104105
let from_val: 'a => t<'a>
105106

106-
/**
107+
/**
107108
`is_val(x)` returns `true` if `x has already been forced and
108109
did not raise an exception.
109110
*/

tests/tests/src/lazy_test.res

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ let f006: Lazy.t<unit => int> = Lazy.make(() => {
5252
_ => x
5353
})
5454

55-
let f007 = Lazy.make(() => raise(Not_found))
56-
let f008 = Lazy.make(() => {
55+
let f007: Lazy.t<string> = Lazy.make(() => raise(Not_found))
56+
let f008: Lazy.t<string> = Lazy.make(() => {
5757
Js.log("hi")
5858
raise(Not_found)
5959
})
@@ -62,7 +62,7 @@ let a2 = x => Lazy.from_val(x)
6262

6363
let a3 = Lazy.from_val(3)
6464
let a4 = a2(3)
65-
let a5 = Lazy.from_val(None)
65+
let a5: Lazy.t<option<string>> = Lazy.from_val(None)
6666
let a6 = Lazy.from_val()
6767

6868
let a7 = Lazy.get(a5)

0 commit comments

Comments
 (0)