Skip to content

Interpret arity of uncurried explicitly. #5795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- Remove obsolete built-in project templates and the "rescript init" functionality. This will be replaced by the create-rescript-app project that is maintained separately.
- Parse the attributes of labelled argument to the pattern attributes of argument instead of function.
- Made pinned dependencies transitive: if *a* is a pinned dependency of *b* and *b* is a pinned dependency of *c*, then *a* is implicitly a pinned dependency of *c*. This change is only breaking if your build process assumes non-transitivity.
- Curried after uncurried is not fused anymore: `(. x) => y => 3` is not equivalent to `(. x, y) => 3` anymore. It's instead equivalent to `(. x) => { y => 3 }`.

#### :nail_care: Polish

Expand Down
3 changes: 2 additions & 1 deletion lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56050,7 +56050,8 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
(ParsetreeViewer.rewriteUnderscoreApply e)
cmtTbl
| Pexp_fun _ | Pexp_newtype _ -> printArrow ~isUncurried:false e
| Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), name)}, funExpr)], None)
| Pexp_record
([({txt = Ldot (Ldot (Lident "Js", "Fn"), name)}, funExpr)], None)
when String.length name >= 1 && name.[0] = 'I' ->
printArrow ~isUncurried:true funExpr
| Pexp_record (rows, spreadExpr) ->
Expand Down
3 changes: 2 additions & 1 deletion lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -56050,7 +56050,8 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
(ParsetreeViewer.rewriteUnderscoreApply e)
cmtTbl
| Pexp_fun _ | Pexp_newtype _ -> printArrow ~isUncurried:false e
| Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), name)}, funExpr)], None)
| Pexp_record
([({txt = Ldot (Ldot (Lident "Js", "Fn"), name)}, funExpr)], None)
when String.length name >= 1 && name.[0] = 'I' ->
printArrow ~isUncurried:true funExpr
| Pexp_record (rows, spreadExpr) ->
Expand Down
3 changes: 2 additions & 1 deletion lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -231912,7 +231912,8 @@ and printExpression ~customLayout (e : Parsetree.expression) cmtTbl =
(ParsetreeViewer.rewriteUnderscoreApply e)
cmtTbl
| Pexp_fun _ | Pexp_newtype _ -> printArrow ~isUncurried:false e
| Pexp_record ([({txt = Ldot (Ldot (Lident "Js", "Fn"), name)}, funExpr)], None)
| Pexp_record
([({txt = Ldot (Ldot (Lident "Js", "Fn"), name)}, funExpr)], None)
when String.length name >= 1 && name.[0] = 'I' ->
printArrow ~isUncurried:true funExpr
| Pexp_record (rows, spreadExpr) ->
Expand Down
12 changes: 12 additions & 0 deletions res_syntax/src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,18 @@ and parseEs6ArrowExpression ?(arrowAttrs = []) ?(arrowStartPos = None) ?context
in
Parser.eatBreadcrumb p;
let endPos = p.prevEndPos in
let body =
match parameters with
| TermParameter {uncurried = true} :: _
when match body.pexp_desc with
| Pexp_fun _ -> true
| _ -> false ->
{
body with
pexp_attributes = makeBracesAttr body.pexp_loc :: body.pexp_attributes;
}
| _ -> body
in
let arrowExpr, _arity =
List.fold_right
(fun parameter (expr, arity) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ let f =
(({
Js.Fn.I1 =
(fun a ->
((fun b -> (({ Js.Fn.I1 = (fun c -> ((fun d -> ())[@attr4 ])) })
((fun b ->
(({
Js.Fn.I1 =
(fun c -> ((fun d -> ())[@ns.braces ][@attr4 ]))
})
[@attr3 ]))
[@attr2 ]))
[@ns.braces ][@attr2 ]))
})
[@attr ])
let f =
Expand Down
6 changes: 1 addition & 5 deletions res_syntax/tests/printer/expr/asyncAwait.res
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,5 @@ let b3 = await (foo->bar(~arg))
let b4 = await (foo.bar.baz)

let c1 = @foo x => @bar y => x + y

// This is not idempotent:
// let c2 = (. x) => y => x+y

let c2 = (. x, y) => x+y
let c2 = (. x) => y => x+y
let c3 = (. x) => @foo y => x+y
8 changes: 2 additions & 6 deletions res_syntax/tests/printer/expr/expected/asyncAwait.res.txt
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,5 @@ let b3 = await foo->bar(~arg)
let b4 = await foo.bar.baz

let c1 = @foo x => @bar y => x + y

// This is not idempotent:
// let c2 = (. x) => y => x+y

let c2 = (. x, y) => x + y
let c3 = (. x) => @foo y => x + y
let c2 = (. x) => {y => x + y}
let c3 = (. x) => {@foo y => x + y}