Skip to content

Commit f1044e0

Browse files
authoredAug 10, 2018
Merge pull request rescript-lang#2995 from BuckleScript/upgrade
provide compatibility layer around arg_label
2 parents fa62f3b + e8ac9ec commit f1044e0

11 files changed

+124
-47
lines changed
 

‎jscomp/all.depend

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ syntax/ast_external_mk.cmx : syntax/ast_compatible.cmx \
186186
syntax/ast_external_mk.cmi
187187
syntax/ast_lift.cmx : syntax/ast_lift.cmi
188188
syntax/ast_literal.cmx : syntax/ast_literal.cmi
189-
syntax/ast_pat.cmx : syntax/ast_pat.cmi
189+
syntax/ast_pat.cmx : syntax/ast_compatible.cmx syntax/ast_pat.cmi
190190
syntax/external_arg_spec.cmx : ext/ext_position.cmx ext/ext_json_parse.cmx \
191191
syntax/external_arg_spec.cmi
192192
syntax/ast_payload.cmx : ext/string_map.cmx ext/ext_list.cmx \

‎jscomp/bin/all_ounit_tests.ml

+9-1
Original file line numberDiff line numberDiff line change
@@ -14323,6 +14323,9 @@ module Ast_compatible : sig
1432314323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
1432414324

1432514325

14326+
type arg_label = string
14327+
14328+
1432614329
type loc = Location.t
1432714330
type attrs = Parsetree.attribute list
1432814331
open Parsetree
@@ -14400,6 +14403,9 @@ val fun_ :
1440014403
pattern ->
1440114404
expression ->
1440214405
expression
14406+
14407+
val is_arg_label_simple :
14408+
arg_label -> bool
1440314409
end = struct
1440414410
#1 "ast_compatible.ml"
1440514411
(* Copyright (C) 2018 Authors of BuckleScript
@@ -14432,7 +14438,7 @@ open Parsetree
1443214438
let default_loc = Location.none
1443314439

1443414440

14435-
14441+
type arg_label = string
1443614442
let const_exp_string
1443714443
?(loc = default_loc)
1443814444
?(attrs = [])
@@ -14540,6 +14546,8 @@ let fun_
1454014546
pexp_attributes = attrs;
1454114547
pexp_desc = Pexp_fun("",None, pat, exp)
1454214548
}
14549+
14550+
let is_arg_label_simple s = s = ""
1454314551

1454414552
end
1454514553
module Bs_loc : sig

‎jscomp/syntax/ast_compatible.ml

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let default_loc = Location.none
3030
#if OCAML_VERSION =~ ">4.03.0" then
3131

3232
#else
33-
33+
type arg_label = string
3434
let const_exp_string
3535
?(loc = default_loc)
3636
?(attrs = [])
@@ -138,4 +138,6 @@ let fun_
138138
pexp_attributes = attrs;
139139
pexp_desc = Pexp_fun("",None, pat, exp)
140140
}
141+
142+
let is_arg_label_simple s = s = ""
141143
#end

‎jscomp/syntax/ast_compatible.mli

+8-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25+
#if OCAML_VERSION =~ ">4.3.0" then
26+
#else
27+
type arg_label = string
28+
#end
2529

2630
type loc = Location.t
2731
type attrs = Parsetree.attribute list
@@ -99,4 +103,7 @@ val fun_ :
99103
?attrs:attrs ->
100104
pattern ->
101105
expression ->
102-
expression
106+
expression
107+
108+
val is_arg_label_simple :
109+
arg_label -> bool

‎jscomp/syntax/ast_exp_extension.ml

+5-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ let rec unroll_function_aux
2828
(body : Parsetree.expression) : string list * string =
2929
match body.pexp_desc with
3030
| Pexp_constant(Const_string(block,_)) -> acc, block
31-
| Pexp_fun("",None,{ppat_desc = Ppat_var s},cont) ->
31+
| Pexp_fun(arg_label,_,{ppat_desc = Ppat_var s},cont)
32+
when Ast_compatible.is_arg_label_simple arg_label ->
3233
unroll_function_aux (s.txt::acc) cont
3334
| _ ->
3435
Location.raise_errorf ~loc:body.pexp_loc
@@ -53,7 +54,9 @@ let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper)
5354
begin match txt with
5455
| "bs.raw" | "raw" ->
5556
begin match payload with
56-
| PStr [{pstr_desc = Pstr_eval({pexp_desc = Pexp_fun("",None,pat,body)},_)}]
57+
| PStr [
58+
{pstr_desc = Pstr_eval({pexp_desc = Pexp_fun(arg_label,_,pat,body)},_)}]
59+
when Ast_compatible.is_arg_label_simple arg_label
5760
->
5861
begin match pat.ppat_desc, body.pexp_desc with
5962
| Ppat_construct ({txt = Lident "()"}, None), Pexp_constant(Const_string(block,_))

‎jscomp/syntax/ast_pat.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ let arity_of_fun
4141
(e : Parsetree.expression) =
4242
let rec aux (e : Parsetree.expression) =
4343
match e.pexp_desc with
44-
| Pexp_fun ("", None, pat, e) ->
44+
| Pexp_fun (arg_label, _, pat, e)
45+
when Ast_compatible.is_arg_label_simple arg_label ->
4546
1 + aux e
4647
| Pexp_fun _
4748
-> Location.raise_errorf

‎jscomp/syntax/ast_util.ml

+10-6
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ let generic_to_uncurry_exp kind loc (self : Bs_ast_mapper.mapper) pat body
220220
match Ast_attributes.process_attributes_rev body.pexp_attributes with
221221
| Nothing, _ ->
222222
begin match body.pexp_desc with
223-
| Pexp_fun (label,_, arg, body)
223+
| Pexp_fun (arg_label,_, arg, body)
224224
->
225-
if label <> "" then
225+
if not (Ast_compatible.is_arg_label_simple arg_label) then
226226
Bs_syntaxerr.err loc Label_in_uncurried_bs_attribute;
227227
aux (self.pat self arg :: acc) body
228228
| _ -> self.expr self body, acc
@@ -467,8 +467,10 @@ let ocaml_obj_as_js_object
467467
->
468468
begin match e.pexp_desc with
469469
| Pexp_poly
470-
(({pexp_desc = Pexp_fun ("", None, pat, e)} ),
471-
None) ->
470+
(({pexp_desc = Pexp_fun (arg_label, _, pat, e)} ),
471+
None)
472+
when Ast_compatible.is_arg_label_simple arg_label
473+
->
472474
let arity = Ast_pat.arity_of_fun pat e in
473475
let method_type =
474476
generate_arg_type x.pcf_loc mapper label.txt arity in
@@ -529,8 +531,10 @@ let ocaml_obj_as_js_object
529531
->
530532
begin match e.pexp_desc with
531533
| Pexp_poly
532-
(({pexp_desc = Pexp_fun ("", None, pat, e)} as f),
533-
None) ->
534+
(({pexp_desc = Pexp_fun (arg_label, None, pat, e)} as f),
535+
None)
536+
when Ast_compatible.is_arg_label_simple arg_label
537+
->
534538
let arity = Ast_pat.arity_of_fun pat e in
535539
let alias_type =
536540
if aliased then None

‎jscomp/syntax/ppx_entry.ml

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ let rec unsafe_mapper : Bs_ast_mapper.mapper =
100100
| `Exn, pexp_attributes ->
101101
Ast_util.convertBsErrorFunction loc self pexp_attributes cases
102102
end
103-
| Pexp_fun ("", None, pat , body)
103+
| Pexp_fun (arg_label, _, pat , body)
104+
when Ast_compatible.is_arg_label_simple arg_label
104105
->
105106
begin match Ast_attributes.process_attributes_rev e.pexp_attributes with
106107
| Nothing, _

‎lib/bsdep.ml

+28-11
Original file line numberDiff line numberDiff line change
@@ -24459,6 +24459,9 @@ module Ast_compatible : sig
2445924459
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2446024460

2446124461

24462+
type arg_label = string
24463+
24464+
2446224465
type loc = Location.t
2446324466
type attrs = Parsetree.attribute list
2446424467
open Parsetree
@@ -24536,6 +24539,9 @@ val fun_ :
2453624539
pattern ->
2453724540
expression ->
2453824541
expression
24542+
24543+
val is_arg_label_simple :
24544+
arg_label -> bool
2453924545
end = struct
2454024546
#1 "ast_compatible.ml"
2454124547
(* Copyright (C) 2018 Authors of BuckleScript
@@ -24568,7 +24574,7 @@ open Parsetree
2456824574
let default_loc = Location.none
2456924575

2457024576

24571-
24577+
type arg_label = string
2457224578
let const_exp_string
2457324579
?(loc = default_loc)
2457424580
?(attrs = [])
@@ -24676,6 +24682,8 @@ let fun_
2467624682
pexp_attributes = attrs;
2467724683
pexp_desc = Pexp_fun("",None, pat, exp)
2467824684
}
24685+
24686+
let is_arg_label_simple s = s = ""
2467924687

2468024688
end
2468124689
module Ext_utf8 : sig
@@ -29320,7 +29328,8 @@ let arity_of_fun
2932029328
(e : Parsetree.expression) =
2932129329
let rec aux (e : Parsetree.expression) =
2932229330
match e.pexp_desc with
29323-
| Pexp_fun ("", None, pat, e) ->
29331+
| Pexp_fun (arg_label, _, pat, e)
29332+
when Ast_compatible.is_arg_label_simple arg_label ->
2932429333
1 + aux e
2932529334
| Pexp_fun _
2932629335
-> Location.raise_errorf
@@ -34194,9 +34203,9 @@ let generic_to_uncurry_exp kind loc (self : Bs_ast_mapper.mapper) pat body
3419434203
match Ast_attributes.process_attributes_rev body.pexp_attributes with
3419534204
| Nothing, _ ->
3419634205
begin match body.pexp_desc with
34197-
| Pexp_fun (label,_, arg, body)
34206+
| Pexp_fun (arg_label,_, arg, body)
3419834207
->
34199-
if label <> "" then
34208+
if not (Ast_compatible.is_arg_label_simple arg_label) then
3420034209
Bs_syntaxerr.err loc Label_in_uncurried_bs_attribute;
3420134210
aux (self.pat self arg :: acc) body
3420234211
| _ -> self.expr self body, acc
@@ -34441,8 +34450,10 @@ let ocaml_obj_as_js_object
3444134450
->
3444234451
begin match e.pexp_desc with
3444334452
| Pexp_poly
34444-
(({pexp_desc = Pexp_fun ("", None, pat, e)} ),
34445-
None) ->
34453+
(({pexp_desc = Pexp_fun (arg_label, _, pat, e)} ),
34454+
None)
34455+
when Ast_compatible.is_arg_label_simple arg_label
34456+
->
3444634457
let arity = Ast_pat.arity_of_fun pat e in
3444734458
let method_type =
3444834459
generate_arg_type x.pcf_loc mapper label.txt arity in
@@ -34503,8 +34514,10 @@ let ocaml_obj_as_js_object
3450334514
->
3450434515
begin match e.pexp_desc with
3450534516
| Pexp_poly
34506-
(({pexp_desc = Pexp_fun ("", None, pat, e)} as f),
34507-
None) ->
34517+
(({pexp_desc = Pexp_fun (arg_label, None, pat, e)} as f),
34518+
None)
34519+
when Ast_compatible.is_arg_label_simple arg_label
34520+
->
3450834521
let arity = Ast_pat.arity_of_fun pat e in
3450934522
let alias_type =
3451034523
if aliased then None
@@ -36699,7 +36712,8 @@ let rec unroll_function_aux
3669936712
(body : Parsetree.expression) : string list * string =
3670036713
match body.pexp_desc with
3670136714
| Pexp_constant(Const_string(block,_)) -> acc, block
36702-
| Pexp_fun("",None,{ppat_desc = Ppat_var s},cont) ->
36715+
| Pexp_fun(arg_label,_,{ppat_desc = Ppat_var s},cont)
36716+
when Ast_compatible.is_arg_label_simple arg_label ->
3670336717
unroll_function_aux (s.txt::acc) cont
3670436718
| _ ->
3670536719
Location.raise_errorf ~loc:body.pexp_loc
@@ -36724,7 +36738,9 @@ let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper)
3672436738
begin match txt with
3672536739
| "bs.raw" | "raw" ->
3672636740
begin match payload with
36727-
| PStr [{pstr_desc = Pstr_eval({pexp_desc = Pexp_fun("",None,pat,body)},_)}]
36741+
| PStr [
36742+
{pstr_desc = Pstr_eval({pexp_desc = Pexp_fun(arg_label,_,pat,body)},_)}]
36743+
when Ast_compatible.is_arg_label_simple arg_label
3672836744
->
3672936745
begin match pat.ppat_desc, body.pexp_desc with
3673036746
| Ppat_construct ({txt = Lident "()"}, None), Pexp_constant(Const_string(block,_))
@@ -38531,7 +38547,8 @@ let rec unsafe_mapper : Bs_ast_mapper.mapper =
3853138547
| `Exn, pexp_attributes ->
3853238548
Ast_util.convertBsErrorFunction loc self pexp_attributes cases
3853338549
end
38534-
| Pexp_fun ("", None, pat , body)
38550+
| Pexp_fun (arg_label, _, pat , body)
38551+
when Ast_compatible.is_arg_label_simple arg_label
3853538552
->
3853638553
begin match Ast_attributes.process_attributes_rev e.pexp_attributes with
3853738554
| Nothing, _

‎lib/bsppx.ml

+28-11
Original file line numberDiff line numberDiff line change
@@ -6401,6 +6401,9 @@ module Ast_compatible : sig
64016401
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
64026402

64036403

6404+
type arg_label = string
6405+
6406+
64046407
type loc = Location.t
64056408
type attrs = Parsetree.attribute list
64066409
open Parsetree
@@ -6478,6 +6481,9 @@ val fun_ :
64786481
pattern ->
64796482
expression ->
64806483
expression
6484+
6485+
val is_arg_label_simple :
6486+
arg_label -> bool
64816487
end = struct
64826488
#1 "ast_compatible.ml"
64836489
(* Copyright (C) 2018 Authors of BuckleScript
@@ -6510,7 +6516,7 @@ open Parsetree
65106516
let default_loc = Location.none
65116517

65126518

6513-
6519+
type arg_label = string
65146520
let const_exp_string
65156521
?(loc = default_loc)
65166522
?(attrs = [])
@@ -6618,6 +6624,8 @@ let fun_
66186624
pexp_attributes = attrs;
66196625
pexp_desc = Pexp_fun("",None, pat, exp)
66206626
}
6627+
6628+
let is_arg_label_simple s = s = ""
66216629

66226630
end
66236631
module Ext_utf8 : sig
@@ -11262,7 +11270,8 @@ let arity_of_fun
1126211270
(e : Parsetree.expression) =
1126311271
let rec aux (e : Parsetree.expression) =
1126411272
match e.pexp_desc with
11265-
| Pexp_fun ("", None, pat, e) ->
11273+
| Pexp_fun (arg_label, _, pat, e)
11274+
when Ast_compatible.is_arg_label_simple arg_label ->
1126611275
1 + aux e
1126711276
| Pexp_fun _
1126811277
-> Location.raise_errorf
@@ -16199,9 +16208,9 @@ let generic_to_uncurry_exp kind loc (self : Bs_ast_mapper.mapper) pat body
1619916208
match Ast_attributes.process_attributes_rev body.pexp_attributes with
1620016209
| Nothing, _ ->
1620116210
begin match body.pexp_desc with
16202-
| Pexp_fun (label,_, arg, body)
16211+
| Pexp_fun (arg_label,_, arg, body)
1620316212
->
16204-
if label <> "" then
16213+
if not (Ast_compatible.is_arg_label_simple arg_label) then
1620516214
Bs_syntaxerr.err loc Label_in_uncurried_bs_attribute;
1620616215
aux (self.pat self arg :: acc) body
1620716216
| _ -> self.expr self body, acc
@@ -16446,8 +16455,10 @@ let ocaml_obj_as_js_object
1644616455
->
1644716456
begin match e.pexp_desc with
1644816457
| Pexp_poly
16449-
(({pexp_desc = Pexp_fun ("", None, pat, e)} ),
16450-
None) ->
16458+
(({pexp_desc = Pexp_fun (arg_label, _, pat, e)} ),
16459+
None)
16460+
when Ast_compatible.is_arg_label_simple arg_label
16461+
->
1645116462
let arity = Ast_pat.arity_of_fun pat e in
1645216463
let method_type =
1645316464
generate_arg_type x.pcf_loc mapper label.txt arity in
@@ -16508,8 +16519,10 @@ let ocaml_obj_as_js_object
1650816519
->
1650916520
begin match e.pexp_desc with
1651016521
| Pexp_poly
16511-
(({pexp_desc = Pexp_fun ("", None, pat, e)} as f),
16512-
None) ->
16522+
(({pexp_desc = Pexp_fun (arg_label, None, pat, e)} as f),
16523+
None)
16524+
when Ast_compatible.is_arg_label_simple arg_label
16525+
->
1651316526
let arity = Ast_pat.arity_of_fun pat e in
1651416527
let alias_type =
1651516528
if aliased then None
@@ -18704,7 +18717,8 @@ let rec unroll_function_aux
1870418717
(body : Parsetree.expression) : string list * string =
1870518718
match body.pexp_desc with
1870618719
| Pexp_constant(Const_string(block,_)) -> acc, block
18707-
| Pexp_fun("",None,{ppat_desc = Ppat_var s},cont) ->
18720+
| Pexp_fun(arg_label,_,{ppat_desc = Ppat_var s},cont)
18721+
when Ast_compatible.is_arg_label_simple arg_label ->
1870818722
unroll_function_aux (s.txt::acc) cont
1870918723
| _ ->
1871018724
Location.raise_errorf ~loc:body.pexp_loc
@@ -18729,7 +18743,9 @@ let handle_extension record_as_js_object e (self : Bs_ast_mapper.mapper)
1872918743
begin match txt with
1873018744
| "bs.raw" | "raw" ->
1873118745
begin match payload with
18732-
| PStr [{pstr_desc = Pstr_eval({pexp_desc = Pexp_fun("",None,pat,body)},_)}]
18746+
| PStr [
18747+
{pstr_desc = Pstr_eval({pexp_desc = Pexp_fun(arg_label,_,pat,body)},_)}]
18748+
when Ast_compatible.is_arg_label_simple arg_label
1873318749
->
1873418750
begin match pat.ppat_desc, body.pexp_desc with
1873518751
| Ppat_construct ({txt = Lident "()"}, None), Pexp_constant(Const_string(block,_))
@@ -20536,7 +20552,8 @@ let rec unsafe_mapper : Bs_ast_mapper.mapper =
2053620552
| `Exn, pexp_attributes ->
2053720553
Ast_util.convertBsErrorFunction loc self pexp_attributes cases
2053820554
end
20539-
| Pexp_fun ("", None, pat , body)
20555+
| Pexp_fun (arg_label, _, pat , body)
20556+
when Ast_compatible.is_arg_label_simple arg_label
2054020557
->
2054120558
begin match Ast_attributes.process_attributes_rev e.pexp_attributes with
2054220559
| Nothing, _

0 commit comments

Comments
 (0)
Please sign in to comment.