Skip to content

Commit 9b9bf2b

Browse files
committed
make sure rest is used and move logic to its own files
1 parent a609047 commit 9b9bf2b

35 files changed

+494
-424
lines changed

compiler/core/lam_analysis.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let rec no_side_effects (lam : Lam.t) : bool =
5353
(* whether it's mutable or not *)
5454
| Pfield _ | Pval_from_option | Pval_from_option_not_nest
5555
(* NOP The compiler already [t option] is the same as t *)
56-
| Pduprecord | Precord_spread_new _
56+
| Pduprecord | Precord_rest _
5757
(* generic primitives *)
5858
| Pobjcomp _ | Pobjorder | Pobjmin | Pobjmax | Pobjtag | Pobjsize
5959
(* bool primitives *)

compiler/core/lam_compile_primitive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ let translate output_prefix loc (cxt : Lam_compile_context.t)
603603
match args with
604604
| [e1] -> E.obj ~dup:e1 []
605605
| _ -> assert false)
606-
| Precord_spread_new excluded -> (
606+
| Precord_rest excluded -> (
607607
match args with
608608
| [e1] ->
609609
(* Generate: (({field1: __unused0, ...__rest}) => __rest)(source)

compiler/core/lam_convert.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,7 @@ let lam_prim ~primitive:(p : Lambda.primitive) ~args loc : Lam.t =
205205
| Pfield (id, info) -> prim ~primitive:(Pfield (id, info)) ~args loc
206206
| Psetfield (id, info) -> prim ~primitive:(Psetfield (id, info)) ~args loc
207207
| Pduprecord -> prim ~primitive:Pduprecord ~args loc
208-
| Precord_spread_new excluded ->
209-
prim ~primitive:(Precord_spread_new excluded) ~args loc
208+
| Precord_rest excluded -> prim ~primitive:(Precord_rest excluded) ~args loc
210209
| Praise _ -> prim ~primitive:Praise ~args loc
211210
| Pobjcomp x -> prim ~primitive:(Pobjcomp x) ~args loc
212211
| Pobjorder -> prim ~primitive:Pobjorder ~args loc

compiler/core/lam_primitive.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type t =
4040
| Psetfield of int * Lam_compat.set_field_dbg_info
4141
(* could have field info at least for record *)
4242
| Pduprecord
43-
| Precord_spread_new of string list
43+
| Precord_rest of string list
4444
(* External call *)
4545
| Pjs_call of {
4646
prim_name: string;
@@ -227,7 +227,7 @@ let eq_primitive_approx (lhs : t) (rhs : t) =
227227
| Pnull_to_opt | Pnull_undefined_to_opt | Pis_null | Pis_not_none | Psome
228228
| Psome_not_nest | Pis_undefined | Pis_null_undefined | Pimport | Ptypeof
229229
| Pfn_arity | Pis_poly_var_block | Pdebugger | Pinit_mod | Pupdate_mod
230-
| Pduprecord | Precord_spread_new _ | Pmakearray | Parraylength | Parrayrefu
230+
| Pduprecord | Precord_rest _ | Pmakearray | Parraylength | Parrayrefu
231231
| Parraysetu | Parrayrefs | Parraysets | Pjs_fn_make_unit | Pjs_fn_method
232232
| Phash | Phash_mixstring | Phash_mixint | Phash_finalmix ->
233233
rhs = lhs

compiler/core/lam_primitive.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type t =
3636
| Pfield of int * Lambda.field_dbg_info
3737
| Psetfield of int * Lambda.set_field_dbg_info
3838
| Pduprecord
39-
| Precord_spread_new of string list
39+
| Precord_rest of string list
4040
| Pjs_call of {
4141
(* Location.t * [loc] is passed down *)
4242
prim_name: string;

compiler/core/lam_print.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ let primitive ppf (prim : Lam_primitive.t) =
8181
let instr = "setfield " in
8282
fprintf ppf "%s%i" instr n
8383
| Pduprecord -> fprintf ppf "duprecord"
84-
| Precord_spread_new excluded ->
85-
fprintf ppf "record_spread_new(%s)" (String.concat ", " excluded)
84+
| Precord_rest excluded ->
85+
fprintf ppf "record_rest(%s)" (String.concat ", " excluded)
8686
| Pjs_call {prim_name} -> fprintf ppf "%s[js]" prim_name
8787
| Pjs_object_create _ -> fprintf ppf "[js.obj]"
8888
| Praise -> fprintf ppf "raise"

compiler/frontend/ast_tuple_pattern_flatten.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ let flattern_tuple_pattern_vb (self : Bs_ast_mapper.mapper)
6565
:: acc)
6666
| _ -> {pvb_pat; pvb_expr; pvb_loc = vb.pvb_loc; pvb_attributes} :: acc)
6767
| Ppat_record (_, _, Some rest), Pexp_pack {pmod_desc = Pmod_ident _} ->
68-
Location.raise_errorf ~loc:rest.ppat_loc
68+
Location.raise_errorf ~loc:rest.rest_loc
6969
"Record rest patterns are not supported when destructuring modules. Bind \
7070
the module fields explicitly."
7171
| Ppat_record (lid_pats, _, None), Pexp_pack {pmod_desc = Pmod_ident id} ->

compiler/frontend/bs_ast_mapper.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,13 @@ module P = struct
430430
?rest:
431431
(match rest with
432432
| None -> None
433-
| Some p -> Some (sub.pat sub p))
433+
| Some {rest_loc; rest_name; rest_type} ->
434+
Some
435+
{
436+
rest_loc = sub.location sub rest_loc;
437+
rest_name = map_loc sub rest_name;
438+
rest_type = map_opt (sub.typ sub) rest_type;
439+
})
434440
(List.map
435441
(fun {lid; x = p; opt} ->
436442
{lid = map_loc sub lid; x = sub.pat sub p; opt})

compiler/ml/ast_helper.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ module Pat : sig
102102
val record :
103103
?loc:loc ->
104104
?attrs:attrs ->
105-
?rest:pattern ->
105+
?rest:record_pat_rest ->
106106
pattern record_element list ->
107107
closed_flag ->
108108
pattern

compiler/ml/ast_iterator.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,11 @@ module P = struct
404404
iter_loc sub lid;
405405
sub.pat sub pat)
406406
lpl;
407-
iter_opt (sub.pat sub) rest
407+
iter_opt
408+
(fun {rest_name; rest_type; _} ->
409+
iter_loc sub rest_name;
410+
iter_opt (sub.typ sub) rest_type)
411+
rest
408412
| Ppat_array pl -> List.iter (sub.pat sub) pl
409413
| Ppat_or (p1, p2) ->
410414
sub.pat sub p1;

0 commit comments

Comments
 (0)