Skip to content

Commit 7b9a647

Browse files
authored
Merge pull request #3791 from BuckleScript/lambda_equal
Beging more conservative about lambda equivalence
2 parents 8da6979 + faf44eb commit 7b9a647

File tree

5 files changed

+92
-15
lines changed

5 files changed

+92
-15
lines changed

jscomp/core/lam_primitive.ml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ type t =
179179

180180

181181

182+
let eq_field_dbg_info (x : Lam_compat.field_dbg_info) (y : Lam_compat.field_dbg_info) =
183+
x = y (* save it to avoid conditional compilation, fix it later *)
184+
185+
let eq_set_field_dbg_info (x : Lam_compat.set_field_dbg_info) (y : Lam_compat.set_field_dbg_info) =
186+
x = y (* save it to avoid conditional compilation, fix it later *)
187+
188+
let eq_tag_info ( x : Lam_tag_info.t) y =
189+
x = y
182190

183191
let eq_record_representation ( p : record_representation) ( p1 : record_representation) =
184192
match p with
@@ -267,12 +275,19 @@ let eq_primitive_approx ( lhs : t) (rhs : t) =
267275
| Pccall {prim_name = n1; prim_native_name = nn1; _}
268276
-> n0 = n1 && nn0 = nn1
269277
| _ -> false )
270-
| Pfield (n0, _dbg_info0) -> (match rhs with Pfield (n1, _dbg_info1) -> n0 = n1 | _ -> false )
271-
| Psetfield(i0, _dbg_info0) -> (match rhs with Psetfield(i1, _dbg_info1) -> i0 = i1 | _ -> false)
278+
| Pfield (n0, info0) ->
279+
(match rhs with Pfield (n1, info1) -> n0 = n1 && eq_field_dbg_info info0 info1 | _ -> false )
280+
| Pfloatfield (i0, info0) ->
281+
(match rhs with Pfloatfield (i1,info1) -> i0 = i1 && eq_field_dbg_info info0 info1 | _ -> false)
282+
| Psetfield(i0, info0) ->
283+
(match rhs with Psetfield(i1, info1) -> i0 = i1 && eq_set_field_dbg_info info0 info1 | _ -> false)
284+
| Psetfloatfield (i0, info0) ->
285+
(match rhs with Psetfloatfield(i1,info1) -> i0 = i1 && eq_set_field_dbg_info info0 info1 | _ -> false)
286+
| Pmakeblock (i0, info0, flag0) ->
287+
(match rhs with Pmakeblock(i1,info1,flag1) ->
288+
i0 = i1 && flag0 = flag1 && eq_tag_info info0 info1 | _ -> false)
289+
272290
| Pglobal_exception ident -> (match rhs with Pglobal_exception ident2 -> Ident.same ident ident2 | _ -> false )
273-
| Pmakeblock (i, _tag_info, mutable_flag) -> (match rhs with Pmakeblock(i1,_,mutable_flag1) -> i = i1 && mutable_flag = mutable_flag1 | _ -> false)
274-
| Pfloatfield (i0,_dbg_info) -> (match rhs with Pfloatfield (i1,_) -> i0 = i1 | _ -> false)
275-
| Psetfloatfield (i0,_dbg_info) -> (match rhs with Psetfloatfield(i1,_) -> i0 = i1 | _ -> false)
276291
| Pduprecord (record_repesentation0,i1) -> (match rhs with Pduprecord(record_repesentation1,i2) -> eq_record_representation record_repesentation0 record_repesentation1 && i1 = i2 | _ -> false)
277292
| Pjs_call (prim_name, arg_types, ffi) -> ( match rhs with Pjs_call(prim_name1, arg_types1,ffi1) -> prim_name = prim_name1 && arg_types = arg_types1 && ffi = ffi1 | _ -> false)
278293
| Pjs_object_create obj_create -> (match rhs with Pjs_object_create obj_create1 -> obj_create = obj_create1 | _ -> false )

jscomp/test/ocaml_proto_test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2898,7 +2898,17 @@ function gen_sig(and_, t, sc) {
28982898
var tmp;
28992899
switch (match.tag | 0) {
29002900
case 0 :
2901+
tmp = /* tuple */[
2902+
f(match[0][/* r_name */0]),
2903+
true
2904+
];
2905+
break;
29012906
case 1 :
2907+
tmp = /* tuple */[
2908+
f(match[0][/* v_name */0]),
2909+
true
2910+
];
2911+
break;
29022912
case 2 :
29032913
tmp = /* tuple */[
29042914
f(match[0][/* cv_name */0]),
@@ -3407,7 +3417,11 @@ function gen_sig$1(and_, t, sc) {
34073417
var match = t[/* spec */1];
34083418
switch (match.tag | 0) {
34093419
case 0 :
3420+
f(match[0][/* r_name */0]);
3421+
break;
34103422
case 1 :
3423+
f(match[0][/* v_name */0]);
3424+
break;
34113425
case 2 :
34123426
f(match[0][/* cv_name */0]);
34133427
break;
@@ -5535,7 +5549,17 @@ function gen_sig$3(and_, t, sc) {
55355549
var tmp;
55365550
switch (match.tag | 0) {
55375551
case 0 :
5552+
tmp = /* tuple */[
5553+
f(match[0][/* r_name */0]),
5554+
true
5555+
];
5556+
break;
55385557
case 1 :
5558+
tmp = /* tuple */[
5559+
f(match[0][/* v_name */0]),
5560+
true
5561+
];
5562+
break;
55395563
case 2 :
55405564
tmp = /* tuple */[
55415565
f(match[0][/* cv_name */0]),
@@ -6178,6 +6202,11 @@ function gen_sig$4(and_, t, sc) {
61786202
];
61796203
break;
61806204
case 1 :
6205+
tmp = /* tuple */[
6206+
f(match[0][/* v_name */0]),
6207+
true
6208+
];
6209+
break;
61816210
case 2 :
61826211
tmp = /* tuple */[
61836212
f(match[0][/* cv_name */0]),

jscomp/test/ocaml_typedtree_test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47376,8 +47376,11 @@ register_error_of_exn((function (param) {
4737647376
function get_location(ti) {
4737747377
switch (ti.tag | 0) {
4737847378
case 0 :
47379+
return ti[0][/* pat_loc */1];
4737947380
case 1 :
47381+
return ti[0][/* exp_loc */1];
4738047382
case 2 :
47383+
return ti[0][/* cl_loc */1];
4738147384
case 3 :
4738247385
return ti[0][/* mod_loc */1];
4738347386
case 4 :

lib/4.02.3/unstable/js_compiler.ml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73927,6 +73927,14 @@ type t =
7392773927

7392873928

7392973929

73930+
let eq_field_dbg_info (x : Lam_compat.field_dbg_info) (y : Lam_compat.field_dbg_info) =
73931+
x = y (* save it to avoid conditional compilation, fix it later *)
73932+
73933+
let eq_set_field_dbg_info (x : Lam_compat.set_field_dbg_info) (y : Lam_compat.set_field_dbg_info) =
73934+
x = y (* save it to avoid conditional compilation, fix it later *)
73935+
73936+
let eq_tag_info ( x : Lam_tag_info.t) y =
73937+
x = y
7393073938

7393173939
let eq_record_representation ( p : record_representation) ( p1 : record_representation) =
7393273940
match p with
@@ -74004,12 +74012,19 @@ let eq_primitive_approx ( lhs : t) (rhs : t) =
7400474012
| Pccall {prim_name = n1; prim_native_name = nn1; _}
7400574013
-> n0 = n1 && nn0 = nn1
7400674014
| _ -> false )
74007-
| Pfield (n0, _dbg_info0) -> (match rhs with Pfield (n1, _dbg_info1) -> n0 = n1 | _ -> false )
74008-
| Psetfield(i0, _dbg_info0) -> (match rhs with Psetfield(i1, _dbg_info1) -> i0 = i1 | _ -> false)
74015+
| Pfield (n0, info0) ->
74016+
(match rhs with Pfield (n1, info1) -> n0 = n1 && eq_field_dbg_info info0 info1 | _ -> false )
74017+
| Pfloatfield (i0, info0) ->
74018+
(match rhs with Pfloatfield (i1,info1) -> i0 = i1 && eq_field_dbg_info info0 info1 | _ -> false)
74019+
| Psetfield(i0, info0) ->
74020+
(match rhs with Psetfield(i1, info1) -> i0 = i1 && eq_set_field_dbg_info info0 info1 | _ -> false)
74021+
| Psetfloatfield (i0, info0) ->
74022+
(match rhs with Psetfloatfield(i1,info1) -> i0 = i1 && eq_set_field_dbg_info info0 info1 | _ -> false)
74023+
| Pmakeblock (i0, info0, flag0) ->
74024+
(match rhs with Pmakeblock(i1,info1,flag1) ->
74025+
i0 = i1 && flag0 = flag1 && eq_tag_info info0 info1 | _ -> false)
74026+
7400974027
| Pglobal_exception ident -> (match rhs with Pglobal_exception ident2 -> Ident.same ident ident2 | _ -> false )
74010-
| Pmakeblock (i, _tag_info, mutable_flag) -> (match rhs with Pmakeblock(i1,_,mutable_flag1) -> i = i1 && mutable_flag = mutable_flag1 | _ -> false)
74011-
| Pfloatfield (i0,_dbg_info) -> (match rhs with Pfloatfield (i1,_) -> i0 = i1 | _ -> false)
74012-
| Psetfloatfield (i0,_dbg_info) -> (match rhs with Psetfloatfield(i1,_) -> i0 = i1 | _ -> false)
7401374028
| Pduprecord (record_repesentation0,i1) -> (match rhs with Pduprecord(record_repesentation1,i2) -> eq_record_representation record_repesentation0 record_repesentation1 && i1 = i2 | _ -> false)
7401474029
| Pjs_call (prim_name, arg_types, ffi) -> ( match rhs with Pjs_call(prim_name1, arg_types1,ffi1) -> prim_name = prim_name1 && arg_types = arg_types1 && ffi = ffi1 | _ -> false)
7401574030
| Pjs_object_create obj_create -> (match rhs with Pjs_object_create obj_create1 -> obj_create = obj_create1 | _ -> false )

lib/4.02.3/whole_compiler.ml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65500,6 +65500,14 @@ type t =
6550065500

6550165501

6550265502

65503+
let eq_field_dbg_info (x : Lam_compat.field_dbg_info) (y : Lam_compat.field_dbg_info) =
65504+
x = y (* save it to avoid conditional compilation, fix it later *)
65505+
65506+
let eq_set_field_dbg_info (x : Lam_compat.set_field_dbg_info) (y : Lam_compat.set_field_dbg_info) =
65507+
x = y (* save it to avoid conditional compilation, fix it later *)
65508+
65509+
let eq_tag_info ( x : Lam_tag_info.t) y =
65510+
x = y
6550365511

6550465512
let eq_record_representation ( p : record_representation) ( p1 : record_representation) =
6550565513
match p with
@@ -65577,12 +65585,19 @@ let eq_primitive_approx ( lhs : t) (rhs : t) =
6557765585
| Pccall {prim_name = n1; prim_native_name = nn1; _}
6557865586
-> n0 = n1 && nn0 = nn1
6557965587
| _ -> false )
65580-
| Pfield (n0, _dbg_info0) -> (match rhs with Pfield (n1, _dbg_info1) -> n0 = n1 | _ -> false )
65581-
| Psetfield(i0, _dbg_info0) -> (match rhs with Psetfield(i1, _dbg_info1) -> i0 = i1 | _ -> false)
65588+
| Pfield (n0, info0) ->
65589+
(match rhs with Pfield (n1, info1) -> n0 = n1 && eq_field_dbg_info info0 info1 | _ -> false )
65590+
| Pfloatfield (i0, info0) ->
65591+
(match rhs with Pfloatfield (i1,info1) -> i0 = i1 && eq_field_dbg_info info0 info1 | _ -> false)
65592+
| Psetfield(i0, info0) ->
65593+
(match rhs with Psetfield(i1, info1) -> i0 = i1 && eq_set_field_dbg_info info0 info1 | _ -> false)
65594+
| Psetfloatfield (i0, info0) ->
65595+
(match rhs with Psetfloatfield(i1,info1) -> i0 = i1 && eq_set_field_dbg_info info0 info1 | _ -> false)
65596+
| Pmakeblock (i0, info0, flag0) ->
65597+
(match rhs with Pmakeblock(i1,info1,flag1) ->
65598+
i0 = i1 && flag0 = flag1 && eq_tag_info info0 info1 | _ -> false)
65599+
6558265600
| Pglobal_exception ident -> (match rhs with Pglobal_exception ident2 -> Ident.same ident ident2 | _ -> false )
65583-
| Pmakeblock (i, _tag_info, mutable_flag) -> (match rhs with Pmakeblock(i1,_,mutable_flag1) -> i = i1 && mutable_flag = mutable_flag1 | _ -> false)
65584-
| Pfloatfield (i0,_dbg_info) -> (match rhs with Pfloatfield (i1,_) -> i0 = i1 | _ -> false)
65585-
| Psetfloatfield (i0,_dbg_info) -> (match rhs with Psetfloatfield(i1,_) -> i0 = i1 | _ -> false)
6558665601
| Pduprecord (record_repesentation0,i1) -> (match rhs with Pduprecord(record_repesentation1,i2) -> eq_record_representation record_repesentation0 record_repesentation1 && i1 = i2 | _ -> false)
6558765602
| Pjs_call (prim_name, arg_types, ffi) -> ( match rhs with Pjs_call(prim_name1, arg_types1,ffi1) -> prim_name = prim_name1 && arg_types = arg_types1 && ffi = ffi1 | _ -> false)
6558865603
| Pjs_object_create obj_create -> (match rhs with Pjs_object_create obj_create1 -> obj_create = obj_create1 | _ -> false )

0 commit comments

Comments
 (0)