Skip to content

Commit f8271f7

Browse files
authored
Merge pull request #1027 from bloomberg/fix_reg_test
fix some edge cases of recursive value
2 parents 195391b + a55f9e1 commit f8271f7

File tree

12 files changed

+254
-82
lines changed

12 files changed

+254
-82
lines changed

jscomp/bin/whole_compiler.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66373,9 +66373,9 @@ let method_
6637366373
comment
6637466374
}
6637566375

66376-
66376+
(** This is coupuled with {!Caml_obj.caml_update_dummy} *)
6637766377
let dummy_obj ?comment () : t =
66378-
{comment ; expression_desc = Object []}
66378+
{comment ; expression_desc = J.Array ([],Mutable)}
6637966379

6638066380
let is_instance_array ?comment e : t =
6638166381
{comment; expression_desc = Bin(InstanceOf, e , str L.js_array_ctor) }

jscomp/core/js_exp_make.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,9 @@ let method_
212212
comment
213213
}
214214

215-
215+
(** This is coupuled with {!Caml_obj.caml_update_dummy} *)
216216
let dummy_obj ?comment () : t =
217-
{comment ; expression_desc = Object []}
217+
{comment ; expression_desc = J.Array ([],Mutable)}
218218

219219
let is_instance_array ?comment e : t =
220220
{comment; expression_desc = Bin(InstanceOf, e , str L.js_array_ctor) }

jscomp/runtime/caml_obj.ml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,32 @@ let caml_obj_truncate (x : Obj.t) (new_size : int) =
9898

9999
let caml_lazy_make_forward x = lazy x
100100

101-
(** TODO: the dummy one should be [{}] *)
101+
(**
102+
For the empty dummy object, whether it's
103+
`[]` or `{}` depends on how
104+
runtime encoding works, and will affect
105+
js polymorphic comparison(Js.(=)) (fine with caml polymoprhic comparison (Pervasives.equal))
106+
In most cases, rec value comes from record/modules,
107+
whose tag is 0, we optimize that case
108+
*)
102109
let caml_update_dummy x y =
110+
(* let len = Bs_obj.length y in
111+
for i = 0 to len - 1 do
112+
Array.unsafe_set x i (Obj.field y i)
113+
done;
114+
Obj.set_tag (Obj.magic x) (Obj.tag y)
115+
*)
103116
let len = Bs_obj.length y in
104117
for i = 0 to len - 1 do
105118
Obj.set_field x i (Obj.field y i)
106-
done ;
107-
Obj.set_tag x (Obj.tag y);
108-
Bs_obj.set_length x (Bs_obj.length y)
109-
119+
done ;
120+
let y_tag = Obj.tag y in
121+
if y_tag <> 0 then
122+
Obj.set_tag x y_tag
123+
124+
(* Bs_obj.set_length x (Bs_obj.length y) *)
125+
(* [set_length] seems redundant here given that it is initialized as an array
126+
*)
110127
let caml_int_compare (x : int) (y: int) : int =
111128
if x < y then -1 else if x = y then 0 else 1
112129

jscomp/test/class3_test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ eq('File "class3_test.ml", line 81, characters 12-19', v, /* int array */[
305305
3
306306
]);
307307

308-
var abstract_point = { };
308+
var abstract_point = [];
309309

310310
Caml_obj.caml_update_dummy(abstract_point, [
311311
0,
@@ -363,7 +363,7 @@ var v$1 = Curry.js1(-792262820, 9, h);
363363

364364
eq('File "class3_test.ml", line 107, characters 12-19', v$1, 32);
365365

366-
var abstract_point2 = { };
366+
var abstract_point2 = [];
367367

368368
Caml_obj.caml_update_dummy(abstract_point2, [
369369
0,

jscomp/test/class4_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ var restricted_point$prime$1 = restricted_point;
9797

9898
var Point = /* module */[/* restricted_point' */restricted_point$prime$1];
9999

100-
var abstract_point = { };
100+
var abstract_point = [];
101101

102102
Caml_obj.caml_update_dummy(abstract_point, [
103103
0,

jscomp/test/class6_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ var d = [
174174
0
175175
];
176176

177-
var c2$prime = { };
177+
var c2$prime = [];
178178

179179
Caml_obj.caml_update_dummy(c2$prime, [
180180
0,

jscomp/test/class8_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ function eq(loc, x, y) {
3535
return /* () */0;
3636
}
3737

38-
var comparable = { };
38+
var comparable = [];
3939

4040
Caml_obj.caml_update_dummy(comparable, [
4141
0,

jscomp/test/hamming_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,13 +214,13 @@ function iter_interval(f, _l, _param) {
214214
};
215215
}
216216

217-
var hamming = { };
217+
var hamming = [];
218218

219-
var ham2 = { };
219+
var ham2 = [];
220220

221-
var ham3 = { };
221+
var ham3 = [];
222222

223-
var ham5 = { };
223+
var ham5 = [];
224224

225225
Caml_obj.caml_update_dummy(hamming, Block.__(246, [function () {
226226
return /* Cons */[

0 commit comments

Comments
 (0)