Skip to content

Commit e981756

Browse files
committed
Clean up: remove "(u)" encoding for uncurried unariy application.
1 parent 34c509a commit e981756

File tree

11 files changed

+65
-120
lines changed

11 files changed

+65
-120
lines changed

jscomp/frontend/ast_exp_apply.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
173173
fn1.pexp_attributes;
174174
{
175175
pexp_desc =
176-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn1
176+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op="|.") e.pexp_loc self fn1
177177
((Nolabel, a) :: args);
178178
pexp_loc = e.pexp_loc;
179179
pexp_attributes = e.pexp_attributes @ other_attributes;
@@ -183,7 +183,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
183183
Uncurried unary application *)
184184
{
185185
pexp_desc =
186-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self f
186+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false e.pexp_loc self f
187187
[ (Nolabel, a) ];
188188
pexp_loc = e.pexp_loc;
189189
pexp_attributes = e.pexp_attributes;
@@ -288,6 +288,6 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
288288
{
289289
e with
290290
pexp_desc =
291-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn args;
291+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc self fn args;
292292
pexp_attributes;
293293
}))

jscomp/frontend/ast_uncurry_apply.ml

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,9 @@ let opaque_full_apply ~loc (e : exp) : Parsetree.expression_desc =
4444
[ (Nolabel, e) ],
4545
Typ.any ~loc () )
4646

47-
let generic_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
48-
(args : Ast_compatible.args) (cb : loc -> exp -> exp) =
47+
let generic_apply ~arity0 loc (self : Bs_ast_mapper.mapper)
48+
(obj : Parsetree.expression) (args : Ast_compatible.args)
49+
(cb : loc -> exp -> exp) =
4950
let obj = self.expr self obj in
5051
let args =
5152
Ext_list.map args (fun (lbl, e) ->
@@ -57,20 +58,9 @@ let generic_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
5758
match args with
5859
| [
5960
(Nolabel, { pexp_desc = Pexp_construct ({ txt = Lident "()" }, None) });
60-
] ->
61+
]
62+
when arity0 ->
6163
[]
62-
| [
63-
( Nolabel,
64-
({ pexp_desc = Pexp_construct (({ txt = Lident "(u)" } as lid), None) }
65-
as e) );
66-
] ->
67-
[
68-
( Asttypes.Nolabel,
69-
{
70-
e with
71-
pexp_desc = Pexp_construct ({ lid with txt = Lident "()" }, None);
72-
} );
73-
]
7464
| _ -> args
7565
in
7666
let arity = List.length args in
@@ -140,9 +130,9 @@ let method_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
140130
])
141131
args)
142132

143-
let uncurry_fn_apply loc self fn args =
144-
generic_apply loc self fn args (fun _ obj -> obj)
133+
let uncurry_fn_apply ~arity0 loc self fn args =
134+
generic_apply ~arity0 loc self fn args (fun _ obj -> obj)
145135

146136
let property_apply loc self obj name args =
147-
generic_apply loc self obj args (fun loc obj ->
137+
generic_apply ~arity0:true loc self obj args (fun loc obj ->
148138
Exp.send ~loc obj { txt = name; loc })

jscomp/frontend/ast_uncurry_apply.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
(* TODO: the interface is not reusable, it depends on too much context *)
2626

2727
val uncurry_fn_apply :
28+
arity0:bool ->
2829
Location.t ->
2930
Bs_ast_mapper.mapper ->
3031
Parsetree.expression ->

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55791,8 +55791,7 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
5579155791
printConstant ~templateLiteral:(ParsetreeViewer.isTemplateLiteral e) c
5579255792
| Pexp_construct _ when ParsetreeViewer.hasJsxAttribute e.pexp_attributes ->
5579355793
printJsxFragment ~state e cmtTbl
55794-
| Pexp_construct ({txt = Longident.Lident ("()" | "(u)")}, _) ->
55795-
Doc.text "()"
55794+
| Pexp_construct ({txt = Longident.Lident "()"}, _) -> Doc.text "()"
5579655795
| Pexp_construct ({txt = Longident.Lident "[]"}, _) ->
5579755796
Doc.concat
5579855797
[Doc.text "list{"; printCommentsInside cmtTbl e.pexp_loc; Doc.rbrace]
@@ -57623,7 +57622,7 @@ and printArguments ~state ~dotted
5762357622
| [
5762457623
( Nolabel,
5762557624
{
57626-
pexp_desc = Pexp_construct ({txt = Longident.Lident ("()" | "(u)")}, _);
57625+
pexp_desc = Pexp_construct ({txt = Longident.Lident "()"}, _);
5762757626
pexp_loc = loc;
5762857627
} );
5762957628
] -> (
@@ -148415,6 +148414,7 @@ module Ast_uncurry_apply : sig
148415148414
(* TODO: the interface is not reusable, it depends on too much context *)
148416148415

148417148416
val uncurry_fn_apply :
148417+
arity0:bool ->
148418148418
Location.t ->
148419148419
Bs_ast_mapper.mapper ->
148420148420
Parsetree.expression ->
@@ -148488,8 +148488,9 @@ let opaque_full_apply ~loc (e : exp) : Parsetree.expression_desc =
148488148488
[ (Nolabel, e) ],
148489148489
Typ.any ~loc () )
148490148490

148491-
let generic_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148492-
(args : Ast_compatible.args) (cb : loc -> exp -> exp) =
148491+
let generic_apply ~arity0 loc (self : Bs_ast_mapper.mapper)
148492+
(obj : Parsetree.expression) (args : Ast_compatible.args)
148493+
(cb : loc -> exp -> exp) =
148493148494
let obj = self.expr self obj in
148494148495
let args =
148495148496
Ext_list.map args (fun (lbl, e) ->
@@ -148501,20 +148502,9 @@ let generic_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148501148502
match args with
148502148503
| [
148503148504
(Nolabel, { pexp_desc = Pexp_construct ({ txt = Lident "()" }, None) });
148504-
] ->
148505+
]
148506+
when arity0 ->
148505148507
[]
148506-
| [
148507-
( Nolabel,
148508-
({ pexp_desc = Pexp_construct (({ txt = Lident "(u)" } as lid), None) }
148509-
as e) );
148510-
] ->
148511-
[
148512-
( Asttypes.Nolabel,
148513-
{
148514-
e with
148515-
pexp_desc = Pexp_construct ({ lid with txt = Lident "()" }, None);
148516-
} );
148517-
]
148518148508
| _ -> args
148519148509
in
148520148510
let arity = List.length args in
@@ -148584,11 +148574,11 @@ let method_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148584148574
])
148585148575
args)
148586148576

148587-
let uncurry_fn_apply loc self fn args =
148588-
generic_apply loc self fn args (fun _ obj -> obj)
148577+
let uncurry_fn_apply ~arity0 loc self fn args =
148578+
generic_apply ~arity0 loc self fn args (fun _ obj -> obj)
148589148579

148590148580
let property_apply loc self obj name args =
148591-
generic_apply loc self obj args (fun loc obj ->
148581+
generic_apply ~arity0:true loc self obj args (fun loc obj ->
148592148582
Exp.send ~loc obj { txt = name; loc })
148593148583

148594148584
end
@@ -150490,7 +150480,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150490150480
fn1.pexp_attributes;
150491150481
{
150492150482
pexp_desc =
150493-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn1
150483+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op="|.") e.pexp_loc self fn1
150494150484
((Nolabel, a) :: args);
150495150485
pexp_loc = e.pexp_loc;
150496150486
pexp_attributes = e.pexp_attributes @ other_attributes;
@@ -150500,7 +150490,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150500150490
Uncurried unary application *)
150501150491
{
150502150492
pexp_desc =
150503-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self f
150493+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false e.pexp_loc self f
150504150494
[ (Nolabel, a) ];
150505150495
pexp_loc = e.pexp_loc;
150506150496
pexp_attributes = e.pexp_attributes;
@@ -150605,7 +150595,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150605150595
{
150606150596
e with
150607150597
pexp_desc =
150608-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn args;
150598+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc self fn args;
150609150599
pexp_attributes;
150610150600
}))
150611150601

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55791,8 +55791,7 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
5579155791
printConstant ~templateLiteral:(ParsetreeViewer.isTemplateLiteral e) c
5579255792
| Pexp_construct _ when ParsetreeViewer.hasJsxAttribute e.pexp_attributes ->
5579355793
printJsxFragment ~state e cmtTbl
55794-
| Pexp_construct ({txt = Longident.Lident ("()" | "(u)")}, _) ->
55795-
Doc.text "()"
55794+
| Pexp_construct ({txt = Longident.Lident "()"}, _) -> Doc.text "()"
5579655795
| Pexp_construct ({txt = Longident.Lident "[]"}, _) ->
5579755796
Doc.concat
5579855797
[Doc.text "list{"; printCommentsInside cmtTbl e.pexp_loc; Doc.rbrace]
@@ -57623,7 +57622,7 @@ and printArguments ~state ~dotted
5762357622
| [
5762457623
( Nolabel,
5762557624
{
57626-
pexp_desc = Pexp_construct ({txt = Longident.Lident ("()" | "(u)")}, _);
57625+
pexp_desc = Pexp_construct ({txt = Longident.Lident "()"}, _);
5762757626
pexp_loc = loc;
5762857627
} );
5762957628
] -> (
@@ -148415,6 +148414,7 @@ module Ast_uncurry_apply : sig
148415148414
(* TODO: the interface is not reusable, it depends on too much context *)
148416148415

148417148416
val uncurry_fn_apply :
148417+
arity0:bool ->
148418148418
Location.t ->
148419148419
Bs_ast_mapper.mapper ->
148420148420
Parsetree.expression ->
@@ -148488,8 +148488,9 @@ let opaque_full_apply ~loc (e : exp) : Parsetree.expression_desc =
148488148488
[ (Nolabel, e) ],
148489148489
Typ.any ~loc () )
148490148490

148491-
let generic_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148492-
(args : Ast_compatible.args) (cb : loc -> exp -> exp) =
148491+
let generic_apply ~arity0 loc (self : Bs_ast_mapper.mapper)
148492+
(obj : Parsetree.expression) (args : Ast_compatible.args)
148493+
(cb : loc -> exp -> exp) =
148493148494
let obj = self.expr self obj in
148494148495
let args =
148495148496
Ext_list.map args (fun (lbl, e) ->
@@ -148501,20 +148502,9 @@ let generic_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148501148502
match args with
148502148503
| [
148503148504
(Nolabel, { pexp_desc = Pexp_construct ({ txt = Lident "()" }, None) });
148504-
] ->
148505+
]
148506+
when arity0 ->
148505148507
[]
148506-
| [
148507-
( Nolabel,
148508-
({ pexp_desc = Pexp_construct (({ txt = Lident "(u)" } as lid), None) }
148509-
as e) );
148510-
] ->
148511-
[
148512-
( Asttypes.Nolabel,
148513-
{
148514-
e with
148515-
pexp_desc = Pexp_construct ({ lid with txt = Lident "()" }, None);
148516-
} );
148517-
]
148518148508
| _ -> args
148519148509
in
148520148510
let arity = List.length args in
@@ -148584,11 +148574,11 @@ let method_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148584148574
])
148585148575
args)
148586148576

148587-
let uncurry_fn_apply loc self fn args =
148588-
generic_apply loc self fn args (fun _ obj -> obj)
148577+
let uncurry_fn_apply ~arity0 loc self fn args =
148578+
generic_apply ~arity0 loc self fn args (fun _ obj -> obj)
148589148579

148590148580
let property_apply loc self obj name args =
148591-
generic_apply loc self obj args (fun loc obj ->
148581+
generic_apply ~arity0:true loc self obj args (fun loc obj ->
148592148582
Exp.send ~loc obj { txt = name; loc })
148593148583

148594148584
end
@@ -150490,7 +150480,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150490150480
fn1.pexp_attributes;
150491150481
{
150492150482
pexp_desc =
150493-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn1
150483+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op="|.") e.pexp_loc self fn1
150494150484
((Nolabel, a) :: args);
150495150485
pexp_loc = e.pexp_loc;
150496150486
pexp_attributes = e.pexp_attributes @ other_attributes;
@@ -150500,7 +150490,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150500150490
Uncurried unary application *)
150501150491
{
150502150492
pexp_desc =
150503-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self f
150493+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false e.pexp_loc self f
150504150494
[ (Nolabel, a) ];
150505150495
pexp_loc = e.pexp_loc;
150506150496
pexp_attributes = e.pexp_attributes;
@@ -150605,7 +150595,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150605150595
{
150606150596
e with
150607150597
pexp_desc =
150608-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn args;
150598+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc self fn args;
150609150599
pexp_attributes;
150610150600
}))
150611150601

@@ -165924,9 +165914,7 @@ and parseArgument p : argument option =
165924165914
| Rparen ->
165925165915
let unitExpr =
165926165916
Ast_helper.Exp.construct
165927-
(Location.mknoloc
165928-
(Longident.Lident
165929-
(if p.uncurried_by_default then "()" else "(u)")))
165917+
(Location.mknoloc (Longident.Lident "()"))
165930165918
None
165931165919
in
165932165920
Some {dotted; label = Asttypes.Nolabel; expr = unitExpr}
@@ -166019,10 +166007,7 @@ and parseCallExpr p funExpr =
166019166007
label = Nolabel;
166020166008
expr =
166021166009
Ast_helper.Exp.construct ~loc
166022-
(Location.mkloc
166023-
(Longident.Lident
166024-
(if p.uncurried_by_default then "(u)" else "()"))
166025-
loc)
166010+
(Location.mkloc (Longident.Lident "()") loc)
166026166011
None;
166027166012
};
166028166013
]

0 commit comments

Comments
 (0)