Skip to content

Commit 2ba3f2b

Browse files
authored
Merge pull request #4296 from BuckleScript/uncurry_pattern_match
support pattern match in uncurried function argument
2 parents 4af1978 + 70c2e6c commit 2ba3f2b

40 files changed

+55549
-55190
lines changed

jscomp/core/bs_conditional_initial.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
(* Clflags.keep_locs := false; *)
2828
let setup_env () =
2929
Env.Persistent_signature.load := Bs_cmi_load.load_cmi;
30+
Translcore.wrap_single_field_record := Transl_single_field_record.wrap_single_field_record;
3031
Typemod.should_hide := Typemod_hide.should_hide;
3132
Clflags.no_std_include := true;
3233
Warnings.parse_options false Bsc_warnings.defaults_w;

jscomp/core/js_pass_tailcall_inline.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,17 @@ let subst (export_set : Set_ident.t) stats =
195195
| (None | Some _) ->
196196
[self#statement st ]
197197
end
198+
199+
| [{statement_desc =
200+
Return {return_value =
201+
{expression_desc =
202+
Call({expression_desc = Fun (false, params, block, env)},args,_info)}} } ]
203+
204+
when Ext_list.same_length params args
205+
->
206+
let no_tailcall = Js_fun_env.no_tailcall env in
207+
let processed_blocks = ( self#block block) (* see #278 before changes*) in
208+
inline_call no_tailcall params args processed_blocks
198209
| x :: xs
199210
->
200211
self#statement x :: self#block xs

jscomp/core/lam.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ let rec is_eta_conversion_exn
275275
| _, _, _ -> raise_notrace Not_simple_form
276276

277277
(** FIXME: more robust inlining check later, we should inline it before we add stub code*)
278-
let apply fn args loc status : t =
278+
let rec apply fn args loc status : t =
279279
match fn with
280280
| Lfunction {
281281
params;
@@ -322,6 +322,10 @@ let apply fn args loc status : t =
322322
Ext_list.fold_right2 (fun p arg acc ->
323323
Llet(Strict,p,arg,acc)
324324
) params args body *) (* TODO: more rigirous analysis on [let_kind] *)
325+
| Llet (kind,id, e, (Lfunction _ as fn)) ->
326+
Llet (kind, id, e, apply fn args loc status)
327+
(* | Llet (kind0, id0, e0, Llet (kind,id, e, (Lfunction _ as fn))) ->
328+
Llet(kind0,id0,e0,Llet (kind, id, e, apply fn args loc status)) *)
325329
| _ ->
326330
Lapply { ap_func = fn; ap_args = args; ap_loc = loc ; ap_status = status }
327331

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(* Copyright (C) 2020 - Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
* GNU Lesser General Public License for more details.
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
26+
let wrap_single_field_record loc lbl_name (lambda : Lambda.lambda) : Lambda.lambda =
27+
if lbl_name.[0] = 'I' then
28+
let arity_s = String.sub lbl_name 1 (String.length lbl_name - 1) in
29+
Lprim (
30+
Pccall (Primitive.make ~name:"#fn_mk" ~alloc:true ~native_name:arity_s ~native_repr_args:[Same_as_ocaml_repr] ~native_repr_res: Same_as_ocaml_repr), [lambda],loc)
31+
else lambda

jscomp/main/builtin_cmi_datasets.ml

Lines changed: 111 additions & 111 deletions
Large diffs are not rendered by default.

jscomp/main/builtin_cmj_datasets.ml

Lines changed: 29 additions & 29 deletions
Large diffs are not rendered by default.

jscomp/others/js_OO.ml

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -29,139 +29,139 @@ external unsafe_to_method : 'a -> 'a = "#fn_method"
2929
(**/**)
3030
module Callback = struct
3131
type 'a arity1 = {
32-
i : 'a [@internal]
32+
i1 : 'a [@internal]
3333
}
3434
type 'a arity2 = {
35-
i : 'a [@internal]
35+
i2 : 'a [@internal]
3636
}
3737
type 'a arity3 = {
38-
i : 'a [@internal]
38+
i3 : 'a [@internal]
3939
}
4040
type 'a arity4 = {
41-
i : 'a [@internal]
41+
i4 : 'a [@internal]
4242
}
4343
type 'a arity5 = {
44-
i : 'a [@internal]
44+
i5 : 'a [@internal]
4545
}
4646
type 'a arity6 = {
47-
i : 'a [@internal]
47+
i6 : 'a [@internal]
4848
}
4949
type 'a arity7 = {
50-
i : 'a [@internal]
50+
i7 : 'a [@internal]
5151
}
5252
type 'a arity8 = {
53-
i : 'a [@internal]
53+
i8 : 'a [@internal]
5454
}
5555
type 'a arity9 = {
56-
i : 'a [@internal]
56+
i9 : 'a [@internal]
5757
}
5858
type 'a arity10 = {
59-
i : 'a [@internal]
59+
i10 : 'a [@internal]
6060
}
6161
type 'a arity11 = {
62-
i : 'a [@internal]
62+
i11 : 'a [@internal]
6363
}
6464
type 'a arity12 = {
65-
i : 'a [@internal]
65+
i12 : 'a [@internal]
6666
}
6767
type 'a arity13 = {
68-
i : 'a [@internal]
68+
i13 : 'a [@internal]
6969
}
7070
type 'a arity14 = {
71-
i : 'a [@internal]
71+
i14 : 'a [@internal]
7272
}
7373
type 'a arity15 = {
74-
i : 'a [@internal]
74+
i15 : 'a [@internal]
7575
}
7676
type 'a arity16 = {
77-
i : 'a [@internal]
77+
i16 : 'a [@internal]
7878
}
7979
type 'a arity17 = {
80-
i : 'a [@internal]
80+
i17 : 'a [@internal]
8181
}
8282
type 'a arity18 = {
83-
i : 'a [@internal]
83+
i18 : 'a [@internal]
8484
}
8585
type 'a arity19 = {
86-
i : 'a [@internal]
86+
i19 : 'a [@internal]
8787
}
8888
type 'a arity20 = {
89-
i : 'a [@internal]
89+
i20 : 'a [@internal]
9090
}
9191
type 'a arity21 = {
92-
i : 'a [@internal]
92+
i21 : 'a [@internal]
9393
}
9494
type 'a arity22 = {
95-
i : 'a [@internal]
95+
i22 : 'a [@internal]
9696
}
9797
end
9898
module Meth = struct
9999
type + 'a arity0
100100
type 'a arity1 = {
101-
i : 'a [@internal]
101+
i1 : 'a [@internal]
102102
}
103103
type 'a arity2 = {
104-
i : 'a [@internal]
104+
i2 : 'a [@internal]
105105
}
106106
type 'a arity3 = {
107-
i : 'a [@internal]
107+
i3 : 'a [@internal]
108108
}
109109
type 'a arity4 = {
110-
i : 'a [@internal]
110+
i4 : 'a [@internal]
111111
}
112112
type 'a arity5 = {
113-
i : 'a [@internal]
113+
i5 : 'a [@internal]
114114
}
115115
type 'a arity6 = {
116-
i : 'a [@internal]
116+
i6 : 'a [@internal]
117117
}
118118
type 'a arity7 = {
119-
i : 'a [@internal]
119+
i7 : 'a [@internal]
120120
}
121121
type 'a arity8 = {
122-
i : 'a [@internal]
122+
i8 : 'a [@internal]
123123
}
124124
type 'a arity9 = {
125-
i : 'a [@internal]
125+
i9 : 'a [@internal]
126126
}
127127
type 'a arity10 = {
128-
i : 'a [@internal]
128+
i10 : 'a [@internal]
129129
}
130130
type 'a arity11 = {
131-
i : 'a [@internal]
131+
i11 : 'a [@internal]
132132
}
133133
type 'a arity12 = {
134-
i : 'a [@internal]
134+
i12 : 'a [@internal]
135135
}
136136
type 'a arity13 = {
137-
i : 'a [@internal]
137+
i13 : 'a [@internal]
138138
}
139139
type 'a arity14 = {
140-
i : 'a [@internal]
140+
i14 : 'a [@internal]
141141
}
142142
type 'a arity15 = {
143-
i : 'a [@internal]
143+
i15 : 'a [@internal]
144144
}
145145
type 'a arity16 = {
146-
i : 'a [@internal]
146+
i16 : 'a [@internal]
147147
}
148148
type 'a arity17 = {
149-
i : 'a [@internal]
149+
i17 : 'a [@internal]
150150
}
151151
type 'a arity18 = {
152-
i : 'a [@internal]
152+
i18 : 'a [@internal]
153153
}
154154
type 'a arity19 = {
155-
i : 'a [@internal]
155+
i19 : 'a [@internal]
156156
}
157157
type 'a arity20 = {
158-
i : 'a [@internal]
158+
i20 : 'a [@internal]
159159
}
160160
type 'a arity21 = {
161-
i : 'a [@internal]
161+
i21 : 'a [@internal]
162162
}
163163
type 'a arity22 = {
164-
i : 'a [@internal]
164+
i22 : 'a [@internal]
165165
}
166166
end
167167

jscomp/runtime/js.ml

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,72 +57,74 @@ type +'a t
5757
Absent cmi file when looking up module alias.
5858
*)
5959
module Fn = struct
60-
type + 'a arity0
60+
type 'a arity0 = {
61+
i0 : unit -> 'a [@internal]
62+
}
6163
type 'a arity1 = {
62-
i : 'a [@internal]
64+
i1 : 'a [@internal]
6365
}
6466
type 'a arity2 = {
65-
i : 'a [@internal]
67+
i2 : 'a [@internal]
6668
}
6769
type 'a arity3 = {
68-
i : 'a [@internal]
70+
i3 : 'a [@internal]
6971
}
7072
type 'a arity4 = {
71-
i : 'a [@internal]
73+
i4 : 'a [@internal]
7274
}
7375
type 'a arity5 = {
74-
i : 'a [@internal]
76+
i5 : 'a [@internal]
7577
}
7678
type 'a arity6 = {
77-
i : 'a [@internal]
79+
i6 : 'a [@internal]
7880
}
7981
type 'a arity7 = {
80-
i : 'a [@internal]
82+
i7 : 'a [@internal]
8183
}
8284
type 'a arity8 = {
83-
i : 'a [@internal]
85+
i8 : 'a [@internal]
8486
}
8587
type 'a arity9 = {
86-
i : 'a [@internal]
88+
i9 : 'a [@internal]
8789
}
8890
type 'a arity10 = {
89-
i : 'a [@internal]
91+
i10 : 'a [@internal]
9092
}
9193
type 'a arity11 = {
92-
i : 'a [@internal]
94+
i11 : 'a [@internal]
9395
}
9496
type 'a arity12 = {
95-
i : 'a [@internal]
97+
i12 : 'a [@internal]
9698
}
9799
type 'a arity13 = {
98-
i : 'a [@internal]
100+
i13 : 'a [@internal]
99101
}
100102
type 'a arity14 = {
101-
i : 'a [@internal]
103+
i14 : 'a [@internal]
102104
}
103105
type 'a arity15 = {
104-
i : 'a [@internal]
106+
i15 : 'a [@internal]
105107
}
106108
type 'a arity16 = {
107-
i : 'a [@internal]
109+
i16 : 'a [@internal]
108110
}
109111
type 'a arity17 = {
110-
i : 'a [@internal]
112+
i17 : 'a [@internal]
111113
}
112114
type 'a arity18 = {
113-
i : 'a [@internal]
115+
i18 : 'a [@internal]
114116
}
115117
type 'a arity19 = {
116-
i : 'a [@internal]
118+
i19 : 'a [@internal]
117119
}
118120
type 'a arity20 = {
119-
i : 'a [@internal]
121+
i20 : 'a [@internal]
120122
}
121123
type 'a arity21 = {
122-
i : 'a [@internal]
124+
i21 : 'a [@internal]
123125
}
124126
type 'a arity22 = {
125-
i : 'a [@internal]
127+
i22 : 'a [@internal]
126128
}
127129
end
128130

@@ -135,7 +137,7 @@ module Internal = struct
135137
(* Use opaque instead of [._n] to prevent some optimizations happening *)
136138
external run : 'a arity0 -> 'a = "#run"
137139
external opaque : 'a -> 'a = "%opaque"
138-
external mk0 : (unit -> 'a0) -> 'a0 arity0 = "#fn_mk" "0"
140+
139141
end
140142
(**/**)
141143

jscomp/syntax/ast_literal.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ module Lid = struct
5959
Ldot (js_oo, "Callback")
6060
let js_obj : t = Ldot (Lident "Js", "t")
6161
let ignore_id : t = Ldot (Lident "Pervasives", "ignore")
62-
let hidden_field : t = Lident "I"
62+
let hidden_field n : t = Lident ("I" ^ n)
6363
let js_null : t = Ldot (Lident "Js", "null")
6464
let js_undefined : t = Ldot (Lident "Js", "undefined")
6565
let js_null_undefined : t = Ldot (Lident "Js", "null_undefined")

jscomp/syntax/ast_literal.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module Lid : sig
4141
val js_meth : t
4242
val js_meth_callback : t
4343
val js_obj : t
44-
val hidden_field : t
44+
val hidden_field : string -> t
4545
val ignore_id : t
4646
val js_null : t
4747
val js_undefined : t

0 commit comments

Comments
 (0)