Skip to content

Commit bb8437b

Browse files
committed
pass lambda tag_info as is
1 parent 2005509 commit bb8437b

16 files changed

+81
-130
lines changed

jscomp/core/js_dump.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ let exn_block_as_obj
117117
| i ->
118118
"_" ^ string_of_int i
119119
)
120-
| Blk_record_ext ss ->
120+
| Blk_record_ext {fields = ss} ->
121121
(fun i ->
122122
match i with
123123
| 0 -> Literals.exception_id
@@ -167,7 +167,7 @@ let exp_need_paren (e : J.expression) =
167167

168168
| Raw_js_code {code_info = Exp _}
169169
| Fun _
170-
| Caml_block (_,_,_, (Blk_record _ | Blk_module _ | Blk_poly_var | Blk_extension | Blk_record_ext _ | Blk_record_inlined _ | Blk_constructor _ ))
170+
| Caml_block (_,_,_, (Blk_record _ | Blk_module _ | Blk_poly_var _ | Blk_extension | Blk_record_ext _ | Blk_record_inlined _ | Blk_constructor _ ))
171171
| Object _ -> true
172172
| Raw_js_code {code_info = Stmt _ }
173173
| Length _
@@ -804,14 +804,14 @@ and expression_desc cxt ~(level:int) f x : cxt =
804804
fields el
805805
(fun x -> Js_op.Lit (Ext_ident.convert x) ))))
806806
(*name convention of Record is slight different from modules*)
807-
| Caml_block(el,mutable_flag, _, Blk_record fields) ->
807+
| Caml_block(el,mutable_flag, _, Blk_record {fields}) ->
808808
if Ext_array.for_alli fields (fun i v -> string_of_int i = v) then
809809
expression_desc cxt ~level f (Array (el, mutable_flag))
810810
else
811811
expression_desc cxt ~level f (Object
812812
((Ext_list.combine_array fields el (fun i -> Js_op.Lit i))))
813813

814-
| Caml_block(el,_,_, Blk_poly_var ) ->
814+
| Caml_block(el,_,_, Blk_poly_var _) ->
815815
begin match el with
816816
| [tag;value] ->
817817
expression_desc
@@ -863,8 +863,8 @@ and expression_desc cxt ~(level:int) f x : cxt =
863863
&& not_is_cons then
864864
pp_comment_option f (Some p.name);
865865
expression_desc cxt ~level f (Object objs)
866-
| Caml_block ( _, _, _, (Blk_module_export )) -> assert false
867-
| Caml_block( el, mutable_flag, _tag, (Blk_tuple | Blk_array ))
866+
| Caml_block ( _, _, _, (Blk_module_export _ | Blk_some | Blk_some_not_nested | Blk_lazy_general)) -> assert false
867+
| Caml_block( el, mutable_flag, _tag, (Blk_tuple ))
868868
->
869869
expression_desc cxt ~level f (Array (el, mutable_flag))
870870

jscomp/core/js_exp_make.ml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,17 +264,19 @@ let dummy_obj ?comment (info : Lam_tag_info.t) : t =
264264
| Blk_module _
265265
| Blk_constructor _
266266
| Blk_record_inlined _
267-
| Blk_poly_var
267+
| Blk_poly_var _
268268
| Blk_extension
269269
| Blk_record_ext _
270270
->
271271
{comment ; expression_desc = Object []}
272-
| Blk_tuple | Blk_array
272+
| Blk_tuple
273273

274-
| Blk_module_export
274+
| Blk_module_export _
275275
->
276276
{comment ; expression_desc = Array ([],Mutable)}
277-
277+
| Blk_some
278+
| Blk_some_not_nested
279+
| Blk_lazy_general -> assert false
278280

279281
(* TODO: complete
280282
pure ...

jscomp/core/js_of_lam_block.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ module E = Js_exp_make
3737
let make_block mutable_flag (tag_info : Lam_tag_info.t) tag args =
3838

3939
match tag_info with
40-
| Blk_array -> Js_of_lam_array.make_array mutable_flag args
40+
4141
| _ -> E.make_block tag tag_info args mutable_flag
4242
(* | _, ( Tuple | Variant _ ) -> (\** TODO: check with inline record *\) *)
4343
(* E.arr Immutable *)

jscomp/core/js_of_lam_variant.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ let eval (arg : J.expression) (dispatches : (string * string) list ) : E.t =
5353
(* arg is a polyvar *)
5454
let eval_as_event (arg : J.expression) (dispatches : (string * string) list option) =
5555
match arg.expression_desc with
56-
| Caml_block([{expression_desc = Str(_,s)}; cb], _, _, Blk_poly_var ) when Js_analyzer.no_side_effect_expression cb
56+
| Caml_block([{expression_desc = Str(_,s)}; cb], _, _, Blk_poly_var _ ) when Js_analyzer.no_side_effect_expression cb
5757
->
5858
let v =
5959
match dispatches with

jscomp/core/js_pass_flatten_and_mark_dead.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ let subst_map (substitution : J.expression Hash_ident.t) = { super
197197
(match Ext_list.nth_opt fields i with
198198
| None -> Printf.sprintf "%d" i
199199
| Some x -> x )
200-
| Blk_record fields ->
200+
| Blk_record {fields} ->
201201
Ext_array.get_or fields i (fun _ -> Printf.sprintf "%d" i)
202202
| _ -> Printf.sprintf "%d" i
203203
)) in

jscomp/core/lam_compile.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ and compile_recursive_let ~all_bindings
389389
S.exp
390390
(Js_of_lam_block.set_field
391391
(match tag_info with
392-
| Blk_record xs -> Fld_record_set xs.(i)
392+
| Blk_record {fields = xs} -> Fld_record_set xs.(i)
393393
| Blk_record_inlined xs -> Fld_record_inline_set xs.fields.(i)
394394
| Blk_constructor p ->
395395
let is_cons = p.name = Literals.cons in

jscomp/core/lam_compile_primitive.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ let translate loc
487487
| Backend_type ->
488488
E.make_block
489489
E.zero_int_literal
490-
(Blk_constructor {name = "Other"; num_nonconst = 1})
490+
(Blk_constructor {name = "Other"; num_nonconst = 1; tag = 0})
491491
[E.str "BS"] Immutable
492492
)
493493
| Pduprecord (Record_regular| Record_extension| Record_inlined _ ) ->

jscomp/core/lam_compile_util.ml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,16 @@ let comment_of_tag_info (x : Lam_tag_info.t) =
4444
match x with
4545
| Blk_constructor {name = n} -> Some n
4646
| Blk_tuple -> Some "tuple"
47-
| Blk_poly_var -> None
47+
| Blk_poly_var _ -> None
4848
| Blk_record _ -> None
4949
| Blk_record_inlined {name = ctor} -> Some ctor
5050
| Blk_record_ext _ -> None
51-
| Blk_array ->
52-
(* so far only appears in {!Translclass}
53-
and some constant immutable array block
54-
*)
55-
Some "array"
56-
| Blk_module_export
51+
| Blk_module_export _
5752
| Blk_module _ ->
5853
(* Turn it on next time to save some noise diff*)
5954
None
6055
| Blk_extension (* TODO: enhance it later *)
6156
-> None
6257

63-
58+
| Blk_some | Blk_some_not_nested | Blk_lazy_general -> assert false
6459
(* let module_alias = Some "alias" *)

jscomp/core/lam_constant_convert.ml

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -65,47 +65,28 @@ let rec convert_constant ( const : Lambda.structured_constant) : Lam_constant.t
6565
Const_some (convert_constant (Ext_list.singleton_exn xs))
6666
| Blk_some ->
6767
Const_some (convert_constant (Ext_list.singleton_exn xs))
68-
| Blk_constructor{name ; num_nonconst } ->
69-
let t : Lam_tag_info.t = Blk_constructor {name; num_nonconst} in
70-
Const_block (tag,t, Ext_list.map xs convert_constant )
71-
| Blk_tuple ->
72-
let t : Lam_tag_info.t = Blk_tuple in
68+
| Blk_constructor _
69+
| Blk_tuple
70+
| Blk_record _
71+
| Blk_module _
72+
| Blk_module_export _
73+
| Blk_extension
74+
| Blk_record_inlined _
75+
| Blk_record_ext _
76+
->
7377
Const_block (tag,t, Ext_list.map xs convert_constant )
7478
| Blk_poly_var s ->
7579
begin match xs with
7680
| [_; value] ->
77-
let t : Lam_tag_info.t = Blk_poly_var in
7881
let tag_val : Lam_constant.t =
7982
if Ext_string.is_valid_hash_number s then Const_int {i = Ext_string.hash_number_as_i32_exn s; comment = None}
8083
else Const_string s in
8184
Const_block (tag,t, [tag_val; convert_constant value] )
8285
| _ -> assert false
8386
end
84-
| Blk_record {fields = s} ->
85-
let t : Lam_tag_info.t = Blk_record s in
86-
Const_block (tag,t, Ext_list.map xs convert_constant )
87-
| Blk_module s ->
88-
let t : Lam_tag_info.t = Blk_module s in
89-
Const_block (tag,t, Ext_list.map xs convert_constant )
90-
| Blk_module_export _ ->
91-
let t : Lam_tag_info.t = Blk_module_export in
92-
Const_block (tag,t, Ext_list.map xs convert_constant )
93-
| Blk_extension_slot -> assert false
94-
(* let t : Lam_tag_info.t = Blk_extension_slot in
95-
Const_block (i,t, Ext_list.map xs convert_constant ) *)
96-
| Blk_extension ->
97-
let t : Lam_tag_info.t = Blk_extension in
98-
Const_block (tag,t, Ext_list.map xs convert_constant )
9987
| Blk_lazy_general
10088
-> assert false
10189

102-
| Blk_record_inlined {name;fields;num_nonconst} ->
103-
let t : Lam_tag_info.t = Blk_record_inlined {name;fields;num_nonconst} in
104-
Const_block (tag,t, Ext_list.map xs convert_constant )
105-
| Blk_record_ext {fields = s} ->
106-
let t : Lam_tag_info.t = Blk_record_ext s in
107-
Const_block(tag,t, Ext_list.map xs convert_constant)
108-
10990
end
11091

11192

jscomp/core/lam_convert.ml

Lines changed: 17 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ let lam_extension_id loc (head : Lam.t) =
3333
prim ~primitive:lam_caml_id ~args:[head] loc
3434

3535
let lazy_block_info : Lam_tag_info.t =
36-
Blk_record
37-
[|Literals.lazy_done;
38-
Literals.lazy_val|]
39-
40-
let unbox_extension info (args : Lam.t list) mutable_flag loc =
41-
prim ~primitive:(Pmakeblock (0,info,mutable_flag)) ~args loc
36+
Blk_record {
37+
fields = [|Literals.lazy_done; Literals.lazy_val|] ;
38+
mutable_flag = Mutable;
39+
record_repr = Record_regular
40+
}
4241

4342

4443
(** A conservative approach to avoid packing exceptions
@@ -214,6 +213,8 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
214213
| Pbytes_to_string (* handled very early *)
215214
-> prim ~primitive:Pbytes_to_string ~args loc
216215
| Pbytes_of_string -> prim ~primitive:Pbytes_of_string ~args loc
216+
| Pcreate_extension s ->
217+
prim ~primitive:(Pcreate_extension s) ~args loc
217218
| Pignore -> (* Pignore means return unit, it is not an nop *)
218219
seq (Ext_list.singleton_exn args) unit
219220
| Pgetglobal _ ->
@@ -233,43 +234,19 @@ let lam_prim ~primitive:( p : Lambda.primitive) ~args loc : Lam.t =
233234
| Blk_some
234235
->
235236
prim ~primitive:Psome ~args loc
236-
| Blk_constructor{name ; num_nonconst } ->
237-
let info : Lam_tag_info.t = Blk_constructor {name; num_nonconst} in
238-
prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
239-
| Blk_tuple ->
240-
let info : Lam_tag_info.t = Blk_tuple in
241-
prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
242-
| Blk_extension ->
243-
let info : Lam_tag_info.t = Blk_extension in
244-
unbox_extension info args mutable_flag loc
245-
| Blk_record_ext {fields = s} ->
246-
let info : Lam_tag_info.t = Blk_record_ext s in
247-
unbox_extension info args mutable_flag loc
248-
| Blk_extension_slot ->
249-
(
250-
match args with
251-
| [ Lconst (Const_string name)] ->
252-
prim ~primitive:(Pcreate_extension name) ~args:[] loc
253-
| _ ->
254-
assert false
255-
)
256-
257-
| Blk_record {fields = s} ->
258-
let info : Lam_tag_info.t = Blk_record s in
259-
prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
260-
| Blk_record_inlined {name; fields; num_nonconst} ->
261-
let info : Lam_tag_info.t = Blk_record_inlined {name; fields; num_nonconst} in
262-
prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
263-
| Blk_module s ->
264-
let info : Lam_tag_info.t = Blk_module s in
237+
| Blk_constructor _
238+
| Blk_tuple
239+
| Blk_record _
240+
| Blk_record_inlined _
241+
| Blk_module _
242+
| Blk_module_export _
243+
| Blk_extension
244+
| Blk_record_ext _
245+
->
265246
prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
266-
| Blk_module_export _ ->
267-
let info : Lam_tag_info.t = Blk_module_export in
268-
prim ~primitive:(Pmakeblock (tag,info,mutable_flag)) ~args loc
269247
| Blk_poly_var s ->
270248
begin match args with
271249
| [_; value] ->
272-
let info : Lam_tag_info.t = Blk_poly_var in
273250
let tag_val : Lam_constant.t =
274251
if Ext_string.is_valid_hash_number s then Const_int {i = Ext_string.hash_number_as_i32_exn s; comment = None}
275252
else Const_string s in
@@ -647,7 +624,7 @@ let convert (exports : Set_ident.t) (lam : Lambda.lambda) : Lam.t * Lam_module_i
647624
| "#apply7"
648625
| "#apply8" -> Pjs_apply
649626
| "#makemutablelist" ->
650-
Pmakeblock(0, Blk_constructor{name = "::"; num_nonconst = 1},Mutable)
627+
Pmakeblock(0, Blk_constructor{name = "::"; num_nonconst = 1; tag = 0},Mutable)
651628
| "#undefined_to_opt" -> Pundefined_to_opt
652629
| "#nullable_to_opt" -> Pnull_undefined_to_opt
653630
| "#null_to_opt" -> Pnull_to_opt

jscomp/core/lam_tag_info.ml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,4 @@
2727
it reduces some branches e.g,
2828
[Blk_some], [Blk_some_not_nested]
2929
*)
30-
type t =
31-
| Blk_tuple
32-
| Blk_array
33-
| Blk_poly_var
34-
| Blk_record of string array
35-
| Blk_module of string list
36-
| Blk_extension
37-
| Blk_record_ext of string array
38-
| Blk_record_inlined of { name : string ; num_nonconst : int; fields : string array }
39-
| Blk_constructor of {name : string ; num_nonconst : int}
40-
| Blk_module_export
30+
type t = Lambda.tag_info

jscomp/core/record_attributes_check.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,18 @@ let find_name_with_loc (attr : Parsetree.attribute) :
4343

4444
let fld_record (lbl : label) =
4545
Lambda.Fld_record
46-
{name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name; mutable_flag = lbl.Types.lbl_mut}
46+
{name = Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name; mutable_flag = lbl.lbl_mut}
4747

4848
let fld_record_set (lbl : label) =
4949
Lambda.Fld_record_set
5050
(Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name)
5151

52-
let blk_record fields mut =
52+
let blk_record (fields : (label * _) array) mut record_repr =
5353
let all_labels_info =
5454
Ext_array.map fields
55-
(fun ((lbl : label),_) ->
56-
Ext_list.find_def lbl.Types.lbl_attributes find_name lbl.lbl_name) in
57-
Lambda.Blk_record {fields = all_labels_info ; mutable_flag = mut}
55+
(fun (lbl,_) ->
56+
Ext_list.find_def lbl.lbl_attributes find_name lbl.lbl_name) in
57+
Lambda.Blk_record {fields = all_labels_info ; mutable_flag = mut; record_repr}
5858

5959
let check_bs_attributes_inclusion
6060
(attrs1 : Parsetree.attributes)

jscomp/ml/lambda.ml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@ type loc_kind =
3434
| Loc_LOC
3535
| Loc_POS
3636

37+
type record_repr =
38+
| Record_regular
39+
| Record_object
40+
3741
type tag_info =
3842
| Blk_constructor of {name : string ; num_nonconst : int ; tag : int }
3943
| Blk_record_inlined of { name : string ; num_nonconst : int; tag : int; fields : string array; mutable_flag : mutable_flag }
4044
| Blk_tuple
4145
| Blk_poly_var of string
42-
| Blk_record of {fields : string array; mutable_flag : mutable_flag}
46+
| Blk_record of {fields : string array; mutable_flag : mutable_flag; record_repr : record_repr}
4347
| Blk_module of string list
4448
| Blk_module_export of Ident.t list
45-
| Blk_extension_slot
49+
4650
| Blk_extension
4751
| Blk_some
4852
| Blk_some_not_nested (* ['a option] where ['a] can not inhabit a non-like value *)
@@ -58,7 +62,6 @@ let tag_of_tag_info (tag : tag_info ) =
5862
| Blk_record _
5963
| Blk_module _
6064
| Blk_module_export _
61-
| Blk_extension_slot (* tag not make sense 248 *)
6265
| Blk_extension
6366
| Blk_some (* tag not make sense *)
6467
| Blk_some_not_nested (* tag not make sense *)
@@ -77,14 +80,13 @@ let mutable_flag_of_tag_info (tag : tag_info) =
7780
| Blk_poly_var _
7881
| Blk_module _
7982
| Blk_module_export _
80-
| Blk_extension_slot
8183
| Blk_extension
8284
| Blk_some_not_nested
8385
| Blk_some
8486
-> Immutable
8587

8688

87-
let blk_record = ref (fun _ _ ->
89+
let blk_record = ref (fun _ _ _ ->
8890
assert false
8991
)
9092

@@ -99,7 +101,8 @@ let blk_record_inlined = ref (fun fields name num_nonconst ~tag mutable_flag ->
99101
Blk_record_inlined {fields; name; num_nonconst; tag; mutable_flag}
100102
)
101103

102-
let ref_tag_info : tag_info = Blk_record {fields = [| "contents" |]; mutable_flag = Mutable}
104+
let ref_tag_info : tag_info =
105+
Blk_record {fields = [| "contents" |]; mutable_flag = Mutable; record_repr = Record_regular}
103106

104107
type field_dbg_info =
105108
| Fld_record of {name : string; mutable_flag : Asttypes.mutable_flag}
@@ -214,6 +217,7 @@ type primitive =
214217
(* Inhibition of optimisation *)
215218
| Popaque
216219
| Puncurried_apply
220+
| Pcreate_extension of string
217221
and comparison =
218222
Ceq | Cneq | Clt | Cgt | Cle | Cge
219223

0 commit comments

Comments
 (0)