Skip to content

Commit 5859409

Browse files
committed
provide fast path
1 parent cc442bc commit 5859409

14 files changed

+253
-31
lines changed

Diff for: jscomp/js_dump.ml

+25-4
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,9 @@ let rec pp_function method_
307307
| [ {statement_desc =
308308
Return {return_value =
309309
{expression_desc =
310-
Call({expression_desc = Var v ; _},
310+
Call(({expression_desc = Var v ; _} as function_),
311311
ls ,
312-
{arity = ( Full (* | NA *) (* see #234*));
312+
{arity = ( Full | NA as arity(* see #234*));
313313
(* TODO: need a case to justify it*)
314314
call_info =
315315
(Call_builtin_runtime | Call_ml )})}}}],
@@ -328,14 +328,35 @@ let rec pp_function method_
328328
P.space f ;
329329
P.string f L.eq;
330330
P.space f ;
331-
vident cxt f v
331+
if arity = NA then
332+
let len = List.length l in (* length *)
333+
begin
334+
P.string f Js_config.curry;
335+
P.string f L.dot;
336+
P.string f "__";
337+
P.string f (Printf.sprintf "%d" len);
338+
P.paren_group f 1 (fun _ -> arguments cxt f [function_])
339+
end
340+
else
341+
vident cxt f v
332342
| None ->
333343
if return then
334344
begin
335345
P.string f L.return ;
336346
P.space f;
337347
end;
338-
vident cxt f v
348+
if arity = NA then
349+
let len = List.length l in (* length *)
350+
begin
351+
P.string f Js_config.curry;
352+
P.string f L.dot;
353+
P.string f "__";
354+
P.string f (Printf.sprintf "%d" len);
355+
P.paren_group f 1 (fun _ -> arguments cxt f [function_])
356+
end
357+
358+
else
359+
vident cxt f v
339360
end
340361
| _, _ ->
341362

Diff for: jscomp/runtime/curry.ml

+40
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ let _1 o a0 =
7878
let js1 label cacheid a0 =
7979
_1 (Obj.magic Caml_oo.caml_get_public_method a0 label cacheid) a0
8080

81+
let __1 o =
82+
let arity = function_length o in
83+
if arity = 1 then o
84+
else fun a0 -> _1 o a0
85+
8186

8287
let curry_2 o a0 a1 arity =
8388
match arity with
@@ -99,6 +104,11 @@ let _2 o a0 a1 =
99104
let js2 label cacheid a0 a1 =
100105
_2 (Obj.magic Caml_oo.caml_get_public_method a0 label cacheid) a0 a1
101106

107+
let __2 o =
108+
let arity = function_length o in
109+
if arity = 2 then o
110+
else fun a0 a1 -> _2 o a0 a1
111+
102112

103113
let curry_3 o a0 a1 a2 arity =
104114
match arity with
@@ -120,6 +130,11 @@ let _3 o a0 a1 a2 =
120130
let js3 label cacheid a0 a1 a2 =
121131
_3 (Obj.magic Caml_oo.caml_get_public_method a0 label cacheid) a0 a1 a2
122132

133+
let __3 o =
134+
let arity = function_length o in
135+
if arity = 3 then o
136+
else fun a0 a1 a2 -> _3 o a0 a1 a2
137+
123138

124139
let curry_4 o a0 a1 a2 a3 arity =
125140
match arity with
@@ -141,6 +156,11 @@ let _4 o a0 a1 a2 a3 =
141156
let js4 label cacheid a0 a1 a2 a3 =
142157
_4 (Obj.magic Caml_oo.caml_get_public_method a0 label cacheid) a0 a1 a2 a3
143158

159+
let __4 o =
160+
let arity = function_length o in
161+
if arity = 4 then o
162+
else fun a0 a1 a2 a3 -> _4 o a0 a1 a2 a3
163+
144164

145165
let curry_5 o a0 a1 a2 a3 a4 arity =
146166
match arity with
@@ -162,6 +182,11 @@ let _5 o a0 a1 a2 a3 a4 =
162182
let js5 label cacheid a0 a1 a2 a3 a4 =
163183
_5 (Obj.magic Caml_oo.caml_get_public_method a0 label cacheid) a0 a1 a2 a3 a4
164184

185+
let __5 o =
186+
let arity = function_length o in
187+
if arity = 5 then o
188+
else fun a0 a1 a2 a3 a4 -> _5 o a0 a1 a2 a3 a4
189+
165190

166191
let curry_6 o a0 a1 a2 a3 a4 a5 arity =
167192
match arity with
@@ -183,6 +208,11 @@ let _6 o a0 a1 a2 a3 a4 a5 =
183208
let js6 label cacheid a0 a1 a2 a3 a4 a5 =
184209
_6 (Obj.magic Caml_oo.caml_get_public_method a0 label cacheid) a0 a1 a2 a3 a4 a5
185210

211+
let __6 o =
212+
let arity = function_length o in
213+
if arity = 6 then o
214+
else fun a0 a1 a2 a3 a4 a5 -> _6 o a0 a1 a2 a3 a4 a5
215+
186216

187217
let curry_7 o a0 a1 a2 a3 a4 a5 a6 arity =
188218
match arity with
@@ -204,6 +234,11 @@ let _7 o a0 a1 a2 a3 a4 a5 a6 =
204234
let js7 label cacheid a0 a1 a2 a3 a4 a5 a6 =
205235
_7 (Obj.magic Caml_oo.caml_get_public_method a0 label cacheid) a0 a1 a2 a3 a4 a5 a6
206236

237+
let __7 o =
238+
let arity = function_length o in
239+
if arity = 7 then o
240+
else fun a0 a1 a2 a3 a4 a5 a6 -> _7 o a0 a1 a2 a3 a4 a5 a6
241+
207242

208243
let curry_8 o a0 a1 a2 a3 a4 a5 a6 a7 arity =
209244
match arity with
@@ -225,3 +260,8 @@ let _8 o a0 a1 a2 a3 a4 a5 a6 a7 =
225260
let js8 label cacheid a0 a1 a2 a3 a4 a5 a6 a7 =
226261
_8 (Obj.magic Caml_oo.caml_get_public_method a0 label cacheid) a0 a1 a2 a3 a4 a5 a6 a7
227262

263+
let __8 o =
264+
let arity = function_length o in
265+
if arity = 8 then o
266+
else fun a0 a1 a2 a3 a4 a5 a6 a7 -> _8 o a0 a1 a2 a3 a4 a5 a6 a7
267+

Diff for: jscomp/test/.depend

+8
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,8 @@ digest_test.cmx : ../stdlib/string.cmx ../stdlib/printf.cmx mt.cmx \
163163
ext_array.cmx ../stdlib/digest.cmx ../stdlib/array.cmx
164164
div_by_zero_test.cmj : mt.cmi ../stdlib/int64.cmi ../stdlib/int32.cmi
165165
div_by_zero_test.cmx : mt.cmx ../stdlib/int64.cmx ../stdlib/int32.cmx
166+
earger_curry_test.cmj :
167+
earger_curry_test.cmx :
166168
empty_obj.cmj :
167169
empty_obj.cmx :
168170
epsilon_test.cmj : mt.cmi
@@ -439,6 +441,8 @@ offset.cmj : ../stdlib/string.cmi ../stdlib/set.cmi
439441
offset.cmx : ../stdlib/string.cmx ../stdlib/set.cmx
440442
optional_ffi_test.cmj : mt.cmi
441443
optional_ffi_test.cmx : mt.cmx
444+
poly_type.cmj : ../runtime/js.cmj
445+
poly_type.cmx : ../runtime/js.cmx
442446
poly_variant_test.cmj : ../runtime/js.cmj poly_variant_test.cmi
443447
poly_variant_test.cmx : ../runtime/js.cmx poly_variant_test.cmi
444448
polymorphism_test.cmj : polymorphism_test.cmi
@@ -927,6 +931,8 @@ digest_test.cmj : ../stdlib/string.cmj ../stdlib/printf.cmj mt.cmj \
927931
ext_array.cmj ../stdlib/digest.cmj ../stdlib/array.cmj
928932
div_by_zero_test.cmo : mt.cmi ../stdlib/int64.cmi ../stdlib/int32.cmi
929933
div_by_zero_test.cmj : mt.cmj ../stdlib/int64.cmj ../stdlib/int32.cmj
934+
earger_curry_test.cmo :
935+
earger_curry_test.cmj :
930936
empty_obj.cmo :
931937
empty_obj.cmj :
932938
epsilon_test.cmo : mt.cmi
@@ -1203,6 +1209,8 @@ offset.cmo : ../stdlib/string.cmi ../stdlib/set.cmi
12031209
offset.cmj : ../stdlib/string.cmj ../stdlib/set.cmj
12041210
optional_ffi_test.cmo : mt.cmi
12051211
optional_ffi_test.cmj : mt.cmj
1212+
poly_type.cmo : ../runtime/js.cmo
1213+
poly_type.cmj : ../runtime/js.cmj
12061214
poly_variant_test.cmo : ../runtime/js.cmo poly_variant_test.cmi
12071215
poly_variant_test.cmj : ../runtime/js.cmj poly_variant_test.cmi
12081216
polymorphism_test.cmo : polymorphism_test.cmi

Diff for: jscomp/test/Makefile

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ OTHERS := literals a test_ari test_export2 test_internalOO test_obj_simple_ffi t
6060
bs_rest_test infer_type_test fs_test module_as_function\
6161
test_case_set test_mutliple string_bound_get_test inline_string_test\
6262
ppx_this_obj_test unsafe_obj_external gpr_627_test jsoo_485_test jsoo_400_test \
63-
test_require more_uncurry
63+
test_require more_uncurry earger_curry_test poly_type
64+
6465

6566

6667
SOURCE_LIST := js_dyn $(OTHERS)

Diff for: jscomp/test/class3_test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,7 @@ function point_again3_init($$class) {
517517
var inh = CamlinternalOO.inherits($$class, shared$5, 0, shared, restricted_point, 1);
518518
var obj_init = inh[0];
519519
var move$1 = inh[4];
520-
CamlinternalOO.set_method($$class, move, function (self$neg14) {
521-
return Curry._1(move$1, self$neg14);
522-
});
520+
CamlinternalOO.set_method($$class, move, Curry.__1(move$1));
523521
return function (_, self, x) {
524522
var self$1 = CamlinternalOO.create_object_opt(self, $$class);
525523
Curry._2(obj_init, self$1, x);

Diff for: jscomp/test/earger_curry_test.js

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use strict';
2+
3+
var Curry = require("../../lib/js/curry");
4+
5+
function f(g) {
6+
return Curry.__1(g);
7+
}
8+
9+
function map(f, lst) {
10+
if (lst) {
11+
return /* :: */[
12+
f(lst[0]),
13+
map(f, lst[1])
14+
];
15+
}
16+
else {
17+
return /* [] */0;
18+
}
19+
}
20+
21+
function map$1(f, lst) {
22+
return map(Curry.__1(f), lst);
23+
}
24+
25+
exports.f = f;
26+
exports.map = map$1;
27+
/* No side effect */

Diff for: jscomp/test/earger_curry_test.ml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
3+
let f g = fun [@bs] x -> g x
4+
5+
let rec map f lst =
6+
match lst with
7+
| [] -> []
8+
| a :: rest ->
9+
f a [@bs] :: map f rest
10+
11+
12+
let map (type u) (type v) (f : u -> v) (lst : u list) : v list =
13+
map (fun [@bs] x -> f x ) lst

Diff for: jscomp/test/ffi_arity_test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ var v = /* int array */[
2222
1,
2323
2,
2424
3
25-
].map(function (param, param$1) {
26-
return Curry._2(f, param, param$1);
27-
});
25+
].map(Curry.__2(f));
2826

2927
var vv = /* int array */[
3028
1,

Diff for: jscomp/test/poly_type.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
'use strict';
2+
3+
4+
function f(x) {
5+
x.pushState(3, "x");
6+
return x.pushState(/* None */0, "x");
7+
}
8+
9+
exports.f = f;
10+
/* No side effect */

Diff for: jscomp/test/poly_type.ml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
3+
4+
class type history = object
5+
method pushState : 'a . 'a -> string -> unit
6+
end [@bs]
7+
8+
let f (x : history Js.t) =
9+
x##pushState 3 "x";
10+
x##pushState None "x"

Diff for: jscomp/test/print_alpha_test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ var Curry = require("../../lib/js/curry");
66

77
function f(h, _) {
88
console.log(3);
9-
return function (x, y) {
10-
return Curry._2(h, x, y);
11-
};
9+
return Curry.__2(h);
1210
}
1311

1412
Mt.from_pair_suites("print_alpha_test.ml", /* :: */[

Diff for: jsconfig.json

-16
This file was deleted.

0 commit comments

Comments
 (0)