Skip to content

Commit b4d92a9

Browse files
committed
generate symbol fields for debugging purpose
1 parent 2d2eac4 commit b4d92a9

21 files changed

+337
-232
lines changed

jscomp/core/js_dump.ml

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
5151
*)
5252

53-
53+
let name_symbol = Js_op.Symbol_name
5454
module P = Ext_pp
5555
module E = Js_exp_make
5656
(* module S = Js_stmt_make *)
@@ -125,11 +125,11 @@ let exn_block_as_obj
125125
| _ -> assert false in
126126
Object (
127127
if stack then
128-
Ext_list.mapi_append el (fun i e -> field_name i, e)
129-
["Error",
128+
Ext_list.mapi_append el (fun i e -> Js_op.Lit (field_name i), e)
129+
[ Js_op.Lit "Error",
130130
E.new_ (E.js_global "Error") []
131131
]
132-
else Ext_list.mapi el (fun i e -> field_name i, e)
132+
else Ext_list.mapi el (fun i e -> Js_op.Lit (field_name i), e)
133133
)
134134

135135
let rec iter_lst cxt (f : P.t) ls element inter =
@@ -812,10 +812,13 @@ and expression_desc cxt ~(level:int) f x : cxt =
812812
E.runtime_call Js_runtime_modules.option "some" [e])
813813
| Caml_block(el,_, _, Blk_module fields) ->
814814
expression_desc cxt ~level f (Object (
815-
(Ext_list.map_combine fields el Ext_ident.convert)))
815+
(Ext_list.map_combine
816+
fields el
817+
(fun x -> Js_op.Lit (Ext_ident.convert x) ))))
816818
(*name convention of Record is slight different from modules*)
817819
| Caml_block(el,_, _, Blk_record fields) ->
818-
expression_desc cxt ~level f (Object ((Ext_list.combine_array fields el )))
820+
expression_desc cxt ~level f (Object
821+
((Ext_list.combine_array fields el (fun i -> Js_op.Lit i))))
819822

820823
| Caml_block(el,_,_, Blk_poly_var name) ->
821824
begin match el with
@@ -825,13 +828,13 @@ and expression_desc cxt ~(level:int) f x : cxt =
825828
~level
826829
f
827830
(Object
828-
((Literals.polyvar_hash,
831+
((Js_op.Lit Literals.polyvar_hash,
829832
if !Js_config.debug then hash
830833
else {hash with comment = Some name}
831834
) ::
832-
(Literals.polyvar_value, value) ::
835+
(Js_op.Lit Literals.polyvar_value, value) ::
833836
if !Js_config.debug then
834-
["name", E.str name]
837+
[name_symbol, E.str name]
835838
else []
836839
)
837840
)
@@ -843,11 +846,11 @@ and expression_desc cxt ~(level:int) f x : cxt =
843846
let objs =
844847
let tails =
845848
Ext_list.combine_array_append p.fields el
846-
(if !Js_config.debug then ["NAME",E.str p.name]
849+
(if !Js_config.debug then [name_symbol,E.str p.name]
847850
else []
848-
) in
851+
) (fun i -> Js_op.Lit i) in
849852
if p.num_nonconst = 1 then tails
850-
else (L.tag,
853+
else (Js_op.Lit L.tag,
851854
if !Js_config.debug then tag else {tag with comment = Some p.name}) :: tails in
852855
if p.num_nonconst = 1 && not !Js_config.debug then
853856
pp_comment_option f (Some p.name);
@@ -858,17 +861,17 @@ and expression_desc cxt ~(level:int) f x : cxt =
858861
let tails =
859862
Ext_list.mapi_append el (fun i e ->
860863
(match is_cons, i with
861-
| true, 0 -> Literals.hd
862-
| true, 1 -> Literals.tl
864+
| true, 0 -> Js_op.Lit Literals.hd
865+
| true, 1 -> Js_op.Lit Literals.tl
863866
| _ ->
864-
"_" ^ string_of_int i) , e )
867+
Js_op.Lit ("_" ^ string_of_int i)) , e )
865868
(if !Js_config.debug then
866-
["NAME", E.str p.name]
869+
[name_symbol, E.str p.name]
867870
else []) in
868871
if p.num_nonconst = 1 then
869872
tails
870873
else
871-
(L.tag,
874+
(Js_op.Lit L.tag,
872875
if !Js_config.debug then tag else {tag with comment = Some p.name}) :: tails
873876
in
874877
if p.num_nonconst = 1 && not !Js_config.debug

jscomp/core/js_dump_property.ml

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,12 @@ let property_access f s =
8787
Js_dump_string.pp_string f s
8888
end
8989

90-
let property_key f s =
91-
if obj_property_no_need_quot s then
92-
P.string f s
93-
else Js_dump_string.pp_string f s
90+
let property_key f (s : J.property_name) =
91+
match s with
92+
| Lit s ->
93+
if obj_property_no_need_quot s then
94+
P.string f s
95+
else Js_dump_string.pp_string f s
96+
| Symbol_name ->
97+
P.string f
98+
{|[Symbol.for("name")]|}

jscomp/core/js_dump_property.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ val property_access :
3131

3232
val property_key :
3333
Ext_pp.t ->
34-
string ->
34+
J.property_name ->
3535
unit

jscomp/core/js_op.ml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,10 @@ type property = Lam_compat.let_kind =
146146
| Variable
147147

148148

149-
type property_name = (* private *)
150-
(* TODO: FIXME [caml_uninitialized_obj] seems to be a bug*)
151-
(* | Key of *)
152-
string
153-
(* | Int_key of int *)
154-
(* | Tag *)
155-
(* | Length *)
156-
149+
type property_name =
150+
| Lit of string
151+
| Symbol_name
152+
157153
type 'a access =
158154
| Getter
159155
| Setter

jscomp/core/lam_compile_external_obj.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ let assemble_obj_args (labels : External_arg_spec.obj_params) (args : J.express
4848
| [] , [] -> [], [], []
4949
| {obj_arg_label = Obj_label {name = label; }; obj_arg_type = Arg_cst cst } :: labels , args ->
5050
let accs, eff, assign = aux labels args in
51-
(label, Lam_compile_const.translate_arg_cst cst )::accs, eff, assign
51+
(Js_op.Lit label, Lam_compile_const.translate_arg_cst cst )::accs, eff, assign
5252
(* | {obj_arg_label = EmptyCst _ } :: rest , args -> assert false *)
5353
| {obj_arg_label = Obj_empty }::labels, arg::args
5454
-> (* unit type*)
@@ -63,7 +63,7 @@ let assemble_obj_args (labels : External_arg_spec.obj_params) (args : J.express
6363
| Splice2 _
6464
| Splice0 -> assert false
6565
| Splice1 x ->
66-
(label, x) :: accs , Ext_list.append new_eff eff , assign
66+
(Js_op.Lit label, x) :: accs , Ext_list.append new_eff eff , assign
6767
end (* evaluation order is undefined *)
6868

6969
| ({obj_arg_label = Obj_optional {name = label}; obj_arg_type } as arg_kind)::labels, arg::args
@@ -77,7 +77,7 @@ let assemble_obj_args (labels : External_arg_spec.obj_params) (args : J.express
7777
| Splice2 _
7878
| Splice0 -> assert false
7979
| Splice1 x ->
80-
(label, x) :: accs , Ext_list.append new_eff eff , assign
80+
(Js_op.Lit label, x) :: accs , Ext_list.append new_eff eff , assign
8181
end )
8282
~not_sure:(fun _ -> accs, eff , (arg_kind,arg)::assign )
8383
| {obj_arg_label = Obj_empty | Obj_label _ | Obj_optional _ } :: _ , [] -> assert false

jscomp/ext/ext_list.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,22 @@ let rec map_combine l1 l2 f =
7676
| (_, _) ->
7777
invalid_arg "Ext_list.map_combine"
7878

79-
let rec combine_array_unsafe arr l i j acc =
79+
let rec combine_array_unsafe arr l i j acc f =
8080
if i = j then acc
8181
else
8282
match l with
8383
| [] -> invalid_arg "Ext_list.combine"
8484
| h :: tl ->
85-
(Array.unsafe_get arr i , h) ::
86-
combine_array_unsafe arr tl (i + 1) j acc
85+
(f (Array.unsafe_get arr i) , h) ::
86+
combine_array_unsafe arr tl (i + 1) j acc f
8787

88-
let combine_array_append arr l acc =
88+
let combine_array_append arr l acc f =
8989
let len = Array.length arr in
90-
combine_array_unsafe arr l 0 len acc
90+
combine_array_unsafe arr l 0 len acc f
9191

92-
let combine_array arr l =
92+
let combine_array arr l f =
9393
let len = Array.length arr in
94-
combine_array_unsafe arr l 0 len []
94+
combine_array_unsafe arr l 0 len [] f
9595

9696
let rec map_split_opt
9797
(xs : 'a list) (f : 'a -> 'b option * 'c option)

jscomp/ext/ext_list.mli

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ val map_combine :
3737
val combine_array:
3838
'a array ->
3939
'b list ->
40-
('a * 'b) list
40+
('a -> 'c) ->
41+
('c * 'b) list
4142

4243
val combine_array_append:
4344
'a array ->
4445
'b list ->
45-
('a * 'b) list ->
46-
('a * 'b) list
46+
('c * 'b) list ->
47+
('a -> 'c) ->
48+
('c * 'b) list
4749

4850
val has_string :
4951
string list ->

jscomp/test/build.ninja

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ build test/cps_test.cmi test/cps_test.cmj : cc test/cps_test.ml | test/mt.cmj $s
142142
build test/cross_module_inline_test.cmi test/cross_module_inline_test.cmj : cc test/cross_module_inline_test.ml | $stdlib
143143
build test/custom_error_test.cmi test/custom_error_test.cmj : cc test/custom_error_test.ml | $stdlib
144144
build test/debug_keep_test.cmi test/debug_keep_test.cmj : cc test/debug_keep_test.ml | $stdlib
145+
build test/debug_mode_value.cmi test/debug_mode_value.cmj : cc test/debug_mode_value.ml | $stdlib
145146
build test/debug_tmp.cmi test/debug_tmp.cmj : cc test/debug_tmp.ml | $stdlib
146147
build test/debugger_test.cmi test/debugger_test.cmj : cc test/debugger_test.ml | $stdlib
147148
build test/default_export_test.cmi test/default_export_test.cmj : cc test/default_export_test.ml | $stdlib
@@ -321,6 +322,7 @@ build test/gpr_4069_test.cmi test/gpr_4069_test.cmj : cc test/gpr_4069_test.ml |
321322
build test/gpr_4265_test.cmi test/gpr_4265_test.cmj : cc test/gpr_4265_test.ml | test/mt.cmj $stdlib
322323
build test/gpr_4274_test.cmi test/gpr_4274_test.cmj : cc test/gpr_4274_test.ml | $stdlib
323324
build test/gpr_4280_test.cmi test/gpr_4280_test.cmj : cc test/gpr_4280_test.ml | test/mt.cmj $stdlib
325+
build test/gpr_4407_test.cmi test/gpr_4407_test.cmj : cc test/gpr_4407_test.ml | test/debug_mode_value.cmj test/mt.cmj $stdlib
324326
build test/gpr_441.cmi test/gpr_441.cmj : cc test/gpr_441.ml | $stdlib
325327
build test/gpr_459_test.cmi test/gpr_459_test.cmj : cc test/gpr_459_test.ml | test/mt.cmj $stdlib
326328
build test/gpr_627_test.cmi test/gpr_627_test.cmj : cc test/gpr_627_test.ml | test/mt.cmj $stdlib

jscomp/test/debug_mode_value.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
'use strict';
2+
3+
4+
var u = {
5+
_0: 1,
6+
_1: 2,
7+
[Symbol.for("name")]: "A"
8+
};
9+
10+
exports.u = u;
11+
/* No side effect */

jscomp/test/debug_mode_value.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
[@@@bs.config {
3+
flags = [|
4+
(* "-drawlambda"; *)
5+
(* "-dlambda"; *)
6+
(* "-dtypedtree"; *)
7+
(* "-bs-diagnose" *)
8+
"-bs-g"
9+
|]
10+
}]
11+
12+
type t = A of int * int
13+
14+
let u = A (1,2)

0 commit comments

Comments
 (0)