Skip to content

Commit a233b08

Browse files
authored
Fix issue where uncurried was not supported with pipe (#5803)
* Refactor: renaming in pipe ppx. * Fix issue where uncurried was not supported with pipe * Update CHANGELOG.md
1 parent 39bceb6 commit a233b08

File tree

8 files changed

+206
-57
lines changed

8 files changed

+206
-57
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
Also, `(. int) => string => bool` is not equivalen to `(. int, string) => bool` anymore.
3030
These are only breaking changes for unformatted code.
3131

32+
#### :bug: Bug Fix
33+
34+
- Fix issue where uncurried was not supported with pipe https://github.com/rescript-lang/rescript-compiler/pull/5803
35+
3236
#### :nail_care: Polish
3337

3438
- Syntax: process uncurried types explicitly in the parser/printer https://github.com/rescript-lang/rescript-compiler/pull/5784

jscomp/frontend/ast_exp_apply.ml

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -95,39 +95,39 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
9595
Location.raise_errorf ~loc "%s expect f%sproperty arg0 arg2 form" op op
9696
| None -> (
9797
match view_as_app e infix_ops with
98-
| Some { op = "|."; args = [ obj_arg; fn ]; loc } -> (
98+
| Some { op = "|."; args = [ a_; f_ ]; loc } -> (
9999
(*
100100
a |. f
101101
a |. f b c [@bs] --> f a b c [@bs]
102102
a |. (g |. b)
103103
a |. `Variant
104104
a |. (b |. f c [@bs])
105105
*)
106-
let new_obj_arg = self.expr self obj_arg in
107-
let fn = self.expr self fn in
108-
match fn.pexp_desc with
106+
let a = self.expr self a_ in
107+
let f = self.expr self f_ in
108+
match f.pexp_desc with
109109
| Pexp_variant (label, None) ->
110110
{
111-
fn with
112-
pexp_desc = Pexp_variant (label, Some new_obj_arg);
111+
f with
112+
pexp_desc = Pexp_variant (label, Some a);
113113
pexp_loc = e.pexp_loc;
114114
}
115115
| Pexp_construct (ctor, None) ->
116116
{
117-
fn with
118-
pexp_desc = Pexp_construct (ctor, Some new_obj_arg);
117+
f with
118+
pexp_desc = Pexp_construct (ctor, Some a);
119119
pexp_loc = e.pexp_loc;
120120
}
121121
| Pexp_apply (fn1, args) ->
122122
Bs_ast_invariant.warn_discarded_unused_attributes
123123
fn1.pexp_attributes;
124124
{
125-
pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args);
125+
pexp_desc = Pexp_apply (fn1, (Nolabel, a) :: args);
126126
pexp_loc = e.pexp_loc;
127127
pexp_attributes = e.pexp_attributes;
128128
}
129129
| Pexp_tuple xs ->
130-
bound new_obj_arg (fun bounded_obj_arg ->
130+
bound a (fun bounded_obj_arg ->
131131
{
132132
pexp_desc =
133133
Pexp_tuple
@@ -153,11 +153,32 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
153153
| _ ->
154154
Ast_compatible.app1 ~loc:fn.pexp_loc fn
155155
bounded_obj_arg));
156-
pexp_attributes = fn.pexp_attributes;
157-
pexp_loc = fn.pexp_loc;
156+
pexp_attributes = f.pexp_attributes;
157+
pexp_loc = f.pexp_loc;
158158
})
159-
| _ ->
160-
Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes fn new_obj_arg)
159+
| _ -> (
160+
match
161+
( Ext_list.exclude_with_val f_.pexp_attributes
162+
Ast_attributes.is_bs,
163+
f_.pexp_desc )
164+
with
165+
| Some other_attributes, Pexp_apply (fn1, args) ->
166+
(* a |. f b c [@bs]
167+
Cannot process uncurried application early as the arity is wip *)
168+
let fn1 = self.expr self fn1 in
169+
let args =
170+
args |> List.map (fun (l, e) -> (l, self.expr self e))
171+
in
172+
Bs_ast_invariant.warn_discarded_unused_attributes
173+
fn1.pexp_attributes;
174+
{
175+
pexp_desc =
176+
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn1
177+
((Nolabel, a) :: args);
178+
pexp_loc = e.pexp_loc;
179+
pexp_attributes = e.pexp_attributes @ other_attributes;
180+
}
181+
| _ -> Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes f a))
161182
| Some { op = "##"; loc; args = [ obj; rest ] } -> (
162183
(* - obj##property
163184
- obj#(method a b )

jscomp/test/build.ninja

Lines changed: 2 additions & 1 deletion
Large diffs are not rendered by default.

jscomp/test/uncurried_pipe.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
3+
4+
function add(x, y) {
5+
return x + y | 0;
6+
}
7+
8+
function addC(x, y) {
9+
return x + y | 0;
10+
}
11+
12+
var v7 = add(3, 4);
13+
14+
var v17 = add(10, add(3, 4));
15+
16+
var v27 = add(20, 7);
17+
18+
var v37 = 30 + add(3, 4) | 0;
19+
20+
var StandardNotation = {
21+
add: add,
22+
addC: addC,
23+
v7: v7,
24+
v17: v17,
25+
v27: v27,
26+
v37: v37
27+
};
28+
29+
var v7$1 = add(3, 4);
30+
31+
var v17$1 = add(10, add(3, 4));
32+
33+
var v27$1 = add(20, 7);
34+
35+
var v37$1 = 30 + add(3, 4) | 0;
36+
37+
exports.StandardNotation = StandardNotation;
38+
exports.v7 = v7$1;
39+
exports.v17 = v17$1;
40+
exports.v27 = v27$1;
41+
exports.v37 = v37$1;
42+
/* v7 Not a pure module */

jscomp/test/uncurried_pipe.res

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module StandardNotation = {
2+
let add = (. x, y) => x + y
3+
let addC = (x, y) => x + y
4+
5+
let v7 = 3->add(. 4)
6+
let v17 = 10->add(. 3->add(. 4))
7+
let v27 = 20->add(. 3->addC(4))
8+
let v37 = 30->addC(3->add(. 4))
9+
}
10+
11+
@@uncurried
12+
13+
open StandardNotation
14+
15+
let v7 = 3->add(4)
16+
let v17 = 10->add(3->add(4))
17+
let v27 = 20->add(3->addC(. 4))
18+
let v37 = 30->addC(. 3->add(4))

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150328,39 +150328,39 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150328150328
Location.raise_errorf ~loc "%s expect f%sproperty arg0 arg2 form" op op
150329150329
| None -> (
150330150330
match view_as_app e infix_ops with
150331-
| Some { op = "|."; args = [ obj_arg; fn ]; loc } -> (
150331+
| Some { op = "|."; args = [ a_; f_ ]; loc } -> (
150332150332
(*
150333150333
a |. f
150334150334
a |. f b c [@bs] --> f a b c [@bs]
150335150335
a |. (g |. b)
150336150336
a |. `Variant
150337150337
a |. (b |. f c [@bs])
150338150338
*)
150339-
let new_obj_arg = self.expr self obj_arg in
150340-
let fn = self.expr self fn in
150341-
match fn.pexp_desc with
150339+
let a = self.expr self a_ in
150340+
let f = self.expr self f_ in
150341+
match f.pexp_desc with
150342150342
| Pexp_variant (label, None) ->
150343150343
{
150344-
fn with
150345-
pexp_desc = Pexp_variant (label, Some new_obj_arg);
150344+
f with
150345+
pexp_desc = Pexp_variant (label, Some a);
150346150346
pexp_loc = e.pexp_loc;
150347150347
}
150348150348
| Pexp_construct (ctor, None) ->
150349150349
{
150350-
fn with
150351-
pexp_desc = Pexp_construct (ctor, Some new_obj_arg);
150350+
f with
150351+
pexp_desc = Pexp_construct (ctor, Some a);
150352150352
pexp_loc = e.pexp_loc;
150353150353
}
150354150354
| Pexp_apply (fn1, args) ->
150355150355
Bs_ast_invariant.warn_discarded_unused_attributes
150356150356
fn1.pexp_attributes;
150357150357
{
150358-
pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args);
150358+
pexp_desc = Pexp_apply (fn1, (Nolabel, a) :: args);
150359150359
pexp_loc = e.pexp_loc;
150360150360
pexp_attributes = e.pexp_attributes;
150361150361
}
150362150362
| Pexp_tuple xs ->
150363-
bound new_obj_arg (fun bounded_obj_arg ->
150363+
bound a (fun bounded_obj_arg ->
150364150364
{
150365150365
pexp_desc =
150366150366
Pexp_tuple
@@ -150386,11 +150386,32 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150386150386
| _ ->
150387150387
Ast_compatible.app1 ~loc:fn.pexp_loc fn
150388150388
bounded_obj_arg));
150389-
pexp_attributes = fn.pexp_attributes;
150390-
pexp_loc = fn.pexp_loc;
150389+
pexp_attributes = f.pexp_attributes;
150390+
pexp_loc = f.pexp_loc;
150391150391
})
150392-
| _ ->
150393-
Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes fn new_obj_arg)
150392+
| _ -> (
150393+
match
150394+
( Ext_list.exclude_with_val f_.pexp_attributes
150395+
Ast_attributes.is_bs,
150396+
f_.pexp_desc )
150397+
with
150398+
| Some other_attributes, Pexp_apply (fn1, args) ->
150399+
(* a |. f b c [@bs]
150400+
Cannot process uncurried application early as the arity is wip *)
150401+
let fn1 = self.expr self fn1 in
150402+
let args =
150403+
args |> List.map (fun (l, e) -> (l, self.expr self e))
150404+
in
150405+
Bs_ast_invariant.warn_discarded_unused_attributes
150406+
fn1.pexp_attributes;
150407+
{
150408+
pexp_desc =
150409+
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn1
150410+
((Nolabel, a) :: args);
150411+
pexp_loc = e.pexp_loc;
150412+
pexp_attributes = e.pexp_attributes @ other_attributes;
150413+
}
150414+
| _ -> Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes f a))
150394150415
| Some { op = "##"; loc; args = [ obj; rest ] } -> (
150395150416
(* - obj##property
150396150417
- obj#(method a b )

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -150328,39 +150328,39 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150328150328
Location.raise_errorf ~loc "%s expect f%sproperty arg0 arg2 form" op op
150329150329
| None -> (
150330150330
match view_as_app e infix_ops with
150331-
| Some { op = "|."; args = [ obj_arg; fn ]; loc } -> (
150331+
| Some { op = "|."; args = [ a_; f_ ]; loc } -> (
150332150332
(*
150333150333
a |. f
150334150334
a |. f b c [@bs] --> f a b c [@bs]
150335150335
a |. (g |. b)
150336150336
a |. `Variant
150337150337
a |. (b |. f c [@bs])
150338150338
*)
150339-
let new_obj_arg = self.expr self obj_arg in
150340-
let fn = self.expr self fn in
150341-
match fn.pexp_desc with
150339+
let a = self.expr self a_ in
150340+
let f = self.expr self f_ in
150341+
match f.pexp_desc with
150342150342
| Pexp_variant (label, None) ->
150343150343
{
150344-
fn with
150345-
pexp_desc = Pexp_variant (label, Some new_obj_arg);
150344+
f with
150345+
pexp_desc = Pexp_variant (label, Some a);
150346150346
pexp_loc = e.pexp_loc;
150347150347
}
150348150348
| Pexp_construct (ctor, None) ->
150349150349
{
150350-
fn with
150351-
pexp_desc = Pexp_construct (ctor, Some new_obj_arg);
150350+
f with
150351+
pexp_desc = Pexp_construct (ctor, Some a);
150352150352
pexp_loc = e.pexp_loc;
150353150353
}
150354150354
| Pexp_apply (fn1, args) ->
150355150355
Bs_ast_invariant.warn_discarded_unused_attributes
150356150356
fn1.pexp_attributes;
150357150357
{
150358-
pexp_desc = Pexp_apply (fn1, (Nolabel, new_obj_arg) :: args);
150358+
pexp_desc = Pexp_apply (fn1, (Nolabel, a) :: args);
150359150359
pexp_loc = e.pexp_loc;
150360150360
pexp_attributes = e.pexp_attributes;
150361150361
}
150362150362
| Pexp_tuple xs ->
150363-
bound new_obj_arg (fun bounded_obj_arg ->
150363+
bound a (fun bounded_obj_arg ->
150364150364
{
150365150365
pexp_desc =
150366150366
Pexp_tuple
@@ -150386,11 +150386,32 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
150386150386
| _ ->
150387150387
Ast_compatible.app1 ~loc:fn.pexp_loc fn
150388150388
bounded_obj_arg));
150389-
pexp_attributes = fn.pexp_attributes;
150390-
pexp_loc = fn.pexp_loc;
150389+
pexp_attributes = f.pexp_attributes;
150390+
pexp_loc = f.pexp_loc;
150391150391
})
150392-
| _ ->
150393-
Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes fn new_obj_arg)
150392+
| _ -> (
150393+
match
150394+
( Ext_list.exclude_with_val f_.pexp_attributes
150395+
Ast_attributes.is_bs,
150396+
f_.pexp_desc )
150397+
with
150398+
| Some other_attributes, Pexp_apply (fn1, args) ->
150399+
(* a |. f b c [@bs]
150400+
Cannot process uncurried application early as the arity is wip *)
150401+
let fn1 = self.expr self fn1 in
150402+
let args =
150403+
args |> List.map (fun (l, e) -> (l, self.expr self e))
150404+
in
150405+
Bs_ast_invariant.warn_discarded_unused_attributes
150406+
fn1.pexp_attributes;
150407+
{
150408+
pexp_desc =
150409+
Ast_uncurry_apply.uncurry_fn_apply e.pexp_loc self fn1
150410+
((Nolabel, a) :: args);
150411+
pexp_loc = e.pexp_loc;
150412+
pexp_attributes = e.pexp_attributes @ other_attributes;
150413+
}
150414+
| _ -> Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes f a))
150394150415
| Some { op = "##"; loc; args = [ obj; rest ] } -> (
150395150416
(* - obj##property
150396150417
- obj#(method a b )

0 commit comments

Comments
 (0)