Skip to content

Commit 169a47c

Browse files
committed
optimize single recursive value
1 parent 1a8c7ef commit 169a47c

13 files changed

+156
-148
lines changed

jscomp/bin/whole_compiler.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62950,8 +62950,11 @@ let preprocess_deps (groups : bindings) : _ * Ident.t array * Int_vec.t array
6295062950
let scc (groups : bindings) ( lam : t) ( body : t)
6295162951
=
6295262952
begin match groups with
62953-
| [ _ ] ->
62954-
lam
62953+
| [ (id,bind) ] ->
62954+
if hit_any_variables (Ident_set.singleton id) bind
62955+
then
62956+
lam
62957+
else let_ Strict id bind body
6295562958
| _ ->
6295662959
let (domain, int_mapping, node_vec) = preprocess_deps groups in
6295762960
let clusters = Ext_scc.graph node_vec in
@@ -62965,11 +62968,11 @@ let scc (groups : bindings) ( lam : t) ( body : t)
6296562968
(id,lam)
6296662969
) v in
6296762970
match bindings with
62968-
| [ id,(Lfunction _ as lam) ] ->
62971+
| [ id,lam ] ->
6296962972
let base_key = Ordered_hash_map_local_ident.rank domain id in
6297062973
if Int_vec_util.mem base_key node_vec.(base_key) then
6297162974
letrec bindings acc
62972-
else let_ StrictOpt id lam acc
62975+
else let_ Strict id lam acc
6297362976
| _ ->
6297462977
letrec bindings acc
6297562978
) clusters body

jscomp/core/lam.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,8 +1263,11 @@ let preprocess_deps (groups : bindings) : _ * Ident.t array * Int_vec.t array
12631263
let scc (groups : bindings) ( lam : t) ( body : t)
12641264
=
12651265
begin match groups with
1266-
| [ _ ] ->
1267-
lam
1266+
| [ (id,bind) ] ->
1267+
if hit_any_variables (Ident_set.singleton id) bind
1268+
then
1269+
lam
1270+
else let_ Strict id bind body
12681271
| _ ->
12691272
let (domain, int_mapping, node_vec) = preprocess_deps groups in
12701273
let clusters = Ext_scc.graph node_vec in
@@ -1278,11 +1281,11 @@ let scc (groups : bindings) ( lam : t) ( body : t)
12781281
(id,lam)
12791282
) v in
12801283
match bindings with
1281-
| [ id,(Lfunction _ as lam) ] ->
1284+
| [ id,lam ] ->
12821285
let base_key = Ordered_hash_map_local_ident.rank domain id in
12831286
if Int_vec_util.mem base_key node_vec.(base_key) then
12841287
letrec bindings acc
1285-
else let_ StrictOpt id lam acc
1288+
else let_ Strict id lam acc
12861289
| _ ->
12871290
letrec bindings acc
12881291
) clusters body

jscomp/test/.depend

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ map_test.cmj : ../stdlib/string.cmj ../stdlib/pervasives.cmj mt.cmj \
253253
math_test.cmj : mt.cmj ../runtime/js.cmj
254254
method_chain.cmj :
255255
method_name_test.cmj : mt.cmj
256+
minimal_test.cmj :
256257
mock_mt.cmj : mt.cmj ../stdlib/list.cmj ../runtime/js.cmj
257258
module_alias.cmj : ../stdlib/pervasives.cmj ../stdlib/list.cmj
258259
module_as_class_ffi.cmj :

jscomp/test/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ OTHERS := literals a test_ari test_export2 test_internalOO test_obj_simple_ffi t
7575
global_module_alias_test class_fib_open_recursion_test\
7676
topsort_test flexible_array_test\
7777
gray_code_test alias_test\
78-
flattern_order_test
78+
flattern_order_test\
79+
minimal_test
7980

8081

8182

jscomp/test/class3_test.js

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
var Caml_obj = require("../../lib/js/caml_obj");
43
var Pervasives = require("../../lib/js/pervasives");
54
var Mt = require("./mt");
65
var Caml_int32 = require("../../lib/js/caml_int32");
@@ -305,27 +304,27 @@ eq('File "class3_test.ml", line 81, characters 12-19', v, /* int array */[
305304
3
306305
]);
307306

308-
var abstract_point = [];
309-
310-
Caml_obj.caml_update_dummy(abstract_point, [
311-
0,
312-
function ($$class) {
313-
var x_init = CamlinternalOO.new_variable($$class, "");
314-
var ids = CamlinternalOO.get_method_labels($$class, shared$7);
315-
var get_x = ids[1];
316-
var get_offset = ids[2];
317-
CamlinternalOO.set_method($$class, get_offset, function (self$neg7) {
318-
return Curry._1(self$neg7[0][get_x], self$neg7) - self$neg7[x_init] | 0;
319-
});
320-
return function (_, self, x_init$1) {
321-
var self$1 = CamlinternalOO.create_object_opt(self, $$class);
322-
self$1[x_init] = x_init$1;
323-
return self$1;
324-
};
325-
},
326-
0,
327-
0
328-
]);
307+
function abstract_point_001($$class) {
308+
var x_init = CamlinternalOO.new_variable($$class, "");
309+
var ids = CamlinternalOO.get_method_labels($$class, shared$7);
310+
var get_x = ids[1];
311+
var get_offset = ids[2];
312+
CamlinternalOO.set_method($$class, get_offset, function (self$neg7) {
313+
return Curry._1(self$neg7[0][get_x], self$neg7) - self$neg7[x_init] | 0;
314+
});
315+
return function (_, self, x_init$1) {
316+
var self$1 = CamlinternalOO.create_object_opt(self, $$class);
317+
self$1[x_init] = x_init$1;
318+
return self$1;
319+
};
320+
}
321+
322+
var abstract_point = [
323+
0,
324+
abstract_point_001,
325+
0,
326+
0
327+
];
329328

330329
function vpoint_init($$class) {
331330
var ids = CamlinternalOO.new_methods_variables($$class, shared$1, shared$5);
@@ -363,25 +362,25 @@ var v$1 = Curry.js1(-792262820, 9, h);
363362

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

366-
var abstract_point2 = [];
367-
368-
Caml_obj.caml_update_dummy(abstract_point2, [
369-
0,
370-
function ($$class) {
371-
var ids = CamlinternalOO.new_methods_variables($$class, shared$2, shared$5);
372-
var move = ids[0];
373-
var x = ids[1];
374-
CamlinternalOO.set_method($$class, move, function (self$neg9, d) {
375-
self$neg9[x] = self$neg9[x] + d | 0;
376-
return /* () */0;
377-
});
378-
return function (_, self) {
379-
return CamlinternalOO.create_object_opt(self, $$class);
380-
};
381-
},
382-
0,
383-
0
384-
]);
365+
function abstract_point2_001($$class) {
366+
var ids = CamlinternalOO.new_methods_variables($$class, shared$2, shared$5);
367+
var move = ids[0];
368+
var x = ids[1];
369+
CamlinternalOO.set_method($$class, move, function (self$neg9, d) {
370+
self$neg9[x] = self$neg9[x] + d | 0;
371+
return /* () */0;
372+
});
373+
return function (_, self) {
374+
return CamlinternalOO.create_object_opt(self, $$class);
375+
};
376+
}
377+
378+
var abstract_point2 = [
379+
0,
380+
abstract_point2_001,
381+
0,
382+
0
383+
];
385384

386385
function point2_init($$class) {
387386
var x_init = CamlinternalOO.new_variable($$class, "");

jscomp/test/class4_test.js

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
'use strict';
22

3-
var Caml_obj = require("../../lib/js/caml_obj");
43
var Mt = require("./mt");
54
var Block = require("../../lib/js/block");
65
var Curry = require("../../lib/js/curry");
@@ -93,35 +92,33 @@ function restricted_point2$prime_init($$class) {
9392

9493
var restricted_point2$prime = CamlinternalOO.make_class(shared$2, restricted_point2$prime_init);
9594

96-
var restricted_point$prime$1 = restricted_point;
97-
98-
var Point = /* module */[/* restricted_point' */restricted_point$prime$1];
99-
100-
var abstract_point = [];
101-
102-
Caml_obj.caml_update_dummy(abstract_point, [
103-
0,
104-
function ($$class) {
105-
var x_init = CamlinternalOO.new_variable($$class, "");
106-
var ids = CamlinternalOO.get_method_labels($$class, [
107-
"move",
108-
"get_x",
109-
"get_offset"
110-
]);
111-
var get_x = ids[1];
112-
var get_offset = ids[2];
113-
CamlinternalOO.set_method($$class, get_offset, function (self$neg5) {
114-
return Curry._1(self$neg5[0][get_x], self$neg5) - self$neg5[x_init] | 0;
115-
});
116-
return function (_, self, x_init$1) {
117-
var self$1 = CamlinternalOO.create_object_opt(self, $$class);
118-
self$1[x_init] = x_init$1;
119-
return self$1;
120-
};
121-
},
122-
0,
123-
0
124-
]);
95+
var Point = /* module */[/* restricted_point' */restricted_point];
96+
97+
function abstract_point_001($$class) {
98+
var x_init = CamlinternalOO.new_variable($$class, "");
99+
var ids = CamlinternalOO.get_method_labels($$class, [
100+
"move",
101+
"get_x",
102+
"get_offset"
103+
]);
104+
var get_x = ids[1];
105+
var get_offset = ids[2];
106+
CamlinternalOO.set_method($$class, get_offset, function (self$neg5) {
107+
return Curry._1(self$neg5[0][get_x], self$neg5) - self$neg5[x_init] | 0;
108+
});
109+
return function (_, self, x_init$1) {
110+
var self$1 = CamlinternalOO.create_object_opt(self, $$class);
111+
self$1[x_init] = x_init$1;
112+
return self$1;
113+
};
114+
}
115+
116+
var abstract_point = [
117+
0,
118+
abstract_point_001,
119+
0,
120+
0
121+
];
125122

126123
function point_init($$class) {
127124
var ids = CamlinternalOO.new_methods_variables($$class, shared, shared$1);

jscomp/test/class6_test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,19 @@ var d = [
174174
0
175175
];
176176

177-
var c2$prime = [];
178-
179-
Caml_obj.caml_update_dummy(c2$prime, [
180-
0,
181-
function ($$class) {
182-
CamlinternalOO.get_method_label($$class, "m");
183-
return function (_, self) {
184-
return CamlinternalOO.create_object_opt(self, $$class);
185-
};
186-
},
187-
0,
188-
0
189-
]);
177+
function c2$prime_001($$class) {
178+
CamlinternalOO.get_method_label($$class, "m");
179+
return function (_, self) {
180+
return CamlinternalOO.create_object_opt(self, $$class);
181+
};
182+
}
183+
184+
var c2$prime = [
185+
0,
186+
c2$prime_001,
187+
0,
188+
0
189+
];
190190

191191
function functional_point_init($$class) {
192192
var ids = CamlinternalOO.new_methods_variables($$class, shared, shared$1);

jscomp/test/class8_test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,19 @@ function eq(loc, x, y) {
3535
return /* () */0;
3636
}
3737

38-
var comparable = [];
39-
40-
Caml_obj.caml_update_dummy(comparable, [
41-
0,
42-
function ($$class) {
43-
CamlinternalOO.get_method_label($$class, "leq");
44-
return function (_, self) {
45-
return CamlinternalOO.create_object_opt(self, $$class);
46-
};
47-
},
48-
0,
49-
0
50-
]);
38+
function comparable_001($$class) {
39+
CamlinternalOO.get_method_label($$class, "leq");
40+
return function (_, self) {
41+
return CamlinternalOO.create_object_opt(self, $$class);
42+
};
43+
}
44+
45+
var comparable = [
46+
0,
47+
comparable_001,
48+
0,
49+
0
50+
];
5151

5252
function money_init($$class) {
5353
var ids = CamlinternalOO.new_methods_variables($$class, [

jscomp/test/flattern_order_test.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,19 @@ function even2(n) {
6161

6262
var v = [0];
6363

64-
var obj = [];
64+
function obj_000() {
65+
return v[0];
66+
}
6567

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-
]);
68+
function obj_001(i) {
69+
v[0] = i;
70+
return /* () */0;
71+
}
72+
73+
var obj = /* record */[
74+
obj_000,
75+
obj_001
76+
];
7577

7678
exports.xs = xs;
7779
exports.even = even;

0 commit comments

Comments
 (0)