Skip to content

Commit cd938d6

Browse files
committed
Do not special case variants with only 1 case with payload.
Also the comment is not emitted anymore, since there's always a tag. Not special casing means that the representation is uniform, and does not change when the type is extended. This is important with zero cost ffi, where the runtime representation is exposed to the user, to reduce possible surprises.
1 parent 501b4a4 commit cd938d6

Some content is hidden

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

64 files changed

+907
-464
lines changed

jscomp/core/js_dump.ml

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -771,15 +771,8 @@ and expression_desc cxt ~(level : int) f x : cxt =
771771
| Undefined when is_optional f -> None
772772
| _ -> Some (f, x))
773773
in
774-
if p.num_nonconst = 1 then tails
775-
else
776-
( Js_op.Lit L.tag,
777-
E.str p.name
778-
)
779-
:: tails
774+
(Js_op.Lit L.tag, E.str p.name) :: tails
780775
in
781-
if p.num_nonconst = 1 && not !Js_config.debug then
782-
pp_comment_option f (Some p.name);
783776
expression_desc cxt ~level f (Object objs)
784777
| Caml_block (el, _, tag, Blk_constructor p) ->
785778
let not_is_cons = p.name <> Literals.cons in
@@ -796,15 +789,13 @@ and expression_desc cxt ~(level : int) f x : cxt =
796789
[ (name_symbol, E.str p.name) ]
797790
else [])
798791
in
799-
if p.num_nonconst = 1 then tails
792+
if not_is_cons = false && p.num_nonconst = 1 then tails
800793
else
801794
( Js_op.Lit L.tag,
802795
E.str p.name
803796
)
804797
:: tails
805798
in
806-
if p.num_nonconst = 1 && (not !Js_config.debug) && not_is_cons then
807-
pp_comment_option f (Some p.name);
808799
expression_desc cxt ~level f (Object objs)
809800
| Caml_block
810801
( _,

jscomp/runtime/release.ninja

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ o runtime/caml_bytes.cmj : cc_cmi runtime/caml_bytes.ml | runtime/caml_bytes.cmi
2121
o runtime/caml_bytes.cmi : cc runtime/caml_bytes.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
2222
o runtime/caml_float.cmj : cc_cmi runtime/caml_float.ml | runtime/caml_float.cmi runtime/caml_float_extern.cmj
2323
o runtime/caml_float.cmi : cc runtime/caml_float.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
24-
o runtime/caml_format.cmj : cc_cmi runtime/caml_format.ml | runtime/caml.cmj runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
24+
o runtime/caml_format.cmj : cc_cmi runtime/caml_format.ml | runtime/caml_float.cmj runtime/caml_float_extern.cmj runtime/caml_format.cmi runtime/caml_int64.cmj runtime/caml_int64_extern.cmj runtime/caml_nativeint_extern.cmj runtime/caml_string_extern.cmj
2525
o runtime/caml_format.cmi : cc runtime/caml_format.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
2626
o runtime/caml_hash.cmj : cc_cmi runtime/caml_hash.ml | runtime/caml_hash.cmi runtime/caml_hash_primitive.cmj runtime/caml_nativeint_extern.cmj runtime/js.cmj
2727
o runtime/caml_hash.cmi : cc runtime/caml_hash.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
@@ -37,7 +37,7 @@ o runtime/caml_md5.cmj : cc_cmi runtime/caml_md5.ml | runtime/caml_array_extern.
3737
o runtime/caml_md5.cmi : cc runtime/caml_md5.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
3838
o runtime/caml_module.cmj : cc_cmi runtime/caml_module.ml | runtime/caml_array_extern.cmj runtime/caml_module.cmi runtime/caml_obj.cmj
3939
o runtime/caml_module.cmi : cc runtime/caml_module.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
40-
o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.ml | runtime/caml.cmj runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj runtime/js.cmj
40+
o runtime/caml_obj.cmj : cc_cmi runtime/caml_obj.ml | runtime/caml_array_extern.cmj runtime/caml_obj.cmi runtime/caml_option.cmj runtime/js.cmj
4141
o runtime/caml_obj.cmi : cc runtime/caml_obj.mli | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
4242
o runtime/caml_option.cmj : cc_cmi runtime/caml_option.ml | runtime/caml_option.cmi runtime/caml_undefined_extern.cmj runtime/js.cmj
4343
o runtime/caml_option.cmi : cc runtime/caml_option.mli | runtime/bs_stdlib_mini.cmi runtime/caml_undefined_extern.cmj runtime/js.cmi runtime/js.cmj
@@ -54,7 +54,7 @@ o runtime/caml_exceptions.cmi runtime/caml_exceptions.cmj : cc runtime/caml_exce
5454
o runtime/caml_external_polyfill.cmi runtime/caml_external_polyfill.cmj : cc runtime/caml_external_polyfill.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
5555
o runtime/caml_float_extern.cmi runtime/caml_float_extern.cmj : cc runtime/caml_float_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
5656
o runtime/caml_int64_extern.cmi runtime/caml_int64_extern.cmj : cc runtime/caml_int64_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
57-
o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.ml | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/caml_option.cmj runtime/js.cmi runtime/js.cmj
57+
o runtime/caml_js_exceptions.cmi runtime/caml_js_exceptions.cmj : cc runtime/caml_js_exceptions.ml | runtime/bs_stdlib_mini.cmi runtime/caml_exceptions.cmj runtime/js.cmi runtime/js.cmj
5858
o runtime/caml_nativeint_extern.cmi runtime/caml_nativeint_extern.cmj : cc runtime/caml_nativeint_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
5959
o runtime/caml_string_extern.cmi runtime/caml_string_extern.cmj : cc runtime/caml_string_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj
6060
o runtime/caml_undefined_extern.cmi runtime/caml_undefined_extern.cmj : cc runtime/caml_undefined_extern.ml | runtime/bs_stdlib_mini.cmi runtime/js.cmi runtime/js.cmj

jscomp/test/406_primitive_test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ function eq(loc, x, y) {
1818

1919
eq("File \"406_primitive_test.ml\", line 18, characters 6-13", 32, 32);
2020

21-
var backend_type = /* Other */{
21+
var backend_type = {
22+
TAG: "Other",
2223
_0: "BS"
2324
};
2425

25-
eq("File \"406_primitive_test.ml\", line 29, characters 6-13", backend_type, /* Other */{
26+
eq("File \"406_primitive_test.ml\", line 29, characters 6-13", backend_type, {
27+
TAG: "Other",
2628
_0: "BS"
2729
});
2830

jscomp/test/a_recursive_type.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ function g(x) {
66
return Curry._1(x._0, x);
77
}
88

9-
var loop = g(/* A */{
9+
var loop = g({
10+
TAG: "A",
1011
_0: g
1112
});
1213

13-
var x = /* A */{
14+
var x = {
15+
TAG: "A",
1416
_0: g
1517
};
1618

jscomp/test/bal_set_mini.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function height(param) {
1212
function create(l, v, r) {
1313
var hl = height(l);
1414
var hr = height(r);
15-
return /* Node */{
15+
return {
16+
TAG: "Node",
1617
_0: l,
1718
_1: v,
1819
_2: r,
@@ -39,7 +40,8 @@ function bal(l, v, r) {
3940
}
4041
}
4142
if (hr <= (hl + 2 | 0)) {
42-
return /* Node */{
43+
return {
44+
TAG: "Node",
4345
_0: l,
4446
_1: v,
4547
_2: r,
@@ -73,7 +75,8 @@ function compare_int(x, y) {
7375

7476
function add(x, t) {
7577
if (typeof t !== "object") {
76-
return /* Node */{
78+
return {
79+
TAG: "Node",
7780
_0: "Empty",
7881
_1: x,
7982
_2: "Empty",

jscomp/test/bdd.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,8 @@ function mkNode(low, v, high) {
170170
}
171171
} else {
172172
var n_2 = (nodeC.contents = nodeC.contents + 1 | 0, nodeC.contents);
173-
var n$1 = /* Node */{
173+
var n$1 = {
174+
TAG: "Node",
174175
_0: low,
175176
_1: v,
176177
_2: n_2,

jscomp/test/debug_mode_value.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
var u = {
5+
TAG: "A",
56
_0: 1,
67
_1: 2,
78
[Symbol.for("name")]: "A"

jscomp/test/defunctor_make_test.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ function height(param) {
2626
function create(l, x, d, r) {
2727
var hl = height(l);
2828
var hr = height(r);
29-
return /* Node */{
29+
return {
30+
TAG: "Node",
3031
_0: l,
3132
_1: x,
3233
_2: d,
@@ -65,7 +66,8 @@ function bal(l, x, d, r) {
6566
};
6667
}
6768
if (hr <= (hl + 2 | 0)) {
68-
return /* Node */{
69+
return {
70+
TAG: "Node",
6971
_0: l,
7072
_1: x,
7173
_2: d,
@@ -99,7 +101,8 @@ function bal(l, x, d, r) {
99101

100102
function add(x, data, compare, param) {
101103
if (typeof param !== "object") {
102-
return /* Node */{
104+
return {
105+
TAG: "Node",
103106
_0: "Empty",
104107
_1: x,
105108
_2: data,
@@ -113,7 +116,8 @@ function add(x, data, compare, param) {
113116
var l = param._0;
114117
var c = compare(x, v);
115118
if (c === 0) {
116-
return /* Node */{
119+
return {
120+
TAG: "Node",
117121
_0: l,
118122
_1: x,
119123
_2: data,

jscomp/test/demo_int_map.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ function height(param) {
1212
function create(l, x, d, r) {
1313
var hl = height(l);
1414
var hr = height(r);
15-
return /* Node */{
15+
return {
16+
TAG: "Node",
1617
l: l,
1718
v: x,
1819
d: d,
@@ -51,7 +52,8 @@ function bal(l, x, d, r) {
5152
};
5253
}
5354
if (hr <= (hl + 2 | 0)) {
54-
return /* Node */{
55+
return {
56+
TAG: "Node",
5557
l: l,
5658
v: x,
5759
d: d,
@@ -85,7 +87,8 @@ function bal(l, x, d, r) {
8587

8688
function add(x, data, m) {
8789
if (typeof m !== "object") {
88-
return /* Node */{
90+
return {
91+
TAG: "Node",
8992
l: "Empty",
9093
v: x,
9194
d: data,
@@ -102,7 +105,8 @@ function add(x, data, m) {
102105
if (d === data) {
103106
return m;
104107
} else {
105-
return /* Node */{
108+
return {
109+
TAG: "Node",
106110
l: l,
107111
v: x,
108112
d: data,

jscomp/test/demo_page.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ function map(f, param) {
2424
if (typeof param !== "object") {
2525
return "Nil";
2626
} else {
27-
return /* Cons */{
27+
return {
28+
TAG: "Cons",
2829
_0: Curry._1(f, param._0),
2930
_1: map(f, param._1)
3031
};

jscomp/test/derive_projector_test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,15 @@ var h = {
9191
};
9292

9393
function xx(param_0) {
94-
return /* Xx */{
94+
return {
95+
TAG: "Xx",
9596
_0: param_0
9697
};
9798
}
9899

99100
function a(param_0) {
100-
return /* A */{
101+
return {
102+
TAG: "A",
101103
_0: param_0
102104
};
103105
}

jscomp/test/flexible_array_test.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ function sub(_tr, _k) {
3232
function update(tr, k, w) {
3333
if (typeof tr !== "object") {
3434
if (k === 1) {
35-
return /* Br */{
35+
return {
36+
TAG: "Br",
3637
_0: w,
3738
_1: "Lf",
3839
_2: "Lf"
@@ -46,21 +47,24 @@ function update(tr, k, w) {
4647
var r = tr._2;
4748
var l = tr._1;
4849
if (k === 1) {
49-
return /* Br */{
50+
return {
51+
TAG: "Br",
5052
_0: w,
5153
_1: l,
5254
_2: r
5355
};
5456
}
5557
var v = tr._0;
5658
if (k % 2 === 0) {
57-
return /* Br */{
59+
return {
60+
TAG: "Br",
5861
_0: v,
5962
_1: update(l, k / 2 | 0, w),
6063
_2: r
6164
};
6265
} else {
63-
return /* Br */{
66+
return {
67+
TAG: "Br",
6468
_0: v,
6569
_1: l,
6670
_2: update(r, k / 2 | 0, w)
@@ -82,13 +86,15 @@ function $$delete(tr, n) {
8286
var l = tr._1;
8387
var v = tr._0;
8488
if (n % 2 === 0) {
85-
return /* Br */{
89+
return {
90+
TAG: "Br",
8691
_0: v,
8792
_1: $$delete(l, n / 2 | 0),
8893
_2: r
8994
};
9095
} else {
91-
return /* Br */{
96+
return {
97+
TAG: "Br",
9298
_0: v,
9399
_1: l,
94100
_2: $$delete(r, n / 2 | 0)
@@ -98,13 +104,15 @@ function $$delete(tr, n) {
98104

99105
function loext(tr, w) {
100106
if (typeof tr !== "object") {
101-
return /* Br */{
107+
return {
108+
TAG: "Br",
102109
_0: w,
103110
_1: "Lf",
104111
_2: "Lf"
105112
};
106113
} else {
107-
return /* Br */{
114+
return {
115+
TAG: "Br",
108116
_0: w,
109117
_1: loext(tr._2, tr._0),
110118
_2: tr._1
@@ -121,7 +129,8 @@ function lorem(tr) {
121129
}
122130
var l = tr._1;
123131
if (typeof l === "object") {
124-
return /* Br */{
132+
return {
133+
TAG: "Br",
125134
_0: l._0,
126135
_1: tr._2,
127136
_2: lorem(l)

0 commit comments

Comments
 (0)