Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 07aba84

Browse files
committedOct 25, 2022
Prevent inlining of async functions
Fixes #5754
1 parent 8278bf0 commit 07aba84

11 files changed

+60
-19
lines changed
 

‎CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@
1212
1313
# 10.1.0-rc.3
1414

15+
#### :bug: Bug Fix
16+
1517
- Fix issue where the JSX key type is not an optional string https://github.com/rescript-lang/syntax/pull/693
1618

19+
- Prevent inlining of async functions
20+
1721
# 10.1.0-rc.2
1822

1923
#### :bug: Bug Fix

‎jscomp/core/lam_analysis.ml

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ let destruct_pattern (body : Lam.t) params args =
247247
(** Hints to inlining *)
248248
let ok_to_inline_fun_when_app (m : Lam.lfunction) (args : Lam.t list) =
249249
match m.attr.inline with
250+
| _ when m.attr.async -> false
250251
| Always_inline -> true
251252
| Never_inline -> false
252253
| Default_inline -> (

‎jscomp/core/lam_pass_lets_dce.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t =
147147
end
148148
| Lsequence(l1, l2) -> Lam.seq (simplif l1) (simplif l2)
149149

150-
| Lapply{ap_func = Lfunction{params; body}; ap_args = args; _}
151-
when Ext_list.same_length params args ->
150+
| Lapply{ap_func = Lfunction{params; body; attr}; ap_args = args; _}
151+
when Ext_list.same_length params args && not attr.async ->
152152
simplif (Lam_beta_reduce.no_names_beta_reduce params body args)
153153
(* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *)
154154
(* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *)

‎jscomp/core/lam_pass_lets_dce.pp.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t =
146146
end
147147
| Lsequence(l1, l2) -> Lam.seq (simplif l1) (simplif l2)
148148

149-
| Lapply{ap_func = Lfunction{params; body}; ap_args = args; _}
150-
when Ext_list.same_length params args ->
149+
| Lapply{ap_func = Lfunction{params; body; attr}; ap_args = args; _}
150+
when Ext_list.same_length params args && not attr.async ->
151151
simplif (Lam_beta_reduce.no_names_beta_reduce params body args)
152152
(* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *)
153153
(* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *)

‎jscomp/core/lam_pass_remove_alias.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
211211
else normal ()
212212
else normal ()
213213
| Some _ | None -> normal ())
214-
| Lapply { ap_func = Lfunction { params; body }; ap_args = args; _ }
215-
when Ext_list.same_length params args ->
214+
| Lapply { ap_func = Lfunction { params; body; attr }; ap_args = args; _ }
215+
when Ext_list.same_length params args && not attr.async ->
216216
simpl (Lam_beta_reduce.propogate_beta_reduce meta params body args)
217217
(* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *)
218218
(* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *)

‎jscomp/test/async_inline.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'use strict';
2+
3+
4+
async function willBeInlined(param) {
5+
return 3;
6+
}
7+
8+
var inlined = willBeInlined(undefined);
9+
10+
function wrapSomethingAsync(param) {
11+
((async function (param) {
12+
var test = await Promise.resolve("Test");
13+
console.log(test);
14+
})(777));
15+
}
16+
17+
exports.willBeInlined = willBeInlined;
18+
exports.inlined = inlined;
19+
exports.wrapSomethingAsync = wrapSomethingAsync;
20+
/* inlined Not a pure module */

‎jscomp/test/async_inline.res

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
let willBeInlined = async () => 3
2+
3+
let inlined = willBeInlined ()
4+
5+
let wrapSomethingAsync: unit => unit = () => {
6+
let _ = (
7+
async (_) => {
8+
let test = await Js.Promise.resolve("Test")
9+
Js.log(test)
10+
}
11+
)(777)
12+
}

‎jscomp/test/build.ninja

+2-1
Large diffs are not rendered by default.

‎lib/4.06.1/unstable/js_compiler.ml

+5-4
Original file line numberDiff line numberDiff line change
@@ -91581,6 +91581,7 @@ let destruct_pattern (body : Lam.t) params args =
9158191581
(** Hints to inlining *)
9158291582
let ok_to_inline_fun_when_app (m : Lam.lfunction) (args : Lam.t list) =
9158391583
match m.attr.inline with
91584+
| _ when m.attr.async -> false
9158491585
| Always_inline -> true
9158591586
| Never_inline -> false
9158691587
| Default_inline -> (
@@ -258306,8 +258307,8 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t =
258306258307
end
258307258308
| Lsequence(l1, l2) -> Lam.seq (simplif l1) (simplif l2)
258308258309

258309-
| Lapply{ap_func = Lfunction{params; body}; ap_args = args; _}
258310-
when Ext_list.same_length params args ->
258310+
| Lapply{ap_func = Lfunction{params; body; attr}; ap_args = args; _}
258311+
when Ext_list.same_length params args && not attr.async ->
258311258312
simplif (Lam_beta_reduce.no_names_beta_reduce params body args)
258312258313
(* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *)
258313258314
(* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *)
@@ -258679,8 +258680,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
258679258680
else normal ()
258680258681
else normal ()
258681258682
| Some _ | None -> normal ())
258682-
| Lapply { ap_func = Lfunction { params; body }; ap_args = args; _ }
258683-
when Ext_list.same_length params args ->
258683+
| Lapply { ap_func = Lfunction { params; body; attr }; ap_args = args; _ }
258684+
when Ext_list.same_length params args && not attr.async ->
258684258685
simpl (Lam_beta_reduce.propogate_beta_reduce meta params body args)
258685258686
(* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *)
258686258687
(* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *)

‎lib/4.06.1/unstable/js_playground_compiler.ml

+5-4
Original file line numberDiff line numberDiff line change
@@ -91581,6 +91581,7 @@ let destruct_pattern (body : Lam.t) params args =
9158191581
(** Hints to inlining *)
9158291582
let ok_to_inline_fun_when_app (m : Lam.lfunction) (args : Lam.t list) =
9158391583
match m.attr.inline with
91584+
| _ when m.attr.async -> false
9158491585
| Always_inline -> true
9158591586
| Never_inline -> false
9158691587
| Default_inline -> (
@@ -258306,8 +258307,8 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t =
258306258307
end
258307258308
| Lsequence(l1, l2) -> Lam.seq (simplif l1) (simplif l2)
258308258309

258309-
| Lapply{ap_func = Lfunction{params; body}; ap_args = args; _}
258310-
when Ext_list.same_length params args ->
258310+
| Lapply{ap_func = Lfunction{params; body; attr}; ap_args = args; _}
258311+
when Ext_list.same_length params args && not attr.async ->
258311258312
simplif (Lam_beta_reduce.no_names_beta_reduce params body args)
258312258313
(* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *)
258313258314
(* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *)
@@ -258679,8 +258680,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
258679258680
else normal ()
258680258681
else normal ()
258681258682
| Some _ | None -> normal ())
258682-
| Lapply { ap_func = Lfunction { params; body }; ap_args = args; _ }
258683-
when Ext_list.same_length params args ->
258683+
| Lapply { ap_func = Lfunction { params; body; attr }; ap_args = args; _ }
258684+
when Ext_list.same_length params args && not attr.async ->
258684258685
simpl (Lam_beta_reduce.propogate_beta_reduce meta params body args)
258685258686
(* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *)
258686258687
(* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *)

‎lib/4.06.1/whole_compiler.ml

+5-4
Original file line numberDiff line numberDiff line change
@@ -260942,6 +260942,7 @@ let destruct_pattern (body : Lam.t) params args =
260942260942
(** Hints to inlining *)
260943260943
let ok_to_inline_fun_when_app (m : Lam.lfunction) (args : Lam.t list) =
260944260944
match m.attr.inline with
260945+
| _ when m.attr.async -> false
260945260946
| Always_inline -> true
260946260947
| Never_inline -> false
260947260948
| Default_inline -> (
@@ -273576,8 +273577,8 @@ let lets_helper (count_var : Ident.t -> Lam_pass_count.used_info) lam : Lam.t =
273576273577
end
273577273578
| Lsequence(l1, l2) -> Lam.seq (simplif l1) (simplif l2)
273578273579

273579-
| Lapply{ap_func = Lfunction{params; body}; ap_args = args; _}
273580-
when Ext_list.same_length params args ->
273580+
| Lapply{ap_func = Lfunction{params; body; attr}; ap_args = args; _}
273581+
when Ext_list.same_length params args && not attr.async ->
273581273582
simplif (Lam_beta_reduce.no_names_beta_reduce params body args)
273582273583
(* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *)
273583273584
(* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *)
@@ -273949,8 +273950,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
273949273950
else normal ()
273950273951
else normal ()
273951273952
| Some _ | None -> normal ())
273952-
| Lapply { ap_func = Lfunction { params; body }; ap_args = args; _ }
273953-
when Ext_list.same_length params args ->
273953+
| Lapply { ap_func = Lfunction { params; body; attr }; ap_args = args; _ }
273954+
when Ext_list.same_length params args && not attr.async ->
273954273955
simpl (Lam_beta_reduce.propogate_beta_reduce meta params body args)
273955273956
(* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *)
273956273957
(* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *)

0 commit comments

Comments
 (0)