Skip to content

Commit 083212f

Browse files
cknittcristianoc
andauthored
10.1_release -> master (#5863)
* Print error message when `?` is used for non-optional fields. * Add CHANGELOG entry * Set version to 10.1.0 (#5848) * Set version to 10.1.1 (#5859) * Fix two more cases of async inline. * CHANGELOG Co-authored-by: Cristiano Calcagno <cristianoc@users.noreply.github.com>
1 parent 949d700 commit 083212f

File tree

8 files changed

+52
-12
lines changed

8 files changed

+52
-12
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ These are only breaking changes for unformatted code.
5757
- Process `@set` annotation for field update as generating an uncurried function https://github.com/rescript-lang/rescript-compiler/pull/5846
5858
- Treat uncurried application of primitives like curried application, which produces better output https://github.com/rescript-lang/rescript-compiler/pull/5851
5959

60+
# 10.1.1
61+
62+
#### :bug: Bug Fix
63+
64+
- Prevent inlining of async functions in additional cases https://github.com/rescript-lang/rescript-compiler/issues/5860
65+
6066
# 10.1.0
6167

6268
#### :bug: Bug Fix

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
@@ -171,7 +171,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
171171
ap_info;
172172
} -> (
173173
match Lam_compile_env.query_external_id_info ident fld_name with
174-
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
174+
| {
175+
persistent_closed_lambda =
176+
Some (Lfunction ({ params; body } as lfunction));
177+
}
175178
(* be more cautious when do cross module inlining *)
176179
when Ext_list.same_length params args
177180
&& Ext_list.for_all args (fun arg ->
@@ -180,7 +183,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
180183
match Hash_ident.find_opt meta.ident_tbl p with
181184
| Some v -> v <> Parameter
182185
| None -> true)
183-
| _ -> true) ->
186+
| _ -> true)
187+
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
184188
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
185189
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
186190
(* 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
}
@@ -58,6 +65,7 @@ var tci = 3;
5865
exports.willBeInlined = willBeInlined;
5966
exports.inlined = inlined;
6067
exports.wrapSomethingAsync = wrapSomethingAsync;
68+
exports.wrapSomethingAsync2 = wrapSomethingAsync2;
6169
exports.M = M;
6270
exports.broken = broken$2;
6371
exports.curriedId = curriedId;

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
@@ -92837,7 +92837,7 @@ let subst (export_set : Set_ident.t) stats =
9283792837
Call
9283892838
( {
9283992839
expression_desc =
92840-
Fun {is_method=false; params; body; env};
92840+
Fun {is_method=false; params; body; env; async=false};
9284192841
},
9284292842
args,
9284392843
_info );
@@ -139496,7 +139496,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
139496139496
ap_info;
139497139497
} -> (
139498139498
match Lam_compile_env.query_external_id_info ident fld_name with
139499-
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
139499+
| {
139500+
persistent_closed_lambda =
139501+
Some (Lfunction ({ params; body } as lfunction));
139502+
}
139500139503
(* be more cautious when do cross module inlining *)
139501139504
when Ext_list.same_length params args
139502139505
&& Ext_list.for_all args (fun arg ->
@@ -139505,7 +139508,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
139505139508
match Hash_ident.find_opt meta.ident_tbl p with
139506139509
| Some v -> v <> Parameter
139507139510
| None -> true)
139508-
| _ -> true) ->
139511+
| _ -> true)
139512+
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
139509139513
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
139510139514
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
139511139515
(* 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
@@ -92837,7 +92837,7 @@ let subst (export_set : Set_ident.t) stats =
9283792837
Call
9283892838
( {
9283992839
expression_desc =
92840-
Fun {is_method=false; params; body; env};
92840+
Fun {is_method=false; params; body; env; async=false};
9284192841
},
9284292842
args,
9284392843
_info );
@@ -139496,7 +139496,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
139496139496
ap_info;
139497139497
} -> (
139498139498
match Lam_compile_env.query_external_id_info ident fld_name with
139499-
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
139499+
| {
139500+
persistent_closed_lambda =
139501+
Some (Lfunction ({ params; body } as lfunction));
139502+
}
139500139503
(* be more cautious when do cross module inlining *)
139501139504
when Ext_list.same_length params args
139502139505
&& Ext_list.for_all args (fun arg ->
@@ -139505,7 +139508,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
139505139508
match Hash_ident.find_opt meta.ident_tbl p with
139506139509
| Some v -> v <> Parameter
139507139510
| None -> true)
139508-
| _ -> true) ->
139511+
| _ -> true)
139512+
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
139509139513
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
139510139514
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
139511139515
(* 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
@@ -141231,7 +141231,7 @@ let subst (export_set : Set_ident.t) stats =
141231141231
Call
141232141232
( {
141233141233
expression_desc =
141234-
Fun {is_method=false; params; body; env};
141234+
Fun {is_method=false; params; body; env; async=false};
141235141235
},
141236141236
args,
141237141237
_info );
@@ -154666,7 +154666,10 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
154666154666
ap_info;
154667154667
} -> (
154668154668
match Lam_compile_env.query_external_id_info ident fld_name with
154669-
| { persistent_closed_lambda = Some (Lfunction { params; body; _ }) }
154669+
| {
154670+
persistent_closed_lambda =
154671+
Some (Lfunction ({ params; body } as lfunction));
154672+
}
154670154673
(* be more cautious when do cross module inlining *)
154671154674
when Ext_list.same_length params args
154672154675
&& Ext_list.for_all args (fun arg ->
@@ -154675,7 +154678,8 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t =
154675154678
match Hash_ident.find_opt meta.ident_tbl p with
154676154679
| Some v -> v <> Parameter
154677154680
| None -> true)
154678-
| _ -> true) ->
154681+
| _ -> true)
154682+
&& Lam_analysis.lfunction_can_be_beta_reduced lfunction ->
154679154683
simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args)
154680154684
| _ -> Lam.apply (simpl l1) (Ext_list.map args simpl) ap_info)
154681154685
(* Function inlining interact with other optimizations...

0 commit comments

Comments
 (0)