Skip to content

Commit c3f972d

Browse files
authored
Merge pull request #4421 from BuckleScript/bump
list special handling
2 parents 310665d + 02122ef commit c3f972d

File tree

328 files changed

+17630
-17411
lines changed

Some content is hidden

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

328 files changed

+17630
-17411
lines changed

jscomp/core/js_dump.ml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,9 +853,15 @@ and expression_desc cxt ~(level:int) f x : cxt =
853853
pp_comment_option f (Some p.name);
854854
expression_desc cxt ~level f (Object objs)
855855
| Caml_block(el,_,tag, (Blk_constructor p)) ->
856+
let is_cons = p.name = Literals.cons in
856857
let objs =
857858
let tails =
858-
Ext_list.mapi_append el (fun i e -> "_" ^ string_of_int i , e )
859+
Ext_list.mapi_append el (fun i e ->
860+
(match is_cons, i with
861+
| true, 0 -> Literals.hd
862+
| true, 1 -> Literals.tl
863+
| _ ->
864+
"_" ^ string_of_int i) , e )
859865
(if !Js_config.debug then
860866
["NAME", E.str p.name]
861867
else []) in
@@ -865,7 +871,8 @@ and expression_desc cxt ~(level:int) f x : cxt =
865871
(L.tag,
866872
if !Js_config.debug then tag else {tag with comment = Some p.name}) :: tails
867873
in
868-
if p.num_nonconst = 1 && not !Js_config.debug then
874+
if p.num_nonconst = 1 && not !Js_config.debug
875+
&& not is_cons then
869876
pp_comment_option f (Some p.name);
870877
expression_desc cxt ~level f (Object objs)
871878
| Caml_block ( _, _, _, (Blk_module_export | Blk_na _ )) -> assert false

jscomp/core/js_exp_make.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,16 @@ let record_access (e : t) (name : string) (pos : int32) =
374374
(* The same as {!record_access} except tag*)
375375
let inline_record_access = record_access
376376

377+
let variant_access (e : t) (pos : int32) =
378+
inline_record_access e ("_" ^ Int32.to_string pos) pos
379+
380+
let cons_access (e : t) (pos : int32) =
381+
inline_record_access e
382+
(match pos with
383+
| 0l -> Literals.hd
384+
| 1l -> Literals.tl
385+
| _ -> ("_" ^ Int32.to_string pos)) pos
386+
377387
let poly_var_tag_access (e : t) =
378388
match e.expression_desc with
379389
| Caml_block (l,_, _, _) when no_side_effect e

jscomp/core/js_exp_make.mli

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,15 @@ val inline_record_access :
194194
Int32.t ->
195195
t
196196

197+
val variant_access :
198+
t ->
199+
int32 ->
200+
t
201+
202+
val cons_access :
203+
t ->
204+
int32 ->
205+
t
197206

198207
val extension_access :
199208
t ->

jscomp/core/js_of_lam_block.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ let field (field_info : Lam_compat.field_dbg_info) e (i : int32) =
6565
E.extension_access e (Some name) i
6666
| Fld_extension ->
6767
E.extension_access e None i
68-
| Fld_variant
69-
->
70-
E.inline_record_access e
71-
("_" ^ Int32.to_string i) i
68+
| Fld_variant ->
69+
E.variant_access e i
70+
| Fld_cons ->
71+
E.cons_access e i
7272
| Fld_record_inline {name}
7373
-> E.inline_record_access e name i
7474
| Fld_record {name}

jscomp/core/lam_compat.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ type field_dbg_info = Lambda.field_dbg_info =
129129
| Fld_poly_var_content
130130
| Fld_extension
131131
| Fld_variant
132+
| Fld_cons
132133
| Fld_array
133134

134135
let str_of_field_info (x : field_dbg_info) : string option =
@@ -137,6 +138,7 @@ let str_of_field_info (x : field_dbg_info) : string option =
137138
| Fld_array
138139
| Fld_extension
139140
| Fld_variant
141+
| Fld_cons
140142
| Fld_poly_var_tag
141143
| Fld_poly_var_content
142144
| Fld_tuple

jscomp/core/lam_compat.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ type field_dbg_info = Lambda.field_dbg_info =
6767
| Fld_poly_var_content
6868
| Fld_extension
6969
| Fld_variant
70+
| Fld_cons
7071
| Fld_array
7172

7273
val str_of_field_info :

jscomp/core/lam_compile.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,13 @@ and compile_recursive_let ~all_bindings
391391
(match tag_info with
392392
| Blk_record xs -> Fld_record_set xs.(i)
393393
| Blk_record_inlined xs -> Fld_record_inline_set xs.fields.(i)
394-
| Blk_constructor _ -> Fld_record_inline_set ("_" ^ string_of_int i)
394+
| Blk_constructor p ->
395+
let is_cons = p.name = Literals.cons in
396+
begin match is_cons,i with
397+
| true, 0 -> Fld_record_inline_set Literals.hd
398+
| true, 1 -> Fld_record_inline_set Literals.tl
399+
| _, _ -> Fld_record_inline_set ("_" ^ string_of_int i)
400+
end
395401
| _ -> assert false) (E.var id) (Int32.of_int i)
396402
(match x with
397403
| Lvar lid -> E.var lid

jscomp/ext/literals.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,8 @@ let ns_sep = "-"
142142
let exception_id = "RE_EXN_ID"
143143

144144
let polyvar_hash = "HASH"
145-
let polyvar_value = "value"
145+
let polyvar_value = "value"
146+
147+
let cons = "::"
148+
let hd = "hd"
149+
let tl = "tl"

jscomp/ext/literals.mli

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,8 @@ val ns_sep : string
140140
val exception_id : string
141141

142142
val polyvar_hash : string
143-
val polyvar_value : string
143+
val polyvar_value : string
144+
145+
val cons : string
146+
val hd : string
147+
val tl : string

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 3 additions & 3 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)