Skip to content

Commit 5fd59ab

Browse files
committed
clean up
1 parent ced9ad2 commit 5fd59ab

File tree

7 files changed

+180
-52
lines changed

7 files changed

+180
-52
lines changed

jscomp/.merlin

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ S depends
2424
B depends
2525
PKG compiler-libs.common
2626
B +compiler-libs
27-
FLG -w -40-30
27+
FLG -w -40-30+6

jscomp/bin/whole_compiler.ml

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -94498,18 +94498,18 @@ end = struct
9449894498
TODO:
9449994499
we should have a pass called, always inlinable
9450094500
as long as its length is smaller than [exit=exit_id], for example
94501-
94501+
9450294502
{[
94503-
switch(box_name)
94503+
switch(box_name)
9450494504
{case "":exit=178;break;
9450594505
case "b":exit=178;break;
9450694506
case "h":box_type=/* Pp_hbox */0;break;
9450794507
case "hov":box_type=/* Pp_hovbox */3;break;
9450894508
case "hv":box_type=/* Pp_hvbox */2;break;
9450994509
case "v":box_type=/* Pp_vbox */1;break;
9451094510
default:box_type=invalid_box(/* () */0);}
94511-
94512-
switch(exit){case 178:box_type=/* Pp_box */4;break}
94511+
94512+
switch(exit){case 178:box_type=/* Pp_box */4;break}
9451394513
]}
9451494514
*)
9451594515

@@ -94591,14 +94591,15 @@ let count_helper (lam : Lam.t) : int ref Int_hashtbl.t =
9459194591
if
9459294592
nconsts < sw.sw_numconsts && nblocks < sw.sw_numblocks
9459394593
then
94594-
begin (* default action will occur twice in native code *)
94595-
count al ; count al
94596-
(**
94594+
(*
9459794595
Reason: for pattern match,
9459894596
we will test whether it is
9459994597
an integer or block, both have default cases
9460094598
predicate: [sw_numconsts] vs nconsts
9460194599
*)
94600+
94601+
begin
94602+
count al ; count al
9460294603
end
9460394604
else
9460494605
begin (* default action will occur once *)
@@ -94632,7 +94633,7 @@ type subst_tbl = (Ident.t list * Lam.t) Int_hashtbl.t
9463294633
*)
9463394634

9463494635

94635-
let subst_helper (subst : subst_tbl) query lam =
94636+
let subst_helper (subst : subst_tbl) (query : int -> int) lam =
9463694637
let rec simplif (lam : Lam.t) =
9463794638
match lam with
9463894639
| Lstaticraise (i,[]) ->
@@ -94653,7 +94654,7 @@ let subst_helper (subst : subst_tbl) query lam =
9465394654
List.fold_right2
9465494655
(fun y l r -> Lam.let_ Alias y l r)
9465594656
ys ls
94656-
(Lam_util.subst_lambda env handler)
94657+
(Lam_util.subst_lambda env handler)
9465794658
| None -> Lam.staticraise i ls
9465894659
end
9465994660
| Lstaticcatch (l1,(i,[]),(Lstaticraise (j,[]) as l2)) ->
@@ -94707,12 +94708,12 @@ let subst_helper (subst : subst_tbl) query lam =
9470794708
*)
9470894709
let lam_size = Lam_analysis.size l2 in
9470994710
let ok_to_inline =
94710-
i >=0 &&
94711-
( (j <= 2 && lam_size < Lam_analysis.exit_inline_size )
94712-
|| lam_size < 5)
94713-
(*TODO: when we do the case merging on the js side,
94714-
the j is not very indicative
94715-
*)
94711+
i >=0 &&
94712+
( (j <= 2 && lam_size < Lam_analysis.exit_inline_size )
94713+
|| lam_size < 5)
94714+
(*TODO: when we do the case merging on the js side,
94715+
the j is not very indicative
94716+
*)
9471694717
in
9471794718
if ok_to_inline (* && false *)
9471894719
then
@@ -94742,20 +94743,20 @@ let subst_helper (subst : subst_tbl) query lam =
9474294743
and new_consts = List.map (fun (n, e) -> (n, simplif e)) sw.sw_consts
9474394744
and new_blocks = List.map (fun (n, e) -> (n, simplif e)) sw.sw_blocks
9474494745
and new_fail =
94745-
begin match sw.sw_failaction with
94746-
| None -> None
94747-
| Some x -> Some (simplif x) end in
94746+
begin match sw.sw_failaction with
94747+
| None -> None
94748+
| Some x -> Some (simplif x) end in
9474894749
Lam.switch
9474994750
new_l
94750-
{
94751-
sw with
94752-
sw_consts = new_consts ;
94753-
sw_blocks = new_blocks;
94754-
sw_failaction = new_fail}
94751+
{
94752+
sw with
94753+
sw_consts = new_consts ;
94754+
sw_blocks = new_blocks;
94755+
sw_failaction = new_fail}
9475594756
| Lstringswitch(l,sw,d) ->
9475694757
Lam.stringswitch
9475794758
(simplif l) (List.map (fun (s,l) -> s,simplif l) sw)
94758-
(begin match d with None -> None | Some d -> Some (simplif d) end)
94759+
(begin match d with None -> None | Some d -> Some (simplif d) end)
9475994760
| Ltrywith (l1, v, l2) ->
9476094761
Lam.try_ (simplif l1) v (simplif l2)
9476194762
| Lifthenelse (l1, l2, l3) ->
@@ -94772,7 +94773,7 @@ let subst_helper (subst : subst_tbl) query lam =
9477294773
Lam.ifused v (simplif l)
9477394774
in
9477494775
simplif lam
94775-
94776+
9477694777
let simplify_exits (lam : Lam.t) =
9477794778
let exits = count_helper lam in
9477894779
subst_helper (Int_hashtbl.create 17 ) (count_exit exits) lam

jscomp/core/lam_pass_exits.ml

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
TODO:
1616
we should have a pass called, always inlinable
1717
as long as its length is smaller than [exit=exit_id], for example
18-
18+
1919
{[
20-
switch(box_name)
20+
switch(box_name)
2121
{case "":exit=178;break;
2222
case "b":exit=178;break;
2323
case "h":box_type=/* Pp_hbox */0;break;
2424
case "hov":box_type=/* Pp_hovbox */3;break;
2525
case "hv":box_type=/* Pp_hvbox */2;break;
2626
case "v":box_type=/* Pp_vbox */1;break;
2727
default:box_type=invalid_box(/* () */0);}
28-
29-
switch(exit){case 178:box_type=/* Pp_box */4;break}
28+
29+
switch(exit){case 178:box_type=/* Pp_box */4;break}
3030
]}
3131
*)
3232

@@ -108,14 +108,15 @@ let count_helper (lam : Lam.t) : int ref Int_hashtbl.t =
108108
if
109109
nconsts < sw.sw_numconsts && nblocks < sw.sw_numblocks
110110
then
111-
begin (* default action will occur twice in native code *)
112-
count al ; count al
113-
(**
111+
(*
114112
Reason: for pattern match,
115113
we will test whether it is
116114
an integer or block, both have default cases
117115
predicate: [sw_numconsts] vs nconsts
118116
*)
117+
118+
begin
119+
count al ; count al
119120
end
120121
else
121122
begin (* default action will occur once *)
@@ -149,7 +150,7 @@ type subst_tbl = (Ident.t list * Lam.t) Int_hashtbl.t
149150
*)
150151

151152

152-
let subst_helper (subst : subst_tbl) query lam =
153+
let subst_helper (subst : subst_tbl) (query : int -> int) lam =
153154
let rec simplif (lam : Lam.t) =
154155
match lam with
155156
| Lstaticraise (i,[]) ->
@@ -170,7 +171,7 @@ let subst_helper (subst : subst_tbl) query lam =
170171
List.fold_right2
171172
(fun y l r -> Lam.let_ Alias y l r)
172173
ys ls
173-
(Lam_util.subst_lambda env handler)
174+
(Lam_util.subst_lambda env handler)
174175
| None -> Lam.staticraise i ls
175176
end
176177
| Lstaticcatch (l1,(i,[]),(Lstaticraise (j,[]) as l2)) ->
@@ -224,12 +225,12 @@ let subst_helper (subst : subst_tbl) query lam =
224225
*)
225226
let lam_size = Lam_analysis.size l2 in
226227
let ok_to_inline =
227-
i >=0 &&
228-
( (j <= 2 && lam_size < Lam_analysis.exit_inline_size )
229-
|| lam_size < 5)
230-
(*TODO: when we do the case merging on the js side,
231-
the j is not very indicative
232-
*)
228+
i >=0 &&
229+
( (j <= 2 && lam_size < Lam_analysis.exit_inline_size )
230+
|| lam_size < 5)
231+
(*TODO: when we do the case merging on the js side,
232+
the j is not very indicative
233+
*)
233234
in
234235
if ok_to_inline (* && false *)
235236
then
@@ -259,20 +260,20 @@ let subst_helper (subst : subst_tbl) query lam =
259260
and new_consts = List.map (fun (n, e) -> (n, simplif e)) sw.sw_consts
260261
and new_blocks = List.map (fun (n, e) -> (n, simplif e)) sw.sw_blocks
261262
and new_fail =
262-
begin match sw.sw_failaction with
263-
| None -> None
264-
| Some x -> Some (simplif x) end in
263+
begin match sw.sw_failaction with
264+
| None -> None
265+
| Some x -> Some (simplif x) end in
265266
Lam.switch
266267
new_l
267-
{
268-
sw with
269-
sw_consts = new_consts ;
270-
sw_blocks = new_blocks;
271-
sw_failaction = new_fail}
268+
{
269+
sw with
270+
sw_consts = new_consts ;
271+
sw_blocks = new_blocks;
272+
sw_failaction = new_fail}
272273
| Lstringswitch(l,sw,d) ->
273274
Lam.stringswitch
274275
(simplif l) (List.map (fun (s,l) -> s,simplif l) sw)
275-
(begin match d with None -> None | Some d -> Some (simplif d) end)
276+
(begin match d with None -> None | Some d -> Some (simplif d) end)
276277
| Ltrywith (l1, v, l2) ->
277278
Lam.try_ (simplif l1) v (simplif l2)
278279
| Lifthenelse (l1, l2, l3) ->
@@ -289,7 +290,7 @@ let subst_helper (subst : subst_tbl) query lam =
289290
Lam.ifused v (simplif l)
290291
in
291292
simplif lam
292-
293+
293294
let simplify_exits (lam : Lam.t) =
294295
let exits = count_helper lam in
295296
subst_helper (Int_hashtbl.create 17 ) (count_exit exits) lam

jscomp/test/.depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ ffi_js_test.cmj : ../stdlib/obj.cmj mt.cmj ../others/js_obj.cmj \
152152
ffi_splice_test.cmj : mt.cmj
153153
ffi_test.cmj : ../runtime/js.cmj
154154
fib.cmj :
155+
flattern_order_test.cmj : ../stdlib/list.cmj
155156
flexible_array_test.cmj : ../stdlib/format.cmj ../stdlib/array.cmj
156157
float_array.cmj :
157158
float_of_bits_test.cmj : ../stdlib/printf.cmj mt.cmj ../stdlib/list.cmj \

jscomp/test/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ OTHERS := literals a test_ari test_export2 test_internalOO test_obj_simple_ffi t
7474
math_test bal_set_mini gpr_974_test test_cpp\
7575
global_module_alias_test class_fib_open_recursion_test\
7676
topsort_test flexible_array_test\
77-
gray_code_test alias_test
77+
gray_code_test alias_test\
78+
flattern_order_test
7879

7980

8081

jscomp/test/flattern_order_test.js

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
'use strict';
2+
3+
var Caml_obj = require("../../lib/js/caml_obj");
4+
var List = require("../../lib/js/list");
5+
6+
function _zs() {
7+
return /* tuple */[
8+
List.hd(ys),
9+
List.hd(xs[0])
10+
];
11+
}
12+
13+
var ys = [];
14+
15+
var xs = [];
16+
17+
Caml_obj.caml_update_dummy(ys, /* :: */[
18+
1,
19+
ys
20+
]);
21+
22+
Caml_obj.caml_update_dummy(xs, /* tuple */[
23+
/* :: */[
24+
2,
25+
/* :: */[
26+
List.hd(ys),
27+
/* [] */0
28+
]
29+
],
30+
_zs
31+
]);
32+
33+
function even(_n) {
34+
while(true) {
35+
var n = _n;
36+
if (n) {
37+
_n = n - 1 | 0;
38+
continue ;
39+
40+
}
41+
else {
42+
return /* true */1;
43+
}
44+
};
45+
}
46+
47+
function even2(n) {
48+
if (n) {
49+
var n$1 = n - 1 | 0;
50+
if (n$1 === 1) {
51+
return /* true */1;
52+
}
53+
else {
54+
return even2(n$1 - 1 | 0);
55+
}
56+
}
57+
else {
58+
return /* true */1;
59+
}
60+
}
61+
62+
var v = [0];
63+
64+
var obj = [];
65+
66+
Caml_obj.caml_update_dummy(obj, /* record */[
67+
/* get */function () {
68+
return v[0];
69+
},
70+
/* set */function (i) {
71+
v[0] = i;
72+
return /* () */0;
73+
}
74+
]);
75+
76+
exports.xs = xs;
77+
exports.even = even;
78+
exports.even2 = even2;
79+
exports.v = v;
80+
exports.obj = obj;
81+
/* xs Not a pure module */

jscomp/test/flattern_order_test.ml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
3+
let rec xs =
4+
let rec ys = 1 :: ys
5+
and _zs () = (List.hd ys, List.hd (fst xs)) in
6+
(* and us = 3 in *)
7+
(* Js.log us; *)
8+
(2 :: List.hd ys :: [], _zs)
9+
10+
(*
11+
let second xs =
12+
let rec ys = 1 :: ys
13+
and _zs () = List.hd xs
14+
(* and us = 3 in *) in
15+
16+
xs
17+
18+
let f x =
19+
let f0 a = a+1 in
20+
let f1 a = f0 a + 1 in
21+
let f2 a = f1 a + 1 in
22+
f2 x
23+
*)
24+
25+
let rec even =
26+
let odd = even in
27+
fun n -> if n == 0 then true else odd (n - 1)
28+
29+
30+
let rec even2 =
31+
let odd n = if n == 1 then true else even2 (n - 1) in
32+
fun n -> if n == 0 then true else odd (n - 1)
33+
34+
type t =
35+
{ get : unit -> int ;
36+
set : int -> unit ;
37+
}
38+
39+
let v = ref 0
40+
let rec obj =
41+
{ get = (fun _ -> !v);
42+
set = (fun i -> v := i )
43+
}

0 commit comments

Comments
 (0)