Skip to content

Commit 0acd566

Browse files
committed
Fix issue where the internal ppx for pipe -> would not use uncurried application in uncurried mode.
1 parent fd0bd7d commit 0acd566

9 files changed

+80
-67
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
- Fix issue with infinite loops with type errors on recursive types. https://github.com/rescript-lang/rescript-compiler/pull/6867
4747
- Fix issue where using partial application `...` can generate code that uses `Curry` at runtime. https://github.com/rescript-lang/rescript-compiler/pull/6872
4848
- Avoid generation of `Curry` with reverse application `|>`. https://github.com/rescript-lang/rescript-compiler/pull/6876
49+
- Fix issue where the internal ppx for pipe `->` would not use uncurried application in uncurried mode. https://github.com/rescript-lang/rescript-compiler/pull/6878
4950

5051
#### :house: Internal
5152

jscomp/frontend/ast_attributes.ml

-5
Original file line numberDiff line numberDiff line change
@@ -293,11 +293,6 @@ let locg = Location.none
293293
(* let bs : attr
294294
= {txt = "bs" ; loc = locg}, Ast_payload.empty *)
295295

296-
let is_bs (attr : attr) =
297-
match attr with
298-
| {Location.txt = "bs"; _}, _ -> true
299-
| _ -> false
300-
301296
let res_uapp : attr = ({txt = "res.uapp"; loc = locg}, Ast_payload.empty)
302297

303298
let get : attr = ({txt = "get"; loc = locg}, Ast_payload.empty)

jscomp/frontend/ast_attributes.mli

-9
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,6 @@ val iter_process_bs_string_or_int_as : t -> as_const_payload option
6060

6161
val process_derive_type : t -> derive_attr * t
6262

63-
(* val iter_process_derive_type :
64-
t -> derive_attr
65-
66-
67-
val bs : attr *)
68-
val is_bs : attr -> bool
69-
(* val is_optional : attr -> bool
70-
val is_bs_as : attr -> bool *)
71-
7263
(* Attribute for uncurried application coming from the ReScript parser *)
7364
val res_uapp : attr
7465

jscomp/frontend/ast_exp_apply.ml

+17-33
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ let rec no_need_bound (exp : exp) =
3232
| Pexp_constraint (e, _) -> no_need_bound e
3333
| _ -> false
3434

35-
let ocaml_obj_id = "__ocaml_internal_obj"
35+
let tuple_obj_id = "__tuple_internal_obj"
3636

3737
let bound (e : exp) (cb : exp -> _) =
3838
if no_need_bound e then cb e
3939
else
4040
let loc = e.pexp_loc in
4141
Exp.let_ ~loc Nonrecursive
42-
[Vb.mk ~loc (Pat.var ~loc {txt = ocaml_obj_id; loc}) e]
43-
(cb (Exp.ident ~loc {txt = Lident ocaml_obj_id; loc}))
42+
[Vb.mk ~loc (Pat.var ~loc {txt = tuple_obj_id; loc}) e]
43+
(cb (Exp.ident ~loc {txt = Lident tuple_obj_id; loc}))
4444

4545
let default_expr_mapper = Bs_ast_mapper.default_mapper.expr
4646

@@ -71,8 +71,7 @@ let view_as_app (fn : exp) (s : string list) : app_pattern option =
7171

7272
let infix_ops = ["|."; "|.u"; "#="; "##"]
7373

74-
let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
75-
(args : Ast_compatible.args) : exp =
74+
let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) : exp =
7675
match view_as_app e infix_ops with
7776
| Some {op = ("|." | "|.u") as op; args = [a_; f_]; loc} -> (
7877
(*
@@ -82,6 +81,11 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
8281
a |. `Variant
8382
a |. (b |. f c [@bs])
8483
*)
84+
let add_uncurried_attr attrs =
85+
if op = "|.u" && not (List.mem Ast_attributes.res_uapp attrs) then
86+
Ast_attributes.res_uapp :: attrs
87+
else attrs
88+
in
8589
let a = self.expr self a_ in
8690
let f = self.expr self f_ in
8791
match f.pexp_desc with
@@ -94,7 +98,8 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
9498
{
9599
pexp_desc = Pexp_apply (fn1, (Nolabel, a) :: args);
96100
pexp_loc = e.pexp_loc;
97-
pexp_attributes = e.pexp_attributes @ f.pexp_attributes;
101+
pexp_attributes =
102+
add_uncurried_attr (e.pexp_attributes @ f.pexp_attributes);
98103
}
99104
| Pexp_tuple xs ->
100105
bound a (fun bounded_obj_arg ->
@@ -114,22 +119,18 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
114119
{
115120
Parsetree.pexp_desc =
116121
Pexp_apply (fn, (Nolabel, bounded_obj_arg) :: args);
117-
pexp_attributes = [];
122+
pexp_attributes = add_uncurried_attr [];
118123
pexp_loc = fn.pexp_loc;
119124
}
120125
| _ ->
121-
Ast_compatible.app1 ~loc:fn.pexp_loc fn bounded_obj_arg));
126+
Ast_compatible.app1 ~loc:fn.pexp_loc
127+
~attrs:(add_uncurried_attr []) fn bounded_obj_arg));
122128
pexp_attributes = f.pexp_attributes;
123129
pexp_loc = f.pexp_loc;
124130
})
125131
| _ ->
126-
if op = "|.u" then
127-
(* a |.u f
128-
Uncurried unary application *)
129-
Ast_compatible.app1 ~loc
130-
~attrs:(Ast_attributes.res_uapp :: e.pexp_attributes)
131-
f a
132-
else Ast_compatible.app1 ~loc ~attrs:e.pexp_attributes f a)
132+
Ast_compatible.app1 ~loc ~attrs:(add_uncurried_attr e.pexp_attributes) f a
133+
)
133134
| Some {op = "##"; loc; args = [obj; rest]} -> (
134135
(* - obj##property
135136
- obj#(method a b )
@@ -202,21 +203,4 @@ let app_exp_mapper (e : exp) (self : Bs_ast_mapper.mapper) (fn : exp)
202203
Location.raise_errorf ~loc
203204
"Js object ## expect syntax like obj##(paint (a,b)) "
204205
| Some {op} -> Location.raise_errorf "invalid %s syntax" op
205-
| None -> (
206-
match Ext_list.exclude_with_val e.pexp_attributes Ast_attributes.is_bs with
207-
| Some pexp_attributes -> (
208-
(* syntax: {[f arg0 arg1 [@bs]]} only for legacy .ml files *)
209-
let fn = self.expr self fn in
210-
let args = Ext_list.map args (fun (lbl, e) -> (lbl, self.expr self e)) in
211-
let js_internal = Ast_literal.Lid.js_internal in
212-
let loc = e.pexp_loc in
213-
match args with
214-
| [(Nolabel, {pexp_desc = Pexp_construct ({txt = Lident "()"}, None)})] ->
215-
Exp.apply ~loc ~attrs:pexp_attributes
216-
(Exp.ident {txt = Ldot (js_internal, "run"); loc})
217-
[(Nolabel, fn)]
218-
| _ ->
219-
Exp.apply ~loc
220-
~attrs:(Ast_attributes.res_uapp :: pexp_attributes)
221-
fn args)
222-
| None -> default_expr_mapper self e)
206+
| None -> default_expr_mapper self e

jscomp/frontend/ast_exp_apply.mli

+1-5
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,4 @@
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

2525
val app_exp_mapper :
26-
Parsetree.expression ->
27-
Bs_ast_mapper.mapper ->
28-
Parsetree.expression ->
29-
Ast_compatible.args ->
30-
Parsetree.expression
26+
Parsetree.expression -> Bs_ast_mapper.mapper -> Parsetree.expression

jscomp/frontend/bs_builtin_ppx.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
154154
Ast_uncurry_gen.to_method_callback e.pexp_loc self label pat body;
155155
pexp_attributes;
156156
})
157-
| Pexp_apply (fn, args) -> Ast_exp_apply.app_exp_mapper e self fn args
157+
| Pexp_apply _ -> Ast_exp_apply.app_exp_mapper e self
158158
| Pexp_match
159159
( b,
160160
[

jscomp/test/UncurriedAlways.js

+39-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/test/UncurriedAlways.res

+11-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,17 @@ module PartialApplication = {
9191
let fxyz = f3(~x=1, ~y=1, ~z=1, ...)
9292
}
9393

94-
let hello1 = (y, f) => f(y)
94+
module ReverseApplication = {
95+
let hello1 = (y, f) => f(y)
96+
let hello2 = (y, f) => y |> f
97+
}
98+
99+
module Pipe = {
100+
let f = (a, b, c) => a->(b, c)
95101

96-
let hello2 = (y, f) => y |> f
102+
let f2 = (a, b, c, d, e) => a(b)->(c(d), d(1, 2), e)->(((u, v, h)) => u + v + h)
97103

104+
let f3 = (foo, x) => foo(x)
98105

106+
let f4 = (x, f) => x->f(3)
107+
}

jscomp/test/pipe_syntax.js

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)