diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fabce7e28..3348d8c97f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,12 @@ These are only breaking changes for unformatted code. - Process `@set` annotation for field update as generating an uncurried function https://github.com/rescript-lang/rescript-compiler/pull/5846 - Treat uncurried application of primitives like curried application, which produces better output https://github.com/rescript-lang/rescript-compiler/pull/5851 +# 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 diff --git a/jscomp/core/js_pass_tailcall_inline.ml b/jscomp/core/js_pass_tailcall_inline.ml index 3ae42a5081..d3e003c109 100644 --- a/jscomp/core/js_pass_tailcall_inline.ml +++ b/jscomp/core/js_pass_tailcall_inline.ml @@ -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 ); diff --git a/jscomp/core/lam_pass_remove_alias.ml b/jscomp/core/lam_pass_remove_alias.ml index fe459f6bfc..33bceda1ff 100644 --- a/jscomp/core/lam_pass_remove_alias.ml +++ b/jscomp/core/lam_pass_remove_alias.ml @@ -171,7 +171,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 -> @@ -180,7 +183,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... diff --git a/jscomp/test/async_inline.js b/jscomp/test/async_inline.js index 150cc10a3f..5854f25103 100644 --- a/jscomp/test/async_inline.js +++ b/jscomp/test/async_inline.js @@ -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); } @@ -58,6 +65,7 @@ var tci = 3; exports.willBeInlined = willBeInlined; exports.inlined = inlined; exports.wrapSomethingAsync = wrapSomethingAsync; +exports.wrapSomethingAsync2 = wrapSomethingAsync2; exports.M = M; exports.broken = broken$2; exports.curriedId = curriedId; diff --git a/jscomp/test/async_inline.res b/jscomp/test/async_inline.res index 98c6ba14d3..9535d50eed 100644 --- a/jscomp/test/async_inline.res +++ b/jscomp/test/async_inline.res @@ -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> } = { diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index ff07ed091d..f5d3a90a8c 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -92837,7 +92837,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 ); @@ -139496,7 +139496,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 -> @@ -139505,7 +139508,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... diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index a063381456..9a5cc506de 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -92837,7 +92837,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 ); @@ -139496,7 +139496,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 -> @@ -139505,7 +139508,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... diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 80bcd4b2dd..b1955c230d 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -141231,7 +141231,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 ); @@ -154666,7 +154666,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 -> @@ -154675,7 +154678,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...