Skip to content

Commit eab526d

Browse files
cristianoccknitt
authored andcommitted
Fix two more cases of async inline.
1 parent 4ec855e commit eab526d

7 files changed

+46
-12
lines changed

jscomp/core/js_pass_tailcall_inline.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ let subst (export_set : Set_ident.t) stats =
200200
Call
201201
( {
202202
expression_desc =
203-
Fun {is_method=false; params; body; env};
203+
Fun {is_method=false; params; body; env; async=false};
204204
},
205205
args,
206206
_info );

jscomp/core/lam_pass_remove_alias.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
128128
ap_info;
129129
} -> (
130130
match Lam_compile_env.query_external_id_info ident fld_name with
131-
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
131+
| {
132+
persistent_closed_lambda =
133+
Some (Lfunction ({ params; body } as lfunction));
134+
}
132135
(* be more cautious when do cross module inlining *)
133136
when Ext_list.same_length params args
134137
&& Ext_list.for_all args (fun arg ->
@@ -137,7 +140,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
137140
match Hash_ident.find_opt meta.ident_tbl p with
138141
| Some v -> v <> Parameter
139142
| None -> true)
140-
| _ -> true) ->
143+
| _ -> true)
144+
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
141145
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
142146
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
143147
(* Function inlining interact with other optimizations...

jscomp/test/async_inline.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ function wrapSomethingAsync(param) {
1515
})(777));
1616
}
1717

18+
function wrapSomethingAsync2(param) {
19+
((async function (param) {
20+
var test = await Promise.resolve("Test");
21+
console.log(test);
22+
})(undefined));
23+
}
24+
1825
async function doSomethingAsync(someAsyncFunction) {
1926
return await Curry._1(someAsyncFunction, undefined);
2027
}
@@ -34,6 +41,7 @@ var broken$2 = broken$1;
3441
exports.willBeInlined = willBeInlined;
3542
exports.inlined = inlined;
3643
exports.wrapSomethingAsync = wrapSomethingAsync;
44+
exports.wrapSomethingAsync2 = wrapSomethingAsync2;
3745
exports.M = M;
3846
exports.broken = broken$2;
3947
/* inlined Not a pure module */

jscomp/test/async_inline.res

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ let wrapSomethingAsync: unit => unit = () => {
1111
)(777)
1212
}
1313

14+
external ignorePromise: promise<'a> => unit = "%identity"
15+
16+
let wrapSomethingAsync2 = () =>
17+
(
18+
async () => {
19+
let test = await Js.Promise.resolve("Test")
20+
Js.log(test)
21+
}
22+
)()->ignorePromise
23+
1424
module M: {
1525
let broken: (unit => promise<'a>) => promise<'a>
1626
} = {

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92813,7 +92813,7 @@ let subst (export_set : Set_ident.t) stats =
9281392813
Call
9281492814
( {
9281592815
expression_desc =
92816-
Fun {is_method=false; params; body; env};
92816+
Fun {is_method=false; params; body; env; async=false};
9281792817
},
9281892818
args,
9281992819
_info );
@@ -260296,7 +260296,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
260296260296
ap_info;
260297260297
} -> (
260298260298
match Lam_compile_env.query_external_id_info ident fld_name with
260299-
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
260299+
| {
260300+
persistent_closed_lambda =
260301+
Some (Lfunction ({ params; body } as lfunction));
260302+
}
260300260303
(* be more cautious when do cross module inlining *)
260301260304
when Ext_list.same_length params args
260302260305
&& Ext_list.for_all args (fun arg ->
@@ -260305,7 +260308,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
260305260308
match Hash_ident.find_opt meta.ident_tbl p with
260306260309
| Some v -> v <> Parameter
260307260310
| None -> true)
260308-
| _ -> true) ->
260311+
| _ -> true)
260312+
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
260309260313
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
260310260314
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
260311260315
(* Function inlining interact with other optimizations...

lib/4.06.1/unstable/js_playground_compiler.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92813,7 +92813,7 @@ let subst (export_set : Set_ident.t) stats =
9281392813
Call
9281492814
( {
9281592815
expression_desc =
92816-
Fun {is_method=false; params; body; env};
92816+
Fun {is_method=false; params; body; env; async=false};
9281792817
},
9281892818
args,
9281992819
_info );
@@ -260296,7 +260296,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
260296260296
ap_info;
260297260297
} -> (
260298260298
match Lam_compile_env.query_external_id_info ident fld_name with
260299-
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
260299+
| {
260300+
persistent_closed_lambda =
260301+
Some (Lfunction ({ params; body } as lfunction));
260302+
}
260300260303
(* be more cautious when do cross module inlining *)
260301260304
when Ext_list.same_length params args
260302260305
&& Ext_list.for_all args (fun arg ->
@@ -260305,7 +260308,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
260305260308
match Hash_ident.find_opt meta.ident_tbl p with
260306260309
| Some v -> v <> Parameter
260307260310
| None -> true)
260308-
| _ -> true) ->
260311+
| _ -> true)
260312+
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
260309260313
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
260310260314
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
260311260315
(* Function inlining interact with other optimizations...

lib/4.06.1/whole_compiler.ml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262174,7 +262174,7 @@ let subst (export_set : Set_ident.t) stats =
262174262174
Call
262175262175
( {
262176262176
expression_desc =
262177-
Fun {is_method=false; params; body; env};
262177+
Fun {is_method=false; params; body; env; async=false};
262178262178
},
262179262179
args,
262180262180
_info );
@@ -275566,7 +275566,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
275566275566
ap_info;
275567275567
} -> (
275568275568
match Lam_compile_env.query_external_id_info ident fld_name with
275569-
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
275569+
| {
275570+
persistent_closed_lambda =
275571+
Some (Lfunction ({ params; body } as lfunction));
275572+
}
275570275573
(* be more cautious when do cross module inlining *)
275571275574
when Ext_list.same_length params args
275572275575
&& Ext_list.for_all args (fun arg ->
@@ -275575,7 +275578,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
275575275578
match Hash_ident.find_opt meta.ident_tbl p with
275576275579
| Some v -> v <> Parameter
275577275580
| None -> true)
275578-
| _ -> true) ->
275581+
| _ -> true)
275582+
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
275579275583
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
275580275584
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
275581275585
(* Function inlining interact with other optimizations...

0 commit comments

Comments
 (0)