Skip to content

Commit 89f91a6

Browse files
committed
Cleanup: remove tracking of uncurried state in parser/printer.
1 parent 1a9c2e3 commit 89f91a6

File tree

10 files changed

+51
-169
lines changed

10 files changed

+51
-169
lines changed

jscomp/ext/config.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ let bs_only = ref true
1111

1212
let unsafe_empty_array = ref false
1313

14-
type uncurried = Legacy | Uncurried
15-
1614
let cmi_magic_number = "Caml1999I022"
1715

1816
and ast_impl_magic_number = "Caml1999M022"

jscomp/ext/config.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,3 @@ val cmt_magic_number : string
4141
(* Magic number for compiled interface files *)
4242

4343
val print_config : out_channel -> unit
44-
45-
type uncurried = Legacy | Uncurried

jscomp/syntax/src/res_core.ml

Lines changed: 25 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,6 @@ type argument = {
189189
}
190190

191191
type type_parameter = {
192-
dotted: bool;
193192
attrs: Ast_helper.attrs;
194193
label: Asttypes.arg_label;
195194
typ: Parsetree.core_type;
@@ -386,8 +385,7 @@ let build_longident words =
386385

387386
let make_infix_operator (p : Parser.t) token start_pos end_pos =
388387
let stringified_token =
389-
if token = Token.MinusGreater then
390-
if p.uncurried_config = Legacy then "|." else "|.u"
388+
if token = Token.MinusGreater then "|.u"
391389
else if token = Token.PlusPlus then "^"
392390
else if token = Token.BangEqual then "<>"
393391
else if token = Token.BangEqualEqual then "!="
@@ -519,7 +517,7 @@ let wrap_type_annotation ~loc newtypes core_type body =
519517
* return a wrapping function that wraps ((__x) => ...) around an expression
520518
* e.g. foo(_, 3) becomes (__x) => foo(__x, 3)
521519
*)
522-
let process_underscore_application (p : Parser.t) args =
520+
let process_underscore_application args =
523521
let exp_question = ref None in
524522
let hidden_var = "__x" in
525523
let check_arg ((lab, exp) as arg) =
@@ -541,8 +539,7 @@ let process_underscore_application (p : Parser.t) args =
541539
~loc:Location.none
542540
in
543541
let fun_expr = Ast_helper.Exp.fun_ ~loc Nolabel None pattern exp_apply in
544-
if p.uncurried_config = Legacy then fun_expr
545-
else Ast_uncurried.uncurried_fun ~loc ~arity:1 fun_expr
542+
Ast_uncurried.uncurried_fun ~loc ~arity:1 fun_expr
546543
| None -> exp_apply
547544
in
548545
(args, wrap)
@@ -1571,53 +1568,17 @@ and parse_es6_arrow_expression ?(arrow_attrs = []) ?(arrow_start_pos = None)
15711568
| TermParameter _ -> true
15721569
| TypeParameter _ -> false)
15731570
in
1574-
let body_needs_braces =
1575-
let is_fun =
1576-
match body.pexp_desc with
1577-
| Pexp_fun _ -> true
1578-
| _ -> false
1579-
in
1580-
match term_parameters with
1581-
| TermParameter {dotted} :: _
1582-
when p.uncurried_config |> Res_uncurried.from_dotted ~dotted && is_fun ->
1583-
true
1584-
| TermParameter _ :: rest when p.uncurried_config = Legacy && is_fun ->
1585-
rest
1586-
|> List.exists (function
1587-
| TermParameter {dotted} -> dotted
1588-
| _ -> false)
1589-
| _ -> false
1590-
in
1591-
let body =
1592-
if body_needs_braces then
1593-
{
1594-
body with
1595-
pexp_attributes = make_braces_attr body.pexp_loc :: body.pexp_attributes;
1596-
}
1597-
else body
1598-
in
15991571
let _paramNum, arrow_expr, _arity =
16001572
List.fold_right
16011573
(fun parameter (term_param_num, expr, arity) ->
16021574
match parameter with
16031575
| TermParameter
1604-
{
1605-
dotted;
1606-
attrs;
1607-
label = lbl;
1608-
expr = default_expr;
1609-
pat;
1610-
pos = start_pos;
1611-
} ->
1576+
{attrs; label = lbl; expr = default_expr; pat; pos = start_pos} ->
16121577
let loc = mk_loc start_pos end_pos in
16131578
let fun_expr =
16141579
Ast_helper.Exp.fun_ ~loc ~attrs lbl default_expr pat expr
16151580
in
1616-
let uncurried =
1617-
p.uncurried_config |> Res_uncurried.from_dotted ~dotted
1618-
in
1619-
if uncurried && (term_param_num = 1 || p.uncurried_config = Legacy)
1620-
then
1581+
if term_param_num = 1 then
16211582
( term_param_num - 1,
16221583
Ast_uncurried.uncurried_fun ~loc ~arity fun_expr,
16231584
1 )
@@ -2257,10 +2218,9 @@ and parse_binary_expr ?(context = OrdinaryExpr) ?a p prec =
22572218
let loc = mk_loc a.Parsetree.pexp_loc.loc_start b.pexp_loc.loc_end in
22582219
let expr =
22592220
match (token, b.pexp_desc) with
2260-
| BarGreater, Pexp_apply (fun_expr, args)
2261-
when p.uncurried_config = Uncurried ->
2221+
| BarGreater, Pexp_apply (fun_expr, args) ->
22622222
{b with pexp_desc = Pexp_apply (fun_expr, args @ [(Nolabel, a)])}
2263-
| BarGreater, _ when p.uncurried_config = Uncurried ->
2223+
| BarGreater, _ ->
22642224
Ast_helper.Exp.apply ~loc ~attrs:[uncurried_app_attr] b [(Nolabel, a)]
22652225
| _ ->
22662226
Ast_helper.Exp.apply ~loc
@@ -3788,13 +3748,10 @@ and parse_call_expr p fun_expr =
37883748
in
37893749
let apply =
37903750
Ext_list.fold_left args fun_expr (fun call_body group ->
3791-
let dotted, args = group in
3792-
let args, wrap = process_underscore_application p args in
3751+
let _, args = group in
3752+
let args, wrap = process_underscore_application args in
37933753
let exp =
3794-
let uncurried =
3795-
p.uncurried_config |> Res_uncurried.from_dotted ~dotted
3796-
in
3797-
let attrs = if uncurried then [uncurried_app_attr] else [] in
3754+
let attrs = [uncurried_app_attr] in
37983755
let attrs = if is_partial then res_partial_attr :: attrs else attrs in
37993756
Ast_helper.Exp.apply ~loc ~attrs call_body args
38003757
in
@@ -4064,8 +4021,7 @@ and parse_poly_type_expr p =
40644021
let t_fun =
40654022
Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ return_type
40664023
in
4067-
if p.uncurried_config = Legacy then t_fun
4068-
else Ast_uncurried.uncurried_type ~loc ~arity:1 t_fun
4024+
Ast_uncurried.uncurried_type ~loc ~arity:1 t_fun
40694025
| _ -> Ast_helper.Typ.var ~loc:var.loc var.txt)
40704026
| _ -> assert false)
40714027
| _ -> parse_typ_expr p
@@ -4285,7 +4241,7 @@ and parse_type_parameter p =
42854241
|| Grammar.is_typ_expr_start p.token
42864242
then
42874243
let start_pos = p.Parser.start_pos in
4288-
let dotted = Parser.optional p Dot in
4244+
let _ = Parser.optional p Dot (* dot is ignored *) in
42894245
let attrs = doc_attr @ parse_attributes p in
42904246
match p.Parser.token with
42914247
| Tilde -> (
@@ -4303,8 +4259,8 @@ and parse_type_parameter p =
43034259
| Equal ->
43044260
Parser.next p;
43054261
Parser.expect Question p;
4306-
Some {dotted; attrs; label = Optional name; typ; start_pos}
4307-
| _ -> Some {dotted; attrs; label = Labelled name; typ; start_pos})
4262+
Some {attrs; label = Optional name; typ; start_pos}
4263+
| _ -> Some {attrs; label = Labelled name; typ; start_pos})
43084264
| Lident _ -> (
43094265
let name, loc = parse_lident p in
43104266
match p.token with
@@ -4322,8 +4278,8 @@ and parse_type_parameter p =
43224278
| Equal ->
43234279
Parser.next p;
43244280
Parser.expect Question p;
4325-
Some {dotted; attrs; label = Optional name; typ; start_pos}
4326-
| _ -> Some {dotted; attrs; label = Labelled name; typ; start_pos})
4281+
Some {attrs; label = Optional name; typ; start_pos}
4282+
| _ -> Some {attrs; label = Labelled name; typ; start_pos})
43274283
| _ ->
43284284
let constr = Location.mkloc (Longident.Lident name) loc in
43294285
let args = parse_type_constructor_args ~constr_name:constr p in
@@ -4335,20 +4291,13 @@ and parse_type_parameter p =
43354291

43364292
let typ = parse_arrow_type_rest ~es6_arrow:true ~start_pos typ p in
43374293
let typ = parse_type_alias p typ in
4338-
Some {dotted; attrs = []; label = Nolabel; typ; start_pos})
4294+
Some {attrs = []; label = Nolabel; typ; start_pos})
43394295
| _ ->
43404296
let typ = parse_typ_expr p in
43414297
let typ_with_attributes =
43424298
{typ with ptyp_attributes = List.concat [attrs; typ.ptyp_attributes]}
43434299
in
4344-
Some
4345-
{
4346-
dotted;
4347-
attrs = [];
4348-
label = Nolabel;
4349-
typ = typ_with_attributes;
4350-
start_pos;
4351-
}
4300+
Some {attrs = []; label = Nolabel; typ = typ_with_attributes; start_pos}
43524301
else None
43534302

43544303
(* (int, ~x:string, float) *)
@@ -4361,7 +4310,7 @@ and parse_type_parameters p =
43614310
let loc = mk_loc start_pos p.prev_end_pos in
43624311
let unit_constr = Location.mkloc (Longident.Lident "unit") loc in
43634312
let typ = Ast_helper.Typ.constr unit_constr [] in
4364-
[{dotted = false; attrs = []; label = Nolabel; typ; start_pos}]
4313+
[{attrs = []; label = Nolabel; typ; start_pos}]
43654314
| _ ->
43664315
let params =
43674316
parse_comma_delimited_region ~grammar:Grammar.TypeParameters
@@ -4402,23 +4351,10 @@ and parse_es6_arrow_type ~attrs p =
44024351
Parser.expect EqualGreater p;
44034352
let return_type = parse_typ_expr ~alias:false p in
44044353
let end_pos = p.prev_end_pos in
4405-
let return_type_arity =
4406-
match parameters with
4407-
| _ when p.uncurried_config <> Legacy -> 0
4408-
| _ ->
4409-
if parameters |> List.exists (function {dotted; typ = _} -> dotted)
4410-
then 0
4411-
else
4412-
let _, args, _ = Res_parsetree_viewer.arrow_type return_type in
4413-
List.length args
4414-
in
4354+
let return_type_arity = 0 in
44154355
let _paramNum, typ, _arity =
44164356
List.fold_right
4417-
(fun {dotted; attrs; label = arg_lbl; typ; start_pos}
4418-
(param_num, t, arity) ->
4419-
let uncurried =
4420-
p.uncurried_config |> Res_uncurried.from_dotted ~dotted
4421-
in
4357+
(fun {attrs; label = arg_lbl; typ; start_pos} (param_num, t, arity) ->
44224358
let loc = mk_loc start_pos end_pos in
44234359
let arity =
44244360
(* Workaround for ~lbl: @as(json`false`) _, which changes the arity *)
@@ -4437,7 +4373,7 @@ and parse_es6_arrow_type ~attrs p =
44374373
| _ -> arity
44384374
in
44394375
let t_arg = Ast_helper.Typ.arrow ~loc ~attrs arg_lbl typ t in
4440-
if uncurried && (param_num = 1 || p.uncurried_config = Legacy) then
4376+
if param_num = 1 then
44414377
(param_num - 1, Ast_uncurried.uncurried_type ~loc ~arity t_arg, 1)
44424378
else (param_num - 1, t_arg, arity + 1))
44434379
parameters
@@ -4498,8 +4434,7 @@ and parse_arrow_type_rest ~es6_arrow ~start_pos typ p =
44984434
let arrow_typ =
44994435
Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ return_type
45004436
in
4501-
if p.uncurried_config = Legacy then arrow_typ
4502-
else Ast_uncurried.uncurried_type ~loc ~arity:1 arrow_typ
4437+
Ast_uncurried.uncurried_type ~loc ~arity:1 arrow_typ
45034438
| _ -> typ
45044439

45054440
and parse_typ_expr_region p =
@@ -5112,12 +5047,10 @@ and parse_type_equation_or_constr_decl p =
51125047
let arrow_type =
51135048
Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ return_type
51145049
in
5115-
let uncurried = p.uncurried_config <> Legacy in
51165050
let arrow_type =
5117-
if uncurried then
5118-
Ast_uncurried.uncurried_type ~loc ~arity:1 arrow_type
5119-
else arrow_type
5051+
Ast_uncurried.uncurried_type ~loc ~arity:1 arrow_type
51205052
in
5053+
51215054
let typ = parse_type_alias p arrow_type in
51225055
(Some typ, Asttypes.Public, Parsetree.Ptype_abstract)
51235056
| _ -> (Some typ, Asttypes.Public, Parsetree.Ptype_abstract))
@@ -6668,13 +6601,6 @@ and parse_standalone_attribute p =
66686601
let start_pos = p.start_pos in
66696602
Parser.expect AtAt p;
66706603
let attr_id = parse_attribute_id ~start_pos p in
6671-
let attr_id =
6672-
match attr_id.txt with
6673-
| "uncurried" ->
6674-
p.uncurried_config <- Config.Uncurried;
6675-
attr_id
6676-
| _ -> attr_id
6677-
in
66786604
let payload = parse_payload p in
66796605
(attr_id, payload)
66806606

jscomp/syntax/src/res_outcome_printer.ml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ let rec print_out_type_doc (out_type : Outcometree.out_type) =
155155
( Oide_dot (Oide_dot (Oide_ident "Js", "Fn"), _),
156156
[(Otyp_arrow _ as arrow_type)] ) ->
157157
(* Compatibility with compiler up to v10.x *)
158-
print_out_arrow_type ~uncurried:true arrow_type
158+
print_out_arrow_type arrow_type
159159
| Otyp_constr (Oide_ident "function$", [(Otyp_arrow _ as arrow_type); _arity])
160160
->
161161
(* function$<(int, int) => int, [#2]> -> (. int, int) => int *)
162-
print_out_arrow_type ~uncurried:true arrow_type
162+
print_out_arrow_type arrow_type
163163
| Otyp_constr (Oide_ident "function$", [Otyp_var _; _arity]) ->
164164
(* function$<'a, arity> -> _ => _ *)
165165
print_out_type_doc (Otyp_stuff "_ => _")
@@ -234,7 +234,7 @@ let rec print_out_type_doc (out_type : Outcometree.out_type) =
234234
Doc.space;
235235
print_out_type_doc out_type;
236236
])
237-
| Otyp_arrow _ as typ -> print_out_arrow_type ~uncurried:false typ
237+
| Otyp_arrow _ as typ -> print_out_arrow_type typ
238238
| Otyp_module (mod_name, string_list, out_types) ->
239239
let package_type_doc =
240240
match (string_list, out_types) with
@@ -266,8 +266,7 @@ let rec print_out_type_doc (out_type : Outcometree.out_type) =
266266
Doc.rparen;
267267
]
268268

269-
and print_out_arrow_type ~uncurried typ =
270-
let uncurried = Res_uncurried.get_dotted ~uncurried Uncurried in
269+
and print_out_arrow_type typ =
271270
let typ_args, typ = collect_arrow_args typ [] in
272271
let args =
273272
Doc.join
@@ -297,7 +296,6 @@ and print_out_arrow_type ~uncurried typ =
297296
let args_doc =
298297
let needs_parens =
299298
match typ_args with
300-
| _ when uncurried -> true
301299
| [
302300
( _,
303301
( Otyp_tuple _ | Otyp_arrow _
@@ -312,7 +310,7 @@ and print_out_arrow_type ~uncurried typ =
312310
Doc.group
313311
(Doc.concat
314312
[
315-
(if uncurried then Doc.text "(. " else Doc.lparen);
313+
Doc.lparen;
316314
Doc.indent (Doc.concat [Doc.soft_line; args]);
317315
Doc.trailing_comma;
318316
Doc.soft_line;

jscomp/syntax/src/res_parser.ml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ type t = {
2222
mutable diagnostics: Diagnostics.t list;
2323
mutable comments: Comment.t list;
2424
mutable regions: region_status ref list;
25-
mutable uncurried_config: Config.uncurried;
2625
}
2726

2827
let err ?start_pos ?end_pos p error =
@@ -131,7 +130,6 @@ let make ?(mode = ParseForTypeChecker) src filename =
131130
diagnostics = [];
132131
comments = [];
133132
regions = [ref Report];
134-
uncurried_config = Uncurried;
135133
}
136134
in
137135
parser_state.scanner.err <-
@@ -180,7 +178,6 @@ let lookahead p callback =
180178
let errors = p.errors in
181179
let diagnostics = p.diagnostics in
182180
let comments = p.comments in
183-
let uncurried_config = p.uncurried_config in
184181

185182
let res = callback p in
186183

@@ -199,6 +196,5 @@ let lookahead p callback =
199196
p.errors <- errors;
200197
p.diagnostics <- diagnostics;
201198
p.comments <- comments;
202-
p.uncurried_config <- uncurried_config;
203199

204200
res

jscomp/syntax/src/res_parser.mli

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ type t = {
2121
mutable diagnostics: Diagnostics.t list;
2222
mutable comments: Comment.t list;
2323
mutable regions: region_status ref list;
24-
mutable uncurried_config: Config.uncurried;
2524
}
2625

2726
val make : ?mode:mode -> string -> string -> t

jscomp/syntax/src/res_parsetree_viewer.ml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,17 +81,12 @@ let process_partial_app_attribute attrs =
8181
in
8282
process false [] attrs
8383

84-
type function_attributes_info = {
85-
async: bool;
86-
bs: bool;
87-
attributes: Parsetree.attributes;
88-
}
84+
type function_attributes_info = {async: bool; attributes: Parsetree.attributes}
8985

9086
let process_function_attributes attrs =
9187
let rec process async bs acc attrs =
9288
match attrs with
93-
| [] -> {async; bs; attributes = List.rev acc}
94-
| ({Location.txt = "bs"}, _) :: rest -> process async true acc rest
89+
| [] -> {async; attributes = List.rev acc}
9590
| ({Location.txt = "res.async"}, _) :: rest -> process true bs acc rest
9691
| attr :: rest -> process async bs (attr :: acc) rest
9792
in

0 commit comments

Comments
 (0)