Skip to content

Fix two more cases of async inline (10.1 branch). #5860

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 28, 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
> - :house: [Internal]
> - :nail_care: [Polish]

# 10.1.1

#### :bug: Bug Fix

- Prevent inlining of async functions in additional cases https://github.com/rescript-lang/rescript-compiler/issues/5860

# 10.1.0

#### :bug: Bug Fix
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/js_pass_tailcall_inline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ let subst (export_set : Set_ident.t) stats =
Call
( {
expression_desc =
Fun {is_method=false; params; body; env};
Fun {is_method=false; params; body; env; async=false};
},
args,
_info );
Expand Down
8 changes: 6 additions & 2 deletions jscomp/core/lam_pass_remove_alias.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
ap_info;
} -> (
match Lam_compile_env.query_external_id_info ident fld_name with
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
| {
persistent_closed_lambda =
Some (Lfunction ({ params; body } as lfunction));
}
(* be more cautious when do cross module inlining *)
when Ext_list.same_length params args
&& Ext_list.for_all args (fun arg ->
Expand All @@ -137,7 +140,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
match Hash_ident.find_opt meta.ident_tbl p with
| Some v -> v <> Parameter
| None -> true)
| _ -> true) ->
| _ -> true)
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
(* Function inlining interact with other optimizations...
Expand Down
8 changes: 8 additions & 0 deletions jscomp/test/async_inline.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ function wrapSomethingAsync(param) {
})(777));
}

function wrapSomethingAsync2(param) {
((async function (param) {
var test = await Promise.resolve("Test");
console.log(test);
})(undefined));
}

async function doSomethingAsync(someAsyncFunction) {
return await Curry._1(someAsyncFunction, undefined);
}
Expand All @@ -34,6 +41,7 @@ var broken$2 = broken$1;
exports.willBeInlined = willBeInlined;
exports.inlined = inlined;
exports.wrapSomethingAsync = wrapSomethingAsync;
exports.wrapSomethingAsync2 = wrapSomethingAsync2;
exports.M = M;
exports.broken = broken$2;
/* inlined Not a pure module */
10 changes: 10 additions & 0 deletions jscomp/test/async_inline.res
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ let wrapSomethingAsync: unit => unit = () => {
)(777)
}

external ignorePromise: promise<'a> => unit = "%identity"

let wrapSomethingAsync2 = () =>
(
async () => {
let test = await Js.Promise.resolve("Test")
Js.log(test)
}
)()->ignorePromise

module M: {
let broken: (unit => promise<'a>) => promise<'a>
} = {
Expand Down
10 changes: 7 additions & 3 deletions lib/4.06.1/unstable/js_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92813,7 +92813,7 @@ let subst (export_set : Set_ident.t) stats =
Call
( {
expression_desc =
Fun {is_method=false; params; body; env};
Fun {is_method=false; params; body; env; async=false};
},
args,
_info );
Expand Down Expand Up @@ -260296,7 +260296,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
ap_info;
} -> (
match Lam_compile_env.query_external_id_info ident fld_name with
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
| {
persistent_closed_lambda =
Some (Lfunction ({ params; body } as lfunction));
}
(* be more cautious when do cross module inlining *)
when Ext_list.same_length params args
&& Ext_list.for_all args (fun arg ->
Expand All @@ -260305,7 +260308,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
match Hash_ident.find_opt meta.ident_tbl p with
| Some v -> v <> Parameter
| None -> true)
| _ -> true) ->
| _ -> true)
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
(* Function inlining interact with other optimizations...
Expand Down
10 changes: 7 additions & 3 deletions lib/4.06.1/unstable/js_playground_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92813,7 +92813,7 @@ let subst (export_set : Set_ident.t) stats =
Call
( {
expression_desc =
Fun {is_method=false; params; body; env};
Fun {is_method=false; params; body; env; async=false};
},
args,
_info );
Expand Down Expand Up @@ -260296,7 +260296,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
ap_info;
} -> (
match Lam_compile_env.query_external_id_info ident fld_name with
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
| {
persistent_closed_lambda =
Some (Lfunction ({ params; body } as lfunction));
}
(* be more cautious when do cross module inlining *)
when Ext_list.same_length params args
&& Ext_list.for_all args (fun arg ->
Expand All @@ -260305,7 +260308,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
match Hash_ident.find_opt meta.ident_tbl p with
| Some v -> v <> Parameter
| None -> true)
| _ -> true) ->
| _ -> true)
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
(* Function inlining interact with other optimizations...
Expand Down
10 changes: 7 additions & 3 deletions lib/4.06.1/whole_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -262174,7 +262174,7 @@ let subst (export_set : Set_ident.t) stats =
Call
( {
expression_desc =
Fun {is_method=false; params; body; env};
Fun {is_method=false; params; body; env; async=false};
},
args,
_info );
Expand Down Expand Up @@ -275566,7 +275566,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
ap_info;
} -> (
match Lam_compile_env.query_external_id_info ident fld_name with
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
| {
persistent_closed_lambda =
Some (Lfunction ({ params; body } as lfunction));
}
(* be more cautious when do cross module inlining *)
when Ext_list.same_length params args
&& Ext_list.for_all args (fun arg ->
Expand All @@ -275575,7 +275578,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
match Hash_ident.find_opt meta.ident_tbl p with
| Some v -> v <> Parameter
| None -> true)
| _ -> true) ->
| _ -> true)
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
(* Function inlining interact with other optimizations...
Expand Down