Skip to content

Fix compiler ppx issue when combining async and uncurried application #5856

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 1 commit into from
Nov 27, 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 @@ -43,6 +43,7 @@ These are only breaking changes for unformatted code.
- Fix issue in printing uncurried callbacks https://github.com/rescript-lang/rescript-compiler/pull/5828
- Fix formatting uncurried functions with attributes https://github.com/rescript-lang/rescript-compiler/pull/5829
- Fix parsing/printing uncurried functions with type parameters https://github.com/rescript-lang/rescript-compiler/pull/5849
- Fix compiler ppx issue when combining `async` and uncurried application https://github.com/rescript-lang/rescript-compiler/pull/5856

#### :nail_care: Polish

Expand Down
14 changes: 6 additions & 8 deletions jscomp/frontend/ast_async.ml
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
let add_promise_type ~async (result : Parsetree.expression) =
if async then
let txt =
Longident.Ldot (Longident.Ldot (Lident "Js", "Promise"), "unsafe_async")
let loc = result.pexp_loc in
let unsafe_async =
Ast_helper.Exp.ident ~loc
{ txt = Ldot (Ldot (Lident "Js", "Promise"), "unsafe_async"); loc }
in
let pexp_desc = Parsetree.Pexp_ident { txt; loc = result.pexp_loc } in
{
result with
pexp_desc = Pexp_apply ({ result with pexp_desc }, [ (Nolabel, result) ]);
}
Ast_helper.Exp.apply ~loc unsafe_async [ (Nolabel, result) ]
else result

let add_async_attribute ~async (body : Parsetree.expression) =
Expand All @@ -30,6 +28,6 @@ let rec add_promise_to_result (e : Parsetree.expression) =
let make_function_async ~async (e : Parsetree.expression) =
if async then
match e.pexp_desc with
| Pexp_fun _ -> add_async_attribute ~async (add_promise_to_result e)
| Pexp_fun _ -> add_promise_to_result e
| _ -> assert false
else e
9 changes: 5 additions & 4 deletions jscomp/frontend/ast_await.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
let create_await_expression (e : Parsetree.expression) =
let txt =
Longident.Ldot (Longident.Ldot (Lident "Js", "Promise"), "unsafe_await")
let loc = e.pexp_loc in
let unsafe_await =
Ast_helper.Exp.ident ~loc
{ txt = Ldot (Ldot (Lident "Js", "Promise"), "unsafe_await"); loc }
in
let pexp_desc = Parsetree.Pexp_ident { txt; loc = e.pexp_loc } in
{ e with pexp_desc = Pexp_apply ({ e with pexp_desc }, [ (Nolabel, e) ]) }
Ast_helper.Exp.apply ~loc unsafe_await [ (Nolabel, e) ]
24 changes: 24 additions & 0 deletions jscomp/test/async_await.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
'use strict';


function next(n) {
return n + 1 | 0;
}

async function useNext(param) {
return 4;
}

function Make(I) {
var get = async function (key) {
return await I.get(key);
};
return {
get: get
};
}

exports.next = next;
exports.useNext = useNext;
exports.Make = Make;
/* No side effect */
12 changes: 12 additions & 0 deletions jscomp/test/async_await.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@@uncurried

let next = n => n + 1
let useNext = async () => next(3)

module type Impl = {
let get: string => Js.Promise.t<string>
}

module Make = (I: Impl) => {
let get = async key => await I.get(key)
}
3 changes: 2 additions & 1 deletion jscomp/test/build.ninja

Large diffs are not rendered by default.

23 changes: 11 additions & 12 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145143,14 +145143,12 @@ module Ast_async
#1 "ast_async.ml"
let add_promise_type ~async (result : Parsetree.expression) =
if async then
let txt =
Longident.Ldot (Longident.Ldot (Lident "Js", "Promise"), "unsafe_async")
let loc = result.pexp_loc in
let unsafe_async =
Ast_helper.Exp.ident ~loc
{ txt = Ldot (Ldot (Lident "Js", "Promise"), "unsafe_async"); loc }
in
let pexp_desc = Parsetree.Pexp_ident { txt; loc = result.pexp_loc } in
{
result with
pexp_desc = Pexp_apply ({ result with pexp_desc }, [ (Nolabel, result) ]);
}
Ast_helper.Exp.apply ~loc unsafe_async [ (Nolabel, result) ]
else result

let add_async_attribute ~async (body : Parsetree.expression) =
Expand All @@ -145173,7 +145171,7 @@ let rec add_promise_to_result (e : Parsetree.expression) =
let make_function_async ~async (e : Parsetree.expression) =
if async then
match e.pexp_desc with
| Pexp_fun _ -> add_async_attribute ~async (add_promise_to_result e)
| Pexp_fun _ -> add_promise_to_result e
| _ -> assert false
else e

Expand Down Expand Up @@ -145664,11 +145662,12 @@ module Ast_await
= struct
#1 "ast_await.ml"
let create_await_expression (e : Parsetree.expression) =
let txt =
Longident.Ldot (Longident.Ldot (Lident "Js", "Promise"), "unsafe_await")
let loc = e.pexp_loc in
let unsafe_await =
Ast_helper.Exp.ident ~loc
{ txt = Ldot (Ldot (Lident "Js", "Promise"), "unsafe_await"); loc }
in
let pexp_desc = Parsetree.Pexp_ident { txt; loc = e.pexp_loc } in
{ e with pexp_desc = Pexp_apply ({ e with pexp_desc }, [ (Nolabel, e) ]) }
Ast_helper.Exp.apply ~loc unsafe_await [ (Nolabel, e) ]

end
module Bs_ast_mapper : sig
Expand Down
23 changes: 11 additions & 12 deletions lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -145143,14 +145143,12 @@ module Ast_async
#1 "ast_async.ml"
let add_promise_type ~async (result : Parsetree.expression) =
if async then
let txt =
Longident.Ldot (Longident.Ldot (Lident "Js", "Promise"), "unsafe_async")
let loc = result.pexp_loc in
let unsafe_async =
Ast_helper.Exp.ident ~loc
{ txt = Ldot (Ldot (Lident "Js", "Promise"), "unsafe_async"); loc }
in
let pexp_desc = Parsetree.Pexp_ident { txt; loc = result.pexp_loc } in
{
result with
pexp_desc = Pexp_apply ({ result with pexp_desc }, [ (Nolabel, result) ]);
}
Ast_helper.Exp.apply ~loc unsafe_async [ (Nolabel, result) ]
else result

let add_async_attribute ~async (body : Parsetree.expression) =
Expand All @@ -145173,7 +145171,7 @@ let rec add_promise_to_result (e : Parsetree.expression) =
let make_function_async ~async (e : Parsetree.expression) =
if async then
match e.pexp_desc with
| Pexp_fun _ -> add_async_attribute ~async (add_promise_to_result e)
| Pexp_fun _ -> add_promise_to_result e
| _ -> assert false
else e

Expand Down Expand Up @@ -145664,11 +145662,12 @@ module Ast_await
= struct
#1 "ast_await.ml"
let create_await_expression (e : Parsetree.expression) =
let txt =
Longident.Ldot (Longident.Ldot (Lident "Js", "Promise"), "unsafe_await")
let loc = e.pexp_loc in
let unsafe_await =
Ast_helper.Exp.ident ~loc
{ txt = Ldot (Ldot (Lident "Js", "Promise"), "unsafe_await"); loc }
in
let pexp_desc = Parsetree.Pexp_ident { txt; loc = e.pexp_loc } in
{ e with pexp_desc = Pexp_apply ({ e with pexp_desc }, [ (Nolabel, e) ]) }
Ast_helper.Exp.apply ~loc unsafe_await [ (Nolabel, e) ]

end
module Bs_ast_mapper : sig
Expand Down
23 changes: 11 additions & 12 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -155427,14 +155427,12 @@ module Ast_async
#1 "ast_async.ml"
let add_promise_type ~async (result : Parsetree.expression) =
if async then
let txt =
Longident.Ldot (Longident.Ldot (Lident "Js", "Promise"), "unsafe_async")
let loc = result.pexp_loc in
let unsafe_async =
Ast_helper.Exp.ident ~loc
{ txt = Ldot (Ldot (Lident "Js", "Promise"), "unsafe_async"); loc }
in
let pexp_desc = Parsetree.Pexp_ident { txt; loc = result.pexp_loc } in
{
result with
pexp_desc = Pexp_apply ({ result with pexp_desc }, [ (Nolabel, result) ]);
}
Ast_helper.Exp.apply ~loc unsafe_async [ (Nolabel, result) ]
else result

let add_async_attribute ~async (body : Parsetree.expression) =
Expand All @@ -155457,7 +155455,7 @@ let rec add_promise_to_result (e : Parsetree.expression) =
let make_function_async ~async (e : Parsetree.expression) =
if async then
match e.pexp_desc with
| Pexp_fun _ -> add_async_attribute ~async (add_promise_to_result e)
| Pexp_fun _ -> add_promise_to_result e
| _ -> assert false
else e

Expand Down Expand Up @@ -155948,11 +155946,12 @@ module Ast_await
= struct
#1 "ast_await.ml"
let create_await_expression (e : Parsetree.expression) =
let txt =
Longident.Ldot (Longident.Ldot (Lident "Js", "Promise"), "unsafe_await")
let loc = e.pexp_loc in
let unsafe_await =
Ast_helper.Exp.ident ~loc
{ txt = Ldot (Ldot (Lident "Js", "Promise"), "unsafe_await"); loc }
in
let pexp_desc = Parsetree.Pexp_ident { txt; loc = e.pexp_loc } in
{ e with pexp_desc = Pexp_apply ({ e with pexp_desc }, [ (Nolabel, e) ]) }
Ast_helper.Exp.apply ~loc unsafe_await [ (Nolabel, e) ]

end
module Bs_ast_mapper : sig
Expand Down