Skip to content

Commit 83ba6a5

Browse files
committed
Clean up: remove "(u)" encoding for uncurried unariy application.
1 parent 0915cbc commit 83ba6a5

File tree

12 files changed

+66
-121
lines changed

12 files changed

+66
-121
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
@@ -55776,8 +55776,7 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
5577655776
printConstant ~templateLiteral:(ParsetreeViewer.isTemplateLiteral e) c
5577755777
| Pexp_construct _ when ParsetreeViewer.hasJsxAttribute e.pexp_attributes ->
5577855778
printJsxFragment ~state e cmtTbl
55779-
| Pexp_construct ({txt = Longident.Lident ("()" | "(u)")}, _) ->
55780-
Doc.text "()"
55779+
| Pexp_construct ({txt = Longident.Lident "()"}, _) -> Doc.text "()"
5578155780
| Pexp_construct ({txt = Longident.Lident "[]"}, _) ->
5578255781
Doc.concat
5578355782
[Doc.text "list{"; printCommentsInside cmtTbl e.pexp_loc; Doc.rbrace]
@@ -57601,7 +57600,7 @@ and printArguments ~state ~dotted
5760157600
| [
5760257601
( Nolabel,
5760357602
{
57604-
pexp_desc = Pexp_construct ({txt = Longident.Lident ("()" | "(u)")}, _);
57603+
pexp_desc = Pexp_construct ({txt = Longident.Lident "()"}, _);
5760557604
pexp_loc = loc;
5760657605
} );
5760757606
] -> (
@@ -148393,6 +148392,7 @@ module Ast_uncurry_apply : sig
148393148392
(* TODO: the interface is not reusable, it depends on too much context *)
148394148393

148395148394
val uncurry_fn_apply :
148395+
arity0:bool ->
148396148396
Location.t ->
148397148397
Bs_ast_mapper.mapper ->
148398148398
Parsetree.expression ->
@@ -148466,8 +148466,9 @@ let opaque_full_apply ~loc (e : exp) : Parsetree.expression_desc =
148466148466
[ (Nolabel, e) ],
148467148467
Typ.any ~loc () )
148468148468

148469-
let generic_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148470-
(args : Ast_compatible.args) (cb : loc -> exp -> exp) =
148469+
let generic_apply ~arity0 loc (self : Bs_ast_mapper.mapper)
148470+
(obj : Parsetree.expression) (args : Ast_compatible.args)
148471+
(cb : loc -> exp -> exp) =
148471148472
let obj = self.expr self obj in
148472148473
let args =
148473148474
Ext_list.map args (fun (lbl, e) ->
@@ -148479,20 +148480,9 @@ let generic_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148479148480
match args with
148480148481
| [
148481148482
(Nolabel, { pexp_desc = Pexp_construct ({ txt = Lident "()" }, None) });
148482-
] ->
148483+
]
148484+
when arity0 ->
148483148485
[]
148484-
| [
148485-
( Nolabel,
148486-
({ pexp_desc = Pexp_construct (({ txt = Lident "(u)" } as lid), None) }
148487-
as e) );
148488-
] ->
148489-
[
148490-
( Asttypes.Nolabel,
148491-
{
148492-
e with
148493-
pexp_desc = Pexp_construct ({ lid with txt = Lident "()" }, None);
148494-
} );
148495-
]
148496148486
| _ -> args
148497148487
in
148498148488
let arity = List.length args in
@@ -148562,11 +148552,11 @@ let method_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148562148552
])
148563148553
args)
148564148554

148565-
let uncurry_fn_apply loc self fn args =
148566-
generic_apply loc self fn args (fun _ obj -> obj)
148555+
let uncurry_fn_apply ~arity0 loc self fn args =
148556+
generic_apply ~arity0 loc self fn args (fun _ obj -> obj)
148567148557

148568148558
let property_apply loc self obj name args =
148569-
generic_apply loc self obj args (fun loc obj ->
148559+
generic_apply ~arity0:true loc self obj args (fun loc obj ->
148570148560
Exp.send ~loc obj { txt = name; loc })
148571148561

148572148562
end
@@ -150468,7 +150458,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150468150458
fn1.pexp_attributes;
150469150459
{
150470150460
pexp_desc =
150471-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn1
150461+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op="|.") e.pexp_loc self fn1
150472150462
((Nolabel, a) :: args);
150473150463
pexp_loc = e.pexp_loc;
150474150464
pexp_attributes = e.pexp_attributes @ other_attributes;
@@ -150478,7 +150468,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150478150468
Uncurried unary application *)
150479150469
{
150480150470
pexp_desc =
150481-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self f
150471+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false e.pexp_loc self f
150482150472
[ (Nolabel, a) ];
150483150473
pexp_loc = e.pexp_loc;
150484150474
pexp_attributes = e.pexp_attributes;
@@ -150583,7 +150573,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150583150573
{
150584150574
e with
150585150575
pexp_desc =
150586-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn args;
150576+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc self fn args;
150587150577
pexp_attributes;
150588150578
}))
150589150579

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -55776,8 +55776,7 @@ and printExpression ~state (e : Parsetree.expression) cmtTbl =
5577655776
printConstant ~templateLiteral:(ParsetreeViewer.isTemplateLiteral e) c
5577755777
| Pexp_construct _ when ParsetreeViewer.hasJsxAttribute e.pexp_attributes ->
5577855778
printJsxFragment ~state e cmtTbl
55779-
| Pexp_construct ({txt = Longident.Lident ("()" | "(u)")}, _) ->
55780-
Doc.text "()"
55779+
| Pexp_construct ({txt = Longident.Lident "()"}, _) -> Doc.text "()"
5578155780
| Pexp_construct ({txt = Longident.Lident "[]"}, _) ->
5578255781
Doc.concat
5578355782
[Doc.text "list{"; printCommentsInside cmtTbl e.pexp_loc; Doc.rbrace]
@@ -57601,7 +57600,7 @@ and printArguments ~state ~dotted
5760157600
| [
5760257601
( Nolabel,
5760357602
{
57604-
pexp_desc = Pexp_construct ({txt = Longident.Lident ("()" | "(u)")}, _);
57603+
pexp_desc = Pexp_construct ({txt = Longident.Lident "()"}, _);
5760557604
pexp_loc = loc;
5760657605
} );
5760757606
] -> (
@@ -148393,6 +148392,7 @@ module Ast_uncurry_apply : sig
148393148392
(* TODO: the interface is not reusable, it depends on too much context *)
148394148393

148395148394
val uncurry_fn_apply :
148395+
arity0:bool ->
148396148396
Location.t ->
148397148397
Bs_ast_mapper.mapper ->
148398148398
Parsetree.expression ->
@@ -148466,8 +148466,9 @@ let opaque_full_apply ~loc (e : exp) : Parsetree.expression_desc =
148466148466
[ (Nolabel, e) ],
148467148467
Typ.any ~loc () )
148468148468

148469-
let generic_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148470-
(args : Ast_compatible.args) (cb : loc -> exp -> exp) =
148469+
let generic_apply ~arity0 loc (self : Bs_ast_mapper.mapper)
148470+
(obj : Parsetree.expression) (args : Ast_compatible.args)
148471+
(cb : loc -> exp -> exp) =
148471148472
let obj = self.expr self obj in
148472148473
let args =
148473148474
Ext_list.map args (fun (lbl, e) ->
@@ -148479,20 +148480,9 @@ let generic_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148479148480
match args with
148480148481
| [
148481148482
(Nolabel, { pexp_desc = Pexp_construct ({ txt = Lident "()" }, None) });
148482-
] ->
148483+
]
148484+
when arity0 ->
148483148485
[]
148484-
| [
148485-
( Nolabel,
148486-
({ pexp_desc = Pexp_construct (({ txt = Lident "(u)" } as lid), None) }
148487-
as e) );
148488-
] ->
148489-
[
148490-
( Asttypes.Nolabel,
148491-
{
148492-
e with
148493-
pexp_desc = Pexp_construct ({ lid with txt = Lident "()" }, None);
148494-
} );
148495-
]
148496148486
| _ -> args
148497148487
in
148498148488
let arity = List.length args in
@@ -148562,11 +148552,11 @@ let method_apply loc (self : Bs_ast_mapper.mapper) (obj : Parsetree.expression)
148562148552
])
148563148553
args)
148564148554

148565-
let uncurry_fn_apply loc self fn args =
148566-
generic_apply loc self fn args (fun _ obj -> obj)
148555+
let uncurry_fn_apply ~arity0 loc self fn args =
148556+
generic_apply ~arity0 loc self fn args (fun _ obj -> obj)
148567148557

148568148558
let property_apply loc self obj name args =
148569-
generic_apply loc self obj args (fun loc obj ->
148559+
generic_apply ~arity0:true loc self obj args (fun loc obj ->
148570148560
Exp.send ~loc obj { txt = name; loc })
148571148561

148572148562
end
@@ -150468,7 +150458,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150468150458
fn1.pexp_attributes;
150469150459
{
150470150460
pexp_desc =
150471-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn1
150461+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:(op="|.") e.pexp_loc self fn1
150472150462
((Nolabel, a) :: args);
150473150463
pexp_loc = e.pexp_loc;
150474150464
pexp_attributes = e.pexp_attributes @ other_attributes;
@@ -150478,7 +150468,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150478150468
Uncurried unary application *)
150479150469
{
150480150470
pexp_desc =
150481-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self f
150471+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:false e.pexp_loc self f
150482150472
[ (Nolabel, a) ];
150483150473
pexp_loc = e.pexp_loc;
150484150474
pexp_attributes = e.pexp_attributes;
@@ -150583,7 +150573,7 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150583150573
{
150584150574
e with
150585150575
pexp_desc =
150586-
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn args;
150576+
Ast_uncurry_apply.uncurry_fn_apply ~arity0:true e.pexp_loc self fn args;
150587150577
pexp_attributes;
150588150578
}))
150589150579

@@ -165897,9 +165887,7 @@ and parseArgument p : argument option =
165897165887
| Rparen ->
165898165888
let unitExpr =
165899165889
Ast_helper.Exp.construct
165900-
(Location.mknoloc
165901-
(Longident.Lident
165902-
(if p.uncurried_by_default then "()" else "(u)")))
165890+
(Location.mknoloc (Longident.Lident "()"))
165903165891
None
165904165892
in
165905165893
Some {dotted; label = Asttypes.Nolabel; expr = unitExpr}
@@ -165992,10 +165980,7 @@ and parseCallExpr p funExpr =
165992165980
label = Nolabel;
165993165981
expr =
165994165982
Ast_helper.Exp.construct ~loc
165995-
(Location.mkloc
165996-
(Longident.Lident
165997-
(if p.uncurried_by_default then "(u)" else "()"))
165998-
loc)
165983+
(Location.mkloc (Longident.Lident "()") loc)
165999165984
None;
166000165985
};
166001165986
]

0 commit comments

Comments
 (0)