Skip to content

Commit dad35f4

Browse files
committedOct 7, 2018
not tweaking function arities
1 parent 7738703 commit dad35f4

File tree

3 files changed

+43
-41
lines changed

3 files changed

+43
-41
lines changed
 

‎jscomp/core/js_dump.ml

-6
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,7 @@ let continue f s =
237237
P.string f s;
238238
semi f
239239

240-
241240
let formal_parameter_list cxt f offset l env =
242-
match l with
243-
| [x] when
244-
Js_fun_env.get_unused env offset ->
245-
cxt
246-
| _ ->
247241
iter_lst cxt f l Ext_pp_scope.ident comma_sp
248242
(* IdentMap *)
249243
(*

‎jscomp/runtime/curry.ml

+34-21
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2+
(* Copyright (C) 2015 - Authors of BuckleScript
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU Lesser General Public License as published by
@@ -23,17 +23,14 @@
2323
* along with this program; if not, write to the Free Software
2424
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2525

26-
27-
(** *)
28-
2926
(** Generated by scripts/curry_gen.ml *)
3027
external function_length : 'a -> int = "#function_length"
3128
external apply_args : ('a -> 'b) -> _ array -> 'b = "#apply"
3229
external sub : 'a array -> int -> int -> 'a array = "caml_array_sub"
3330

31+
(** Public *)
3432
let rec app f args =
3533
let arity = function_length f in
36-
let arity = if arity = 0 then 1 else arity in (* TOOD: optimize later *)
3734
let len = Array.length args in
3835
let d = arity - len in
3936
if d = 0 then
@@ -46,18 +43,26 @@ let rec app f args =
4643
Obj.magic (fun x -> app f (Caml_array.append args [|x|] ))
4744

4845

46+
(* Internal use *)
4947
external apply1 : ('a0 -> 'a1) -> 'a0 -> 'a1 = "#apply1"
48+
(* Internal use *)
5049
external apply2 : ('a0 -> 'a1 -> 'a2) -> 'a0 -> 'a1 -> 'a2 = "#apply2"
50+
(* Internal use *)
5151
external apply3 : ('a0 -> 'a1 -> 'a2 -> 'a3) -> 'a0 -> 'a1 -> 'a2 -> 'a3 = "#apply3"
52+
(* Internal use *)
5253
external apply4 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4) -> 'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 = "#apply4"
54+
(* Internal use *)
5355
external apply5 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5) -> 'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 = "#apply5"
56+
(* Internal use *)
5457
external apply6 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6) -> 'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 = "#apply6"
58+
(* Internal use *)
5559
external apply7 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7) -> 'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 = "#apply7"
60+
(* Internal use *)
5661
external apply8 : ('a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8) -> 'a0 -> 'a1 -> 'a2 -> 'a3 -> 'a4 -> 'a5 -> 'a6 -> 'a7 -> 'a8 = "#apply8"
5762

63+
(* Intenral use *)
5864
let curry_1 o a0 arity =
5965
match arity with
60-
| 0 -> apply1 (Obj.magic o) a0
6166
| 1 -> apply1 (Obj.magic o) a0
6267
| 2 -> apply2 (Obj.magic o) a0
6368
| 3 -> apply3 (Obj.magic o) a0
@@ -67,20 +72,21 @@ let curry_1 o a0 arity =
6772
| 7 -> apply7 (Obj.magic o) a0
6873
| _ -> Obj.magic (app o [|a0|])
6974

75+
(** Public *)
7076
let _1 o a0 =
7177
let arity = function_length o in
7278
if arity = 1 then apply1 o a0
7379
else curry_1 o a0 arity
74-
80+
(** Public *)
7581
let __1 o =
7682
let arity = function_length o in
7783
if arity = 1 then o
7884
else fun a0 -> _1 o a0
7985

8086

87+
(* Intenral use *)
8188
let curry_2 o a0 a1 arity =
8289
match arity with
83-
| 0 -> app (apply1 (Obj.magic o) a0) [|a1|]
8490
| 1 -> app (apply1 (Obj.magic o) a0) [|a1|]
8591
| 2 -> apply2 (Obj.magic o) a0 a1
8692
| 3 -> apply3 (Obj.magic o) a0 a1
@@ -90,20 +96,21 @@ let curry_2 o a0 a1 arity =
9096
| 7 -> apply7 (Obj.magic o) a0 a1
9197
| _ -> Obj.magic (app o [|a0;a1|])
9298

99+
(** Public *)
93100
let _2 o a0 a1 =
94101
let arity = function_length o in
95102
if arity = 2 then apply2 o a0 a1
96103
else curry_2 o a0 a1 arity
97-
104+
(** Public *)
98105
let __2 o =
99106
let arity = function_length o in
100107
if arity = 2 then o
101108
else fun a0 a1 -> _2 o a0 a1
102109

103110

111+
(* Intenral use *)
104112
let curry_3 o a0 a1 a2 arity =
105113
match arity with
106-
| 0 -> app (apply1 (Obj.magic o) a0) [|a1;a2|]
107114
| 1 -> app (apply1 (Obj.magic o) a0) [|a1;a2|]
108115
| 2 -> app (apply2 (Obj.magic o) a0 a1) [|a2|]
109116
| 3 -> apply3 (Obj.magic o) a0 a1 a2
@@ -113,20 +120,21 @@ let curry_3 o a0 a1 a2 arity =
113120
| 7 -> apply7 (Obj.magic o) a0 a1 a2
114121
| _ -> Obj.magic (app o [|a0;a1;a2|])
115122

123+
(** Public *)
116124
let _3 o a0 a1 a2 =
117125
let arity = function_length o in
118126
if arity = 3 then apply3 o a0 a1 a2
119127
else curry_3 o a0 a1 a2 arity
120-
128+
(** Public *)
121129
let __3 o =
122130
let arity = function_length o in
123131
if arity = 3 then o
124132
else fun a0 a1 a2 -> _3 o a0 a1 a2
125133

126134

135+
(* Intenral use *)
127136
let curry_4 o a0 a1 a2 a3 arity =
128137
match arity with
129-
| 0 -> app (apply1 (Obj.magic o) a0) [|a1;a2;a3|]
130138
| 1 -> app (apply1 (Obj.magic o) a0) [|a1;a2;a3|]
131139
| 2 -> app (apply2 (Obj.magic o) a0 a1) [|a2;a3|]
132140
| 3 -> app (apply3 (Obj.magic o) a0 a1 a2) [|a3|]
@@ -136,20 +144,21 @@ let curry_4 o a0 a1 a2 a3 arity =
136144
| 7 -> apply7 (Obj.magic o) a0 a1 a2 a3
137145
| _ -> Obj.magic (app o [|a0;a1;a2;a3|])
138146

147+
(** Public *)
139148
let _4 o a0 a1 a2 a3 =
140149
let arity = function_length o in
141150
if arity = 4 then apply4 o a0 a1 a2 a3
142151
else curry_4 o a0 a1 a2 a3 arity
143-
152+
(** Public *)
144153
let __4 o =
145154
let arity = function_length o in
146155
if arity = 4 then o
147156
else fun a0 a1 a2 a3 -> _4 o a0 a1 a2 a3
148157

149158

159+
(* Intenral use *)
150160
let curry_5 o a0 a1 a2 a3 a4 arity =
151161
match arity with
152-
| 0 -> app (apply1 (Obj.magic o) a0) [|a1;a2;a3;a4|]
153162
| 1 -> app (apply1 (Obj.magic o) a0) [|a1;a2;a3;a4|]
154163
| 2 -> app (apply2 (Obj.magic o) a0 a1) [|a2;a3;a4|]
155164
| 3 -> app (apply3 (Obj.magic o) a0 a1 a2) [|a3;a4|]
@@ -159,20 +168,21 @@ let curry_5 o a0 a1 a2 a3 a4 arity =
159168
| 7 -> apply7 (Obj.magic o) a0 a1 a2 a3 a4
160169
| _ -> Obj.magic (app o [|a0;a1;a2;a3;a4|])
161170

171+
(** Public *)
162172
let _5 o a0 a1 a2 a3 a4 =
163173
let arity = function_length o in
164174
if arity = 5 then apply5 o a0 a1 a2 a3 a4
165175
else curry_5 o a0 a1 a2 a3 a4 arity
166-
176+
(** Public *)
167177
let __5 o =
168178
let arity = function_length o in
169179
if arity = 5 then o
170180
else fun a0 a1 a2 a3 a4 -> _5 o a0 a1 a2 a3 a4
171181

172182

183+
(* Intenral use *)
173184
let curry_6 o a0 a1 a2 a3 a4 a5 arity =
174185
match arity with
175-
| 0 -> app (apply1 (Obj.magic o) a0) [|a1;a2;a3;a4;a5|]
176186
| 1 -> app (apply1 (Obj.magic o) a0) [|a1;a2;a3;a4;a5|]
177187
| 2 -> app (apply2 (Obj.magic o) a0 a1) [|a2;a3;a4;a5|]
178188
| 3 -> app (apply3 (Obj.magic o) a0 a1 a2) [|a3;a4;a5|]
@@ -182,20 +192,21 @@ let curry_6 o a0 a1 a2 a3 a4 a5 arity =
182192
| 7 -> apply7 (Obj.magic o) a0 a1 a2 a3 a4 a5
183193
| _ -> Obj.magic (app o [|a0;a1;a2;a3;a4;a5|])
184194

195+
(** Public *)
185196
let _6 o a0 a1 a2 a3 a4 a5 =
186197
let arity = function_length o in
187198
if arity = 6 then apply6 o a0 a1 a2 a3 a4 a5
188199
else curry_6 o a0 a1 a2 a3 a4 a5 arity
189-
200+
(** Public *)
190201
let __6 o =
191202
let arity = function_length o in
192203
if arity = 6 then o
193204
else fun a0 a1 a2 a3 a4 a5 -> _6 o a0 a1 a2 a3 a4 a5
194205

195206

207+
(* Intenral use *)
196208
let curry_7 o a0 a1 a2 a3 a4 a5 a6 arity =
197209
match arity with
198-
| 0 -> app (apply1 (Obj.magic o) a0) [|a1;a2;a3;a4;a5;a6|]
199210
| 1 -> app (apply1 (Obj.magic o) a0) [|a1;a2;a3;a4;a5;a6|]
200211
| 2 -> app (apply2 (Obj.magic o) a0 a1) [|a2;a3;a4;a5;a6|]
201212
| 3 -> app (apply3 (Obj.magic o) a0 a1 a2) [|a3;a4;a5;a6|]
@@ -205,20 +216,21 @@ let curry_7 o a0 a1 a2 a3 a4 a5 a6 arity =
205216
| 7 -> apply7 (Obj.magic o) a0 a1 a2 a3 a4 a5 a6
206217
| _ -> Obj.magic (app o [|a0;a1;a2;a3;a4;a5;a6|])
207218

219+
(** Public *)
208220
let _7 o a0 a1 a2 a3 a4 a5 a6 =
209221
let arity = function_length o in
210222
if arity = 7 then apply7 o a0 a1 a2 a3 a4 a5 a6
211223
else curry_7 o a0 a1 a2 a3 a4 a5 a6 arity
212-
224+
(** Public *)
213225
let __7 o =
214226
let arity = function_length o in
215227
if arity = 7 then o
216228
else fun a0 a1 a2 a3 a4 a5 a6 -> _7 o a0 a1 a2 a3 a4 a5 a6
217229

218230

231+
(* Intenral use *)
219232
let curry_8 o a0 a1 a2 a3 a4 a5 a6 a7 arity =
220233
match arity with
221-
| 0 -> app (apply1 (Obj.magic o) a0) [|a1;a2;a3;a4;a5;a6;a7|]
222234
| 1 -> app (apply1 (Obj.magic o) a0) [|a1;a2;a3;a4;a5;a6;a7|]
223235
| 2 -> app (apply2 (Obj.magic o) a0 a1) [|a2;a3;a4;a5;a6;a7|]
224236
| 3 -> app (apply3 (Obj.magic o) a0 a1 a2) [|a3;a4;a5;a6;a7|]
@@ -228,11 +240,12 @@ let curry_8 o a0 a1 a2 a3 a4 a5 a6 a7 arity =
228240
| 7 -> app (apply7 (Obj.magic o) a0 a1 a2 a3 a4 a5 a6) [|a7|]
229241
| _ -> Obj.magic (app o [|a0;a1;a2;a3;a4;a5;a6;a7|])
230242

243+
(** Public *)
231244
let _8 o a0 a1 a2 a3 a4 a5 a6 a7 =
232245
let arity = function_length o in
233246
if arity = 8 then apply8 o a0 a1 a2 a3 a4 a5 a6 a7
234247
else curry_8 o a0 a1 a2 a3 a4 a5 a6 a7 arity
235-
248+
(** Public *)
236249
let __8 o =
237250
let arity = function_length o in
238251
if arity = 8 then o

‎scripts/curry_gen.ml

+9-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
let prelude ={|
2-
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
2+
(* Copyright (C) 2015 - Authors of BuckleScript
33
*
44
* This program is free software: you can redistribute it and/or modify
55
* it under the terms of the GNU Lesser General Public License as published by
@@ -28,9 +28,9 @@ external function_length : 'a -> int = "#function_length"
2828
external apply_args : ('a -> 'b) -> _ array -> 'b = "#apply"
2929
external sub : 'a array -> int -> int -> 'a array = "caml_array_sub"
3030

31+
(** Public *)
3132
let rec app f args =
3233
let arity = function_length f in
33-
let arity = if arity = 0 then 1 else arity in (* TOOD: optimize later *)
3434
let len = Array.length args in
3535
let d = arity - len in
3636
if d = 0 then
@@ -58,15 +58,6 @@ let generate_case
5858
(if arity >= args_number then
5959
Printf.sprintf "apply%d (Obj.magic o) %s"
6060
arity (String.concat " " args)
61-
else
62-
if arity = 0 then
63-
match args with
64-
| first_arg :: [] ->
65-
Printf.sprintf "apply1 (Obj.magic o) %s" first_arg
66-
| first_arg :: rest ->
67-
Printf.sprintf "app (apply1 (Obj.magic o) %s) [|%s|] "
68-
first_arg (String.concat ";" rest)
69-
| _ -> assert false
7061
else
7162
Printf.sprintf
7263
"app (apply%d (Obj.magic o) %s) [|%s|]"
@@ -92,7 +83,8 @@ let generate_apply arity =
9283
(fun acc x -> acc ^ " -> " ^ x )
9384
x xs in
9485
Printf.sprintf
95-
"external apply%d : (%s) -> %s = \"#apply%d\""
86+
"(* Internal use *)\n\
87+
external apply%d : (%s) -> %s = \"#apply%d\""
9688
arity ty ty arity
9789

9890

@@ -104,15 +96,17 @@ let generate_fun args_number =
10496
let args_string = (String.concat " " args) in
10597

10698
Printf.sprintf {|
99+
(* Intenral use *)
107100
let curry_%d o %s arity =
108101
match arity with
109102
|%s
110103

104+
(** Public *)
111105
let _%d o %s =
112106
let arity = function_length o in
113107
if arity = %d then apply%d o %s
114108
else curry_%d o %s arity
115-
109+
(** Public *)
116110
let __%d o =
117111
let arity = function_length o in
118112
if arity = %d then o
@@ -122,7 +116,8 @@ let __%d o =
122116
args_string
123117
(String.concat "\n |"
124118

125-
(list_init number (fun arity -> generate_case ~arity ~args_number args_array args)
119+
(list_init (number - 1)
120+
(fun arity -> generate_case ~arity:(arity + 1) ~args_number args_array args)
126121
@ [ generate_case ~args_number args_array args]
127122
)
128123
)

0 commit comments

Comments
 (0)
Please sign in to comment.