Skip to content

Commit dc88212

Browse files
committed
Clean up lazy from ASTs and back-end.
Now that lazy is handled user-side, there's a bunch of unused code. The type `lazy_t` is still predefined, and module `Primitive_lazy.res` still exists. Perhaps `lazy_t` can be moved user side too, and `Primitive_lazy` just moved into `Stdlib_lazy`, which seems just a wrapper for it at the moment.
1 parent 429f901 commit dc88212

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+75
-443
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#### :house: Internal
4444

4545
- AST: Add bar location to `case`. https://github.com/rescript-lang/rescript/pull/7407
46+
- Clean up lazy from ASTs and back-end. https://github.com/rescript-lang/rescript/pull/7474
4647

4748
#### :nail_care: Polish
4849

analysis/reanalyze/src/Arnold.ml

-3
Original file line numberDiff line numberDiff line change
@@ -988,9 +988,6 @@ module Compile = struct
988988
| Texp_letexception _ ->
989989
notImplemented "Texp_letexception";
990990
assert false
991-
| Texp_lazy _ ->
992-
notImplemented "Texp_lazy";
993-
assert false
994991
| Texp_pack _ ->
995992
notImplemented "Texp_pack";
996993
assert false

analysis/reanalyze/src/SideEffects.ml

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ let rec exprNoSideEffects (expr : Typedtree.expression) =
4545
partial = Total && e |> exprNoSideEffects
4646
&& cases |> List.for_all caseNoSideEffects
4747
| Texp_letmodule _ -> false
48-
| Texp_lazy e -> e |> exprNoSideEffects
4948
| Texp_try (e, cases) ->
5049
e |> exprNoSideEffects && cases |> List.for_all caseNoSideEffects
5150
| Texp_tuple el -> el |> List.for_all exprNoSideEffects

analysis/src/CompletionFrontEnd.ml

-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
538538
?contextPath:(TypeUtils.contextPathFromCoreType coreType)
539539
p
540540
| Ppat_type _ -> ()
541-
| Ppat_lazy p -> scopePattern ~patternPath ?contextPath p
542541
| Ppat_unpack {txt; loc} ->
543542
scope :=
544543
!scope |> Scope.addValue ~name:txt ~loc ?contextPath:contextPathToSave

analysis/src/CompletionPatterns.ml

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ and traversePattern (pat : Parsetree.pattern) ~patternPath ~locHasCursor
4646
in
4747
match pat.ppat_desc with
4848
| Ppat_constant _ | Ppat_interval _ -> None
49-
| Ppat_lazy p
5049
| Ppat_constraint (p, _)
5150
| Ppat_alias (p, _)
5251
| Ppat_exception p

analysis/src/Hint.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ let inlay ~path ~pos ~maxLength ~debug =
5959
pexp_desc =
6060
( Pexp_constant _ | Pexp_tuple _ | Pexp_record _ | Pexp_variant _
6161
| Pexp_apply _ | Pexp_match _ | Pexp_construct _ | Pexp_ifthenelse _
62-
| Pexp_array _ | Pexp_ident _ | Pexp_try _ | Pexp_lazy _
63-
| Pexp_send _ | Pexp_field _ | Pexp_open _
62+
| Pexp_array _ | Pexp_ident _ | Pexp_try _ | Pexp_send _
63+
| Pexp_field _ | Pexp_open _
6464
| Pexp_fun {arity = Some _} );
6565
};
6666
} ->

analysis/src/ProcessCmt.ml

-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
460460
| Tpat_or (p, _, _) -> handlePattern [] p
461461
| Tpat_record (items, _) ->
462462
items |> List.iter (fun (_, _, p, _) -> handlePattern [] p)
463-
| Tpat_lazy p -> handlePattern [] p
464463
| Tpat_variant (_, Some p, _) -> handlePattern [] p
465464
| Tpat_variant (_, None, _) | Tpat_any | Tpat_constant _ -> ()
466465
in

analysis/src/Utils.ml

-2
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ let identifyPexp pexp =
106106
| Pexp_letmodule _ -> "Pexp_letmodule"
107107
| Pexp_letexception _ -> "Pexp_letexception"
108108
| Pexp_assert _ -> "Pexp_assert"
109-
| Pexp_lazy _ -> "Pexp_lazy"
110109
| Pexp_newtype _ -> "Pexp_newtype"
111110
| Pexp_pack _ -> "Pexp_pack"
112111
| Pexp_extension _ -> "Pexp_extension"
@@ -129,7 +128,6 @@ let identifyPpat pat =
129128
| Ppat_or _ -> "Ppat_or"
130129
| Ppat_constraint _ -> "Ppat_constraint"
131130
| Ppat_type _ -> "Ppat_type"
132-
| Ppat_lazy _ -> "Ppat_lazy"
133131
| Ppat_unpack _ -> "Ppat_unpack"
134132
| Ppat_exception _ -> "Ppat_exception"
135133
| Ppat_extension _ -> "Ppat_extension"

compiler/common/pattern_printer.ml

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ let untype typed =
3838
in
3939
mkpat (Ppat_record (fields, closed_flag))
4040
| Tpat_array lst -> mkpat (Ppat_array (List.map loop lst))
41-
| Tpat_lazy p -> mkpat (Ppat_lazy (loop p))
4241
in
4342
loop typed
4443

compiler/core/js_dump.ml

+2-6
Original file line numberDiff line numberDiff line change
@@ -969,12 +969,8 @@ and expression_desc cxt ~(level : int) f x : cxt =
969969
| _ -> J.Object (None, objs)
970970
in
971971
expression_desc cxt ~level f exp
972-
| Caml_block
973-
( _,
974-
_,
975-
_,
976-
(Blk_module_export _ | Blk_some | Blk_some_not_nested | Blk_lazy_general)
977-
) ->
972+
| Caml_block (_, _, _, (Blk_module_export _ | Blk_some | Blk_some_not_nested))
973+
->
978974
assert false
979975
| Caml_block (el, mutable_flag, _tag, Blk_tuple) ->
980976
expression_desc cxt ~level f (Array (el, mutable_flag))

compiler/core/js_exp_make.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ let dummy_obj ?comment (info : Lam_tag_info.t) : t =
283283
{comment; expression_desc = Object (None, [])}
284284
| Blk_tuple | Blk_module_export _ ->
285285
{comment; expression_desc = Array ([], Mutable)}
286-
| Blk_some | Blk_some_not_nested | Blk_lazy_general -> assert false
286+
| Blk_some | Blk_some_not_nested -> assert false
287287

288288
(* TODO: complete
289289
pure ...

compiler/core/lam_constant_convert.ml

+1-2
Original file line numberDiff line numberDiff line change
@@ -83,5 +83,4 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t =
8383
else Const_string {s; unicode = false}
8484
in
8585
Const_block (tag, t, [tag_val; convert_constant value])
86-
| _ -> assert false)
87-
| Blk_lazy_general -> assert false)
86+
| _ -> assert false))

compiler/core/lam_convert.ml

-23
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@ let prim = Lam.prim
3131
let lam_extension_id loc (head : Lam.t) =
3232
prim ~primitive:lam_caml_id ~args:[head] loc
3333

34-
let lazy_block_info : Lam_tag_info.t =
35-
Blk_record
36-
{
37-
fields = [|(Literals.lazy_done, false); (Literals.lazy_val, false)|];
38-
mutable_flag = Mutable;
39-
}
40-
4134
(** A conservative approach to avoid packing exceptions
4235
for lambda expression like {[
4336
try { ... }catch(id){body}
@@ -197,22 +190,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
197190
~primitive:(Pmakeblock (tag, info, mutable_flag))
198191
~args:[Lam.const tag_val; value]
199192
loc
200-
| _ -> assert false)
201-
| Blk_lazy_general -> (
202-
match args with
203-
| [((Lvar _ | Lconst _ | Lfunction _) as result)] ->
204-
let args = [Lam.const Const_js_true; result] in
205-
prim ~primitive:(Pmakeblock (tag, lazy_block_info, Mutable)) ~args loc
206-
| [computation] ->
207-
let args =
208-
[
209-
Lam.const Const_js_false;
210-
(* FIXME: arity 0 does not get proper supported*)
211-
Lam.function_ ~arity:0 ~params:[] ~body:computation
212-
~attr:Lambda.default_function_attribute;
213-
]
214-
in
215-
prim ~primitive:(Pmakeblock (tag, lazy_block_info, Mutable)) ~args loc
216193
| _ -> assert false))
217194
| Pfn_arity -> prim ~primitive:Pfn_arity ~args loc
218195
| Pdebugger -> prim ~primitive:Pdebugger ~args loc

compiler/ext/literals.ml

-4
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,4 @@ let hd = "hd"
164164

165165
let tl = "tl"
166166

167-
let lazy_done = "LAZY_DONE"
168-
169-
let lazy_val = "VAL"
170-
171167
let pure = "@__PURE__"

compiler/ext/primitive_modules.ml

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ let promise = "Primitive_promise"
4242

4343
let module_ = "Primitive_module"
4444

45-
let lazy_ = "Primitive_lazy"
46-
4745
let option = "Primitive_option"
4846

4947
let hash = "Primitive_hash"

compiler/frontend/bs_ast_mapper.ml

-2
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ module E = struct
373373
(sub.extension_constructor sub cd)
374374
(sub.expr sub e)
375375
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
376-
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
377376
| Pexp_newtype (s, e) ->
378377
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
379378
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
@@ -434,7 +433,6 @@ module P = struct
434433
| Ppat_constraint (p, t) ->
435434
constraint_ ~loc ~attrs (sub.pat sub p) (sub.typ sub t)
436435
| Ppat_type s -> type_ ~loc ~attrs (map_loc sub s)
437-
| Ppat_lazy p -> lazy_ ~loc ~attrs (sub.pat sub p)
438436
| Ppat_unpack s -> unpack ~loc ~attrs (map_loc sub s)
439437
| Ppat_open (lid, p) -> open_ ~loc ~attrs (map_loc sub lid) (sub.pat sub p)
440438
| Ppat_exception p -> exception_ ~loc ~attrs (sub.pat sub p)

compiler/ml/ast_helper.ml

-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ module Pat = struct
136136
let or_ ?loc ?attrs a b = mk ?loc ?attrs (Ppat_or (a, b))
137137
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Ppat_constraint (a, b))
138138
let type_ ?loc ?attrs a = mk ?loc ?attrs (Ppat_type a)
139-
let lazy_ ?loc ?attrs a = mk ?loc ?attrs (Ppat_lazy a)
140139
let unpack ?loc ?attrs a = mk ?loc ?attrs (Ppat_unpack a)
141140
let open_ ?loc ?attrs a b = mk ?loc ?attrs (Ppat_open (a, b))
142141
let exception_ ?loc ?attrs a = mk ?loc ?attrs (Ppat_exception a)
@@ -176,7 +175,6 @@ module Exp = struct
176175
let letmodule ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_letmodule (a, b, c))
177176
let letexception ?loc ?attrs a b = mk ?loc ?attrs (Pexp_letexception (a, b))
178177
let assert_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_assert a)
179-
let lazy_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_lazy a)
180178
let newtype ?loc ?attrs a b = mk ?loc ?attrs (Pexp_newtype (a, b))
181179
let pack ?loc ?attrs a = mk ?loc ?attrs (Pexp_pack a)
182180
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_open (a, b, c))

compiler/ml/ast_helper.mli

-2
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ module Pat : sig
114114
val or_ : ?loc:loc -> ?attrs:attrs -> pattern -> pattern -> pattern
115115
val constraint_ : ?loc:loc -> ?attrs:attrs -> pattern -> core_type -> pattern
116116
val type_ : ?loc:loc -> ?attrs:attrs -> lid -> pattern
117-
val lazy_ : ?loc:loc -> ?attrs:attrs -> pattern -> pattern
118117
val unpack : ?loc:loc -> ?attrs:attrs -> str -> pattern
119118
val open_ : ?loc:loc -> ?attrs:attrs -> lid -> pattern -> pattern
120119
val exception_ : ?loc:loc -> ?attrs:attrs -> pattern -> pattern
@@ -203,7 +202,6 @@ module Exp : sig
203202
expression ->
204203
expression
205204
val assert_ : ?loc:loc -> ?attrs:attrs -> expression -> expression
206-
val lazy_ : ?loc:loc -> ?attrs:attrs -> expression -> expression
207205
val newtype : ?loc:loc -> ?attrs:attrs -> str -> expression -> expression
208206
val pack : ?loc:loc -> ?attrs:attrs -> module_expr -> expression
209207
val open_ :

compiler/ml/ast_iterator.ml

-2
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ module E = struct
350350
sub.extension_constructor sub cd;
351351
sub.expr sub e
352352
| Pexp_assert e -> sub.expr sub e
353-
| Pexp_lazy e -> sub.expr sub e
354353
| Pexp_newtype (_s, e) -> sub.expr sub e
355354
| Pexp_pack me -> sub.module_expr sub me
356355
| Pexp_open (_ovf, lid, e) ->
@@ -407,7 +406,6 @@ module P = struct
407406
sub.pat sub p;
408407
sub.typ sub t
409408
| Ppat_type s -> iter_loc sub s
410-
| Ppat_lazy p -> sub.pat sub p
411409
| Ppat_unpack s -> iter_loc sub s
412410
| Ppat_exception p -> sub.pat sub p
413411
| Ppat_extension x -> sub.extension sub x

compiler/ml/ast_mapper.ml

-2
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ module E = struct
336336
(sub.extension_constructor sub cd)
337337
(sub.expr sub e)
338338
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
339-
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
340339
| Pexp_newtype (s, e) ->
341340
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
342341
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
@@ -398,7 +397,6 @@ module P = struct
398397
| Ppat_constraint (p, t) ->
399398
constraint_ ~loc ~attrs (sub.pat sub p) (sub.typ sub t)
400399
| Ppat_type s -> type_ ~loc ~attrs (map_loc sub s)
401-
| Ppat_lazy p -> lazy_ ~loc ~attrs (sub.pat sub p)
402400
| Ppat_unpack s -> unpack ~loc ~attrs (map_loc sub s)
403401
| Ppat_open (lid, p) -> open_ ~loc ~attrs (map_loc sub lid) (sub.pat sub p)
404402
| Ppat_exception p -> exception_ ~loc ~attrs (sub.pat sub p)

compiler/ml/ast_mapper_from0.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ module E = struct
527527
(sub.extension_constructor sub cd)
528528
(sub.expr sub e)
529529
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
530-
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
530+
| Pexp_lazy _ -> failwith "Pexp_lazy is no longer present in ReScript"
531531
| Pexp_poly _ -> failwith "Pexp_poly is no longer present in ReScript"
532532
| Pexp_object () -> assert false
533533
| Pexp_newtype (s, e) ->
@@ -572,7 +572,7 @@ module P = struct
572572
| Ppat_constraint (p, t) ->
573573
constraint_ ~loc ~attrs (sub.pat sub p) (sub.typ sub t)
574574
| Ppat_type s -> type_ ~loc ~attrs (map_loc sub s)
575-
| Ppat_lazy p -> lazy_ ~loc ~attrs (sub.pat sub p)
575+
| Ppat_lazy _ -> failwith "Ppat_lazy is no longer present in ReScript"
576576
| Ppat_unpack s -> unpack ~loc ~attrs (map_loc sub s)
577577
| Ppat_open (lid, p) -> open_ ~loc ~attrs (map_loc sub lid) (sub.pat sub p)
578578
| Ppat_exception p -> exception_ ~loc ~attrs (sub.pat sub p)

compiler/ml/ast_mapper_to0.ml

-2
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,6 @@ module E = struct
460460
(sub.extension_constructor sub cd)
461461
(sub.expr sub e)
462462
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
463-
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
464463
| Pexp_newtype (s, e) ->
465464
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
466465
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
@@ -568,7 +567,6 @@ module P = struct
568567
| Ppat_constraint (p, t) ->
569568
constraint_ ~loc ~attrs (sub.pat sub p) (sub.typ sub t)
570569
| Ppat_type s -> type_ ~loc ~attrs (map_loc sub s)
571-
| Ppat_lazy p -> lazy_ ~loc ~attrs (sub.pat sub p)
572570
| Ppat_unpack s -> unpack ~loc ~attrs (map_loc sub s)
573571
| Ppat_open (lid, p) -> open_ ~loc ~attrs (map_loc sub lid) (sub.pat sub p)
574572
| Ppat_exception p -> exception_ ~loc ~attrs (sub.pat sub p)

compiler/ml/depend.ml

-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ let rec add_pattern bv pat =
198198
add_type bv ty
199199
| Ppat_variant (_, op) -> add_opt add_pattern bv op
200200
| Ppat_type li -> add bv li
201-
| Ppat_lazy p -> add_pattern bv p
202201
| Ppat_unpack id -> pattern_bv := StringMap.add id.txt bound !pattern_bv
203202
| Ppat_open (m, p) ->
204203
let bv = open_module bv m.txt in
@@ -276,7 +275,6 @@ let rec add_expr bv exp =
276275
add_expr (StringMap.add id.txt b bv) e
277276
| Pexp_letexception (_, e) -> add_expr bv e
278277
| Pexp_assert e -> add_expr bv e
279-
| Pexp_lazy e -> add_expr bv e
280278
| Pexp_newtype (_, e) -> add_expr bv e
281279
| Pexp_pack m -> add_module bv m
282280
| Pexp_open (_ovf, m, e) ->

compiler/ml/env.ml

-5
Original file line numberDiff line numberDiff line change
@@ -1878,11 +1878,6 @@ let open_signature slot root env0 =
18781878

18791879
(* Open a signature from a file *)
18801880

1881-
let open_pers_signature name env =
1882-
match open_signature None (Pident (Ident.create_persistent name)) env with
1883-
| Some env -> env
1884-
| None -> assert false (* a compilation unit cannot refer to a functor *)
1885-
18861881
let open_signature ?(used_slot = ref false) ?(loc = Location.none)
18871882
?(toplevel = false) ovf root env =
18881883
if

compiler/ml/env.mli

-2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ val open_signature :
155155
t ->
156156
t option
157157

158-
val open_pers_signature : string -> t -> t
159-
160158
(* Insertion by name *)
161159

162160
val enter_value :

compiler/ml/lambda.ml

-3
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,13 @@ type tag_info =
4646
fields: string array;
4747
mutable_flag: Asttypes.mutable_flag;
4848
}
49-
| Blk_lazy_general
5049

5150
let tag_of_tag_info (tag : tag_info) =
5251
match tag with
5352
| Blk_constructor {tag} | Blk_record_inlined {tag} -> tag
5453
| Blk_tuple | Blk_poly_var _ | Blk_record _ | Blk_module _
5554
| Blk_module_export _ | Blk_extension | Blk_some (* tag not make sense *)
5655
| Blk_some_not_nested (* tag not make sense *)
57-
| Blk_lazy_general (* tag not make sense 248 *)
5856
| Blk_record_ext _ (* similar to Blk_extension*) ->
5957
0
6058

@@ -64,7 +62,6 @@ let mutable_flag_of_tag_info (tag : tag_info) =
6462
| Blk_record {mutable_flag}
6563
| Blk_record_ext {mutable_flag} ->
6664
mutable_flag
67-
| Blk_lazy_general -> Mutable
6865
| Blk_tuple | Blk_constructor _ | Blk_poly_var _ | Blk_module _
6966
| Blk_module_export _ | Blk_extension | Blk_some_not_nested | Blk_some ->
7067
Immutable

compiler/ml/lambda.mli

-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ type tag_info =
5656
| Blk_some_not_nested
5757
(* ['a option] where ['a] can not inhabit a non-like value *)
5858
| Blk_record_ext of {fields: string array; mutable_flag: mutable_flag}
59-
| Blk_lazy_general
6059

6160
val find_name : Parsetree.attribute -> Asttypes.label option
6261

0 commit comments

Comments
 (0)