Skip to content

Commit 6dae93f

Browse files
authored
Merge pull request #654 from bloomberg/eager_evaluate_lazy
Eager evaluate lazy
2 parents cc442bc + 44d84ea commit 6dae93f

18 files changed

+965
-31
lines changed

jscomp/js_dump.ml

Lines changed: 18 additions & 4 deletions
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 )})}}}],
@@ -320,6 +320,19 @@ let rec pp_function method_
320320
match b.J.expression_desc with
321321
| Var (Id i) -> Ident.same a i
322322
| _ -> false) l ls ->
323+
let optimize len p cxt f v =
324+
if p then
325+
begin
326+
P.string f Js_config.curry;
327+
P.string f L.dot;
328+
P.string f "__";
329+
P.string f (Printf.sprintf "%d" len);
330+
P.paren_group f 1 (fun _ -> arguments cxt f [function_])
331+
end
332+
else
333+
vident cxt f v
334+
in
335+
let len = List.length l in (* length *)
323336
begin match name with
324337
| Some i ->
325338
P.string f L.var;
@@ -328,14 +341,15 @@ let rec pp_function method_
328341
P.space f ;
329342
P.string f L.eq;
330343
P.space f ;
331-
vident cxt f v
344+
345+
optimize len (arity = NA && len <= 8) cxt f v
332346
| None ->
333347
if return then
334348
begin
335349
P.string f L.return ;
336350
P.space f;
337351
end;
338-
vident cxt f v
352+
optimize len (arity = NA && len <=8) cxt f v
339353
end
340354
| _, _ ->
341355

jscomp/runtime/curry.ml

Lines changed: 40 additions & 0 deletions
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+

jscomp/test/.depend

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ basic_module_test.cmx : ../stdlib/set.cmx pr6726.cmx offset.cmx \
7575
mt_global.cmx mt.cmx basic_module_test.cmi
7676
bdd.cmj : ../stdlib/array.cmi
7777
bdd.cmx : ../stdlib/array.cmx
78+
bench.cmj : ../stdlib/array.cmi
79+
bench.cmx : ../stdlib/array.cmx
7880
bigarray_test.cmj : ../stdlib/int32.cmi ../stdlib/complex.cmi \
7981
../stdlib/bigarray.cmi
8082
bigarray_test.cmx : ../stdlib/int32.cmx ../stdlib/complex.cmx \
@@ -163,6 +165,8 @@ digest_test.cmx : ../stdlib/string.cmx ../stdlib/printf.cmx mt.cmx \
163165
ext_array.cmx ../stdlib/digest.cmx ../stdlib/array.cmx
164166
div_by_zero_test.cmj : mt.cmi ../stdlib/int64.cmi ../stdlib/int32.cmi
165167
div_by_zero_test.cmx : mt.cmx ../stdlib/int64.cmx ../stdlib/int32.cmx
168+
earger_curry_test.cmj : ../stdlib/array.cmi
169+
earger_curry_test.cmx : ../stdlib/array.cmx
166170
empty_obj.cmj :
167171
empty_obj.cmx :
168172
epsilon_test.cmj : mt.cmi
@@ -439,6 +443,8 @@ offset.cmj : ../stdlib/string.cmi ../stdlib/set.cmi
439443
offset.cmx : ../stdlib/string.cmx ../stdlib/set.cmx
440444
optional_ffi_test.cmj : mt.cmi
441445
optional_ffi_test.cmx : mt.cmx
446+
poly_type.cmj : ../runtime/js.cmj
447+
poly_type.cmx : ../runtime/js.cmx
442448
poly_variant_test.cmj : ../runtime/js.cmj poly_variant_test.cmi
443449
poly_variant_test.cmx : ../runtime/js.cmx poly_variant_test.cmi
444450
polymorphism_test.cmj : polymorphism_test.cmi
@@ -839,6 +845,8 @@ basic_module_test.cmj : ../stdlib/set.cmj pr6726.cmj offset.cmj \
839845
mt_global.cmj mt.cmj basic_module_test.cmi
840846
bdd.cmo : ../stdlib/array.cmi
841847
bdd.cmj : ../stdlib/array.cmj
848+
bench.cmo : ../stdlib/array.cmi
849+
bench.cmj : ../stdlib/array.cmj
842850
bigarray_test.cmo : ../stdlib/int32.cmi ../stdlib/complex.cmi \
843851
../stdlib/bigarray.cmi
844852
bigarray_test.cmj : ../stdlib/int32.cmj ../stdlib/complex.cmj \
@@ -927,6 +935,8 @@ digest_test.cmj : ../stdlib/string.cmj ../stdlib/printf.cmj mt.cmj \
927935
ext_array.cmj ../stdlib/digest.cmj ../stdlib/array.cmj
928936
div_by_zero_test.cmo : mt.cmi ../stdlib/int64.cmi ../stdlib/int32.cmi
929937
div_by_zero_test.cmj : mt.cmj ../stdlib/int64.cmj ../stdlib/int32.cmj
938+
earger_curry_test.cmo : ../stdlib/array.cmi
939+
earger_curry_test.cmj : ../stdlib/array.cmj
930940
empty_obj.cmo :
931941
empty_obj.cmj :
932942
epsilon_test.cmo : mt.cmi
@@ -1203,6 +1213,8 @@ offset.cmo : ../stdlib/string.cmi ../stdlib/set.cmi
12031213
offset.cmj : ../stdlib/string.cmj ../stdlib/set.cmj
12041214
optional_ffi_test.cmo : mt.cmi
12051215
optional_ffi_test.cmj : mt.cmj
1216+
poly_type.cmo : ../runtime/js.cmo
1217+
poly_type.cmj : ../runtime/js.cmj
12061218
poly_variant_test.cmo : ../runtime/js.cmo poly_variant_test.cmi
12071219
poly_variant_test.cmj : ../runtime/js.cmj poly_variant_test.cmi
12081220
polymorphism_test.cmo : polymorphism_test.cmi

jscomp/test/Makefile

Lines changed: 2 additions & 1 deletion
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 bench
64+
6465

6566

6667
SOURCE_LIST := js_dyn $(OTHERS)

0 commit comments

Comments
 (0)