Skip to content

Clean up lazy from ASTs and back-end. #7474

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 1 commit into from
May 16, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#### :house: Internal

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

#### :nail_care: Polish

Expand Down
3 changes: 0 additions & 3 deletions analysis/reanalyze/src/Arnold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -988,9 +988,6 @@ module Compile = struct
| Texp_letexception _ ->
notImplemented "Texp_letexception";
assert false
| Texp_lazy _ ->
notImplemented "Texp_lazy";
assert false
| Texp_pack _ ->
notImplemented "Texp_pack";
assert false
Expand Down
1 change: 0 additions & 1 deletion analysis/reanalyze/src/SideEffects.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ let rec exprNoSideEffects (expr : Typedtree.expression) =
partial = Total && e |> exprNoSideEffects
&& cases |> List.for_all caseNoSideEffects
| Texp_letmodule _ -> false
| Texp_lazy e -> e |> exprNoSideEffects
| Texp_try (e, cases) ->
e |> exprNoSideEffects && cases |> List.for_all caseNoSideEffects
| Texp_tuple el -> el |> List.for_all exprNoSideEffects
Expand Down
1 change: 0 additions & 1 deletion analysis/src/CompletionFrontEnd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,6 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
?contextPath:(TypeUtils.contextPathFromCoreType coreType)
p
| Ppat_type _ -> ()
| Ppat_lazy p -> scopePattern ~patternPath ?contextPath p
| Ppat_unpack {txt; loc} ->
scope :=
!scope |> Scope.addValue ~name:txt ~loc ?contextPath:contextPathToSave
Expand Down
1 change: 0 additions & 1 deletion analysis/src/CompletionPatterns.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ and traversePattern (pat : Parsetree.pattern) ~patternPath ~locHasCursor
in
match pat.ppat_desc with
| Ppat_constant _ | Ppat_interval _ -> None
| Ppat_lazy p
| Ppat_constraint (p, _)
| Ppat_alias (p, _)
| Ppat_exception p
Expand Down
4 changes: 2 additions & 2 deletions analysis/src/Hint.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ let inlay ~path ~pos ~maxLength ~debug =
pexp_desc =
( Pexp_constant _ | Pexp_tuple _ | Pexp_record _ | Pexp_variant _
| Pexp_apply _ | Pexp_match _ | Pexp_construct _ | Pexp_ifthenelse _
| Pexp_array _ | Pexp_ident _ | Pexp_try _ | Pexp_lazy _
| Pexp_send _ | Pexp_field _ | Pexp_open _
| Pexp_array _ | Pexp_ident _ | Pexp_try _ | Pexp_send _
| Pexp_field _ | Pexp_open _
| Pexp_fun {arity = Some _} );
};
} ->
Expand Down
1 change: 0 additions & 1 deletion analysis/src/ProcessCmt.ml
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ let rec forStructureItem ~env ~(exported : Exported.t) item =
| Tpat_or (p, _, _) -> handlePattern [] p
| Tpat_record (items, _) ->
items |> List.iter (fun (_, _, p, _) -> handlePattern [] p)
| Tpat_lazy p -> handlePattern [] p
| Tpat_variant (_, Some p, _) -> handlePattern [] p
| Tpat_variant (_, None, _) | Tpat_any | Tpat_constant _ -> ()
in
Expand Down
2 changes: 0 additions & 2 deletions analysis/src/Utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ let identifyPexp pexp =
| Pexp_letmodule _ -> "Pexp_letmodule"
| Pexp_letexception _ -> "Pexp_letexception"
| Pexp_assert _ -> "Pexp_assert"
| Pexp_lazy _ -> "Pexp_lazy"
| Pexp_newtype _ -> "Pexp_newtype"
| Pexp_pack _ -> "Pexp_pack"
| Pexp_extension _ -> "Pexp_extension"
Expand All @@ -129,7 +128,6 @@ let identifyPpat pat =
| Ppat_or _ -> "Ppat_or"
| Ppat_constraint _ -> "Ppat_constraint"
| Ppat_type _ -> "Ppat_type"
| Ppat_lazy _ -> "Ppat_lazy"
| Ppat_unpack _ -> "Ppat_unpack"
| Ppat_exception _ -> "Ppat_exception"
| Ppat_extension _ -> "Ppat_extension"
Expand Down
1 change: 0 additions & 1 deletion compiler/common/pattern_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ let untype typed =
in
mkpat (Ppat_record (fields, closed_flag))
| Tpat_array lst -> mkpat (Ppat_array (List.map loop lst))
| Tpat_lazy p -> mkpat (Ppat_lazy (loop p))
in
loop typed

Expand Down
8 changes: 2 additions & 6 deletions compiler/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -969,12 +969,8 @@ and expression_desc cxt ~(level : int) f x : cxt =
| _ -> J.Object (None, objs)
in
expression_desc cxt ~level f exp
| Caml_block
( _,
_,
_,
(Blk_module_export _ | Blk_some | Blk_some_not_nested | Blk_lazy_general)
) ->
| Caml_block (_, _, _, (Blk_module_export _ | Blk_some | Blk_some_not_nested))
->
assert false
| Caml_block (el, mutable_flag, _tag, Blk_tuple) ->
expression_desc cxt ~level f (Array (el, mutable_flag))
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/js_exp_make.ml
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ let dummy_obj ?comment (info : Lam_tag_info.t) : t =
{comment; expression_desc = Object (None, [])}
| Blk_tuple | Blk_module_export _ ->
{comment; expression_desc = Array ([], Mutable)}
| Blk_some | Blk_some_not_nested | Blk_lazy_general -> assert false
| Blk_some | Blk_some_not_nested -> assert false

(* TODO: complete
pure ...
Expand Down
3 changes: 1 addition & 2 deletions compiler/core/lam_constant_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,4 @@ let rec convert_constant (const : Lambda.structured_constant) : Lam_constant.t =
else Const_string {s; unicode = false}
in
Const_block (tag, t, [tag_val; convert_constant value])
| _ -> assert false)
| Blk_lazy_general -> assert false)
| _ -> assert false))
23 changes: 0 additions & 23 deletions compiler/core/lam_convert.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ let prim = Lam.prim
let lam_extension_id loc (head : Lam.t) =
prim ~primitive:lam_caml_id ~args:[head] loc

let lazy_block_info : Lam_tag_info.t =
Blk_record
{
fields = [|(Literals.lazy_done, false); (Literals.lazy_val, false)|];
mutable_flag = Mutable;
}

(** A conservative approach to avoid packing exceptions
for lambda expression like {[
try { ... }catch(id){body}
Expand Down Expand Up @@ -197,22 +190,6 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
~primitive:(Pmakeblock (tag, info, mutable_flag))
~args:[Lam.const tag_val; value]
loc
| _ -> assert false)
| Blk_lazy_general -> (
match args with
| [((Lvar _ | Lconst _ | Lfunction _) as result)] ->
let args = [Lam.const Const_js_true; result] in
prim ~primitive:(Pmakeblock (tag, lazy_block_info, Mutable)) ~args loc
| [computation] ->
let args =
[
Lam.const Const_js_false;
(* FIXME: arity 0 does not get proper supported*)
Lam.function_ ~arity:0 ~params:[] ~body:computation
~attr:Lambda.default_function_attribute;
]
in
prim ~primitive:(Pmakeblock (tag, lazy_block_info, Mutable)) ~args loc
| _ -> assert false))
| Pfn_arity -> prim ~primitive:Pfn_arity ~args loc
| Pdebugger -> prim ~primitive:Pdebugger ~args loc
Expand Down
4 changes: 0 additions & 4 deletions compiler/ext/literals.ml
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,4 @@ let hd = "hd"

let tl = "tl"

let lazy_done = "LAZY_DONE"

let lazy_val = "VAL"

let pure = "@__PURE__"
2 changes: 0 additions & 2 deletions compiler/ext/primitive_modules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ let promise = "Primitive_promise"

let module_ = "Primitive_module"

let lazy_ = "Primitive_lazy"

let option = "Primitive_option"

let hash = "Primitive_hash"
Expand Down
2 changes: 0 additions & 2 deletions compiler/frontend/bs_ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ module E = struct
(sub.extension_constructor sub cd)
(sub.expr sub e)
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
| Pexp_newtype (s, e) ->
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
Expand Down Expand Up @@ -434,7 +433,6 @@ module P = struct
| Ppat_constraint (p, t) ->
constraint_ ~loc ~attrs (sub.pat sub p) (sub.typ sub t)
| Ppat_type s -> type_ ~loc ~attrs (map_loc sub s)
| Ppat_lazy p -> lazy_ ~loc ~attrs (sub.pat sub p)
| Ppat_unpack s -> unpack ~loc ~attrs (map_loc sub s)
| Ppat_open (lid, p) -> open_ ~loc ~attrs (map_loc sub lid) (sub.pat sub p)
| Ppat_exception p -> exception_ ~loc ~attrs (sub.pat sub p)
Expand Down
2 changes: 0 additions & 2 deletions compiler/ml/ast_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ module Pat = struct
let or_ ?loc ?attrs a b = mk ?loc ?attrs (Ppat_or (a, b))
let constraint_ ?loc ?attrs a b = mk ?loc ?attrs (Ppat_constraint (a, b))
let type_ ?loc ?attrs a = mk ?loc ?attrs (Ppat_type a)
let lazy_ ?loc ?attrs a = mk ?loc ?attrs (Ppat_lazy a)
let unpack ?loc ?attrs a = mk ?loc ?attrs (Ppat_unpack a)
let open_ ?loc ?attrs a b = mk ?loc ?attrs (Ppat_open (a, b))
let exception_ ?loc ?attrs a = mk ?loc ?attrs (Ppat_exception a)
Expand Down Expand Up @@ -176,7 +175,6 @@ module Exp = struct
let letmodule ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_letmodule (a, b, c))
let letexception ?loc ?attrs a b = mk ?loc ?attrs (Pexp_letexception (a, b))
let assert_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_assert a)
let lazy_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_lazy a)
let newtype ?loc ?attrs a b = mk ?loc ?attrs (Pexp_newtype (a, b))
let pack ?loc ?attrs a = mk ?loc ?attrs (Pexp_pack a)
let open_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_open (a, b, c))
Expand Down
2 changes: 0 additions & 2 deletions compiler/ml/ast_helper.mli
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ module Pat : sig
val or_ : ?loc:loc -> ?attrs:attrs -> pattern -> pattern -> pattern
val constraint_ : ?loc:loc -> ?attrs:attrs -> pattern -> core_type -> pattern
val type_ : ?loc:loc -> ?attrs:attrs -> lid -> pattern
val lazy_ : ?loc:loc -> ?attrs:attrs -> pattern -> pattern
val unpack : ?loc:loc -> ?attrs:attrs -> str -> pattern
val open_ : ?loc:loc -> ?attrs:attrs -> lid -> pattern -> pattern
val exception_ : ?loc:loc -> ?attrs:attrs -> pattern -> pattern
Expand Down Expand Up @@ -203,7 +202,6 @@ module Exp : sig
expression ->
expression
val assert_ : ?loc:loc -> ?attrs:attrs -> expression -> expression
val lazy_ : ?loc:loc -> ?attrs:attrs -> expression -> expression
val newtype : ?loc:loc -> ?attrs:attrs -> str -> expression -> expression
val pack : ?loc:loc -> ?attrs:attrs -> module_expr -> expression
val open_ :
Expand Down
2 changes: 0 additions & 2 deletions compiler/ml/ast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,6 @@ module E = struct
sub.extension_constructor sub cd;
sub.expr sub e
| Pexp_assert e -> sub.expr sub e
| Pexp_lazy e -> sub.expr sub e
| Pexp_newtype (_s, e) -> sub.expr sub e
| Pexp_pack me -> sub.module_expr sub me
| Pexp_open (_ovf, lid, e) ->
Expand Down Expand Up @@ -407,7 +406,6 @@ module P = struct
sub.pat sub p;
sub.typ sub t
| Ppat_type s -> iter_loc sub s
| Ppat_lazy p -> sub.pat sub p
| Ppat_unpack s -> iter_loc sub s
| Ppat_exception p -> sub.pat sub p
| Ppat_extension x -> sub.extension sub x
Expand Down
2 changes: 0 additions & 2 deletions compiler/ml/ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ module E = struct
(sub.extension_constructor sub cd)
(sub.expr sub e)
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
| Pexp_newtype (s, e) ->
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
Expand Down Expand Up @@ -398,7 +397,6 @@ module P = struct
| Ppat_constraint (p, t) ->
constraint_ ~loc ~attrs (sub.pat sub p) (sub.typ sub t)
| Ppat_type s -> type_ ~loc ~attrs (map_loc sub s)
| Ppat_lazy p -> lazy_ ~loc ~attrs (sub.pat sub p)
| Ppat_unpack s -> unpack ~loc ~attrs (map_loc sub s)
| Ppat_open (lid, p) -> open_ ~loc ~attrs (map_loc sub lid) (sub.pat sub p)
| Ppat_exception p -> exception_ ~loc ~attrs (sub.pat sub p)
Expand Down
4 changes: 2 additions & 2 deletions compiler/ml/ast_mapper_from0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ module E = struct
(sub.extension_constructor sub cd)
(sub.expr sub e)
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
| Pexp_lazy _ -> failwith "Pexp_lazy is no longer present in ReScript"
| Pexp_poly _ -> failwith "Pexp_poly is no longer present in ReScript"
| Pexp_object () -> assert false
| Pexp_newtype (s, e) ->
Expand Down Expand Up @@ -572,7 +572,7 @@ module P = struct
| Ppat_constraint (p, t) ->
constraint_ ~loc ~attrs (sub.pat sub p) (sub.typ sub t)
| Ppat_type s -> type_ ~loc ~attrs (map_loc sub s)
| Ppat_lazy p -> lazy_ ~loc ~attrs (sub.pat sub p)
| Ppat_lazy _ -> failwith "Ppat_lazy is no longer present in ReScript"
| Ppat_unpack s -> unpack ~loc ~attrs (map_loc sub s)
| Ppat_open (lid, p) -> open_ ~loc ~attrs (map_loc sub lid) (sub.pat sub p)
| Ppat_exception p -> exception_ ~loc ~attrs (sub.pat sub p)
Expand Down
2 changes: 0 additions & 2 deletions compiler/ml/ast_mapper_to0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ module E = struct
(sub.extension_constructor sub cd)
(sub.expr sub e)
| Pexp_assert e -> assert_ ~loc ~attrs (sub.expr sub e)
| Pexp_lazy e -> lazy_ ~loc ~attrs (sub.expr sub e)
| Pexp_newtype (s, e) ->
newtype ~loc ~attrs (map_loc sub s) (sub.expr sub e)
| Pexp_pack me -> pack ~loc ~attrs (sub.module_expr sub me)
Expand Down Expand Up @@ -568,7 +567,6 @@ module P = struct
| Ppat_constraint (p, t) ->
constraint_ ~loc ~attrs (sub.pat sub p) (sub.typ sub t)
| Ppat_type s -> type_ ~loc ~attrs (map_loc sub s)
| Ppat_lazy p -> lazy_ ~loc ~attrs (sub.pat sub p)
| Ppat_unpack s -> unpack ~loc ~attrs (map_loc sub s)
| Ppat_open (lid, p) -> open_ ~loc ~attrs (map_loc sub lid) (sub.pat sub p)
| Ppat_exception p -> exception_ ~loc ~attrs (sub.pat sub p)
Expand Down
2 changes: 0 additions & 2 deletions compiler/ml/depend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ let rec add_pattern bv pat =
add_type bv ty
| Ppat_variant (_, op) -> add_opt add_pattern bv op
| Ppat_type li -> add bv li
| Ppat_lazy p -> add_pattern bv p
| Ppat_unpack id -> pattern_bv := StringMap.add id.txt bound !pattern_bv
| Ppat_open (m, p) ->
let bv = open_module bv m.txt in
Expand Down Expand Up @@ -276,7 +275,6 @@ let rec add_expr bv exp =
add_expr (StringMap.add id.txt b bv) e
| Pexp_letexception (_, e) -> add_expr bv e
| Pexp_assert e -> add_expr bv e
| Pexp_lazy e -> add_expr bv e
| Pexp_newtype (_, e) -> add_expr bv e
| Pexp_pack m -> add_module bv m
| Pexp_open (_ovf, m, e) ->
Expand Down
5 changes: 0 additions & 5 deletions compiler/ml/env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1878,11 +1878,6 @@ let open_signature slot root env0 =

(* Open a signature from a file *)

let open_pers_signature name env =
match open_signature None (Pident (Ident.create_persistent name)) env with
| Some env -> env
| None -> assert false (* a compilation unit cannot refer to a functor *)

let open_signature ?(used_slot = ref false) ?(loc = Location.none)
?(toplevel = false) ovf root env =
if
Expand Down
2 changes: 0 additions & 2 deletions compiler/ml/env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ val open_signature :
t ->
t option

val open_pers_signature : string -> t -> t

(* Insertion by name *)

val enter_value :
Expand Down
3 changes: 0 additions & 3 deletions compiler/ml/lambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,13 @@ type tag_info =
fields: string array;
mutable_flag: Asttypes.mutable_flag;
}
| Blk_lazy_general

let tag_of_tag_info (tag : tag_info) =
match tag with
| Blk_constructor {tag} | Blk_record_inlined {tag} -> tag
| Blk_tuple | Blk_poly_var _ | Blk_record _ | Blk_module _
| Blk_module_export _ | Blk_extension | Blk_some (* tag not make sense *)
| Blk_some_not_nested (* tag not make sense *)
| Blk_lazy_general (* tag not make sense 248 *)
| Blk_record_ext _ (* similar to Blk_extension*) ->
0

Expand All @@ -64,7 +62,6 @@ let mutable_flag_of_tag_info (tag : tag_info) =
| Blk_record {mutable_flag}
| Blk_record_ext {mutable_flag} ->
mutable_flag
| Blk_lazy_general -> Mutable
| Blk_tuple | Blk_constructor _ | Blk_poly_var _ | Blk_module _
| Blk_module_export _ | Blk_extension | Blk_some_not_nested | Blk_some ->
Immutable
Expand Down
1 change: 0 additions & 1 deletion compiler/ml/lambda.mli
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ type tag_info =
| Blk_some_not_nested
(* ['a option] where ['a] can not inhabit a non-like value *)
| Blk_record_ext of {fields: string array; mutable_flag: mutable_flag}
| Blk_lazy_general

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

Expand Down
Loading