From 11b0b62d77a3bd0634024f2957e5b108d220a333 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Sat, 26 Nov 2022 12:39:59 +0100 Subject: [PATCH 1/6] Print error message when `?` is used for non-optional fields. --- .../expected/fieldNotOptional.res.expected | 11 ++++++ .../fixtures/fieldNotOptional.res | 17 +++++++++ jscomp/ml/typecore.ml | 37 ++++++++++-------- jscomp/ml/typecore.mli | 1 + lib/4.06.1/unstable/js_compiler.ml | 38 +++++++++++-------- lib/4.06.1/unstable/js_playground_compiler.ml | 38 +++++++++++-------- lib/4.06.1/whole_compiler.ml | 38 +++++++++++-------- 7 files changed, 116 insertions(+), 64 deletions(-) create mode 100644 jscomp/build_tests/super_errors/expected/fieldNotOptional.res.expected create mode 100644 jscomp/build_tests/super_errors/fixtures/fieldNotOptional.res diff --git a/jscomp/build_tests/super_errors/expected/fieldNotOptional.res.expected b/jscomp/build_tests/super_errors/expected/fieldNotOptional.res.expected new file mode 100644 index 0000000000..c4069fbeaa --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/fieldNotOptional.res.expected @@ -0,0 +1,11 @@ + + We've found a bug for you! + /.../fixtures/fieldNotOptional.res:3:19 + + 1 │ type r = {nonopt: int, opt?: string} + 2 │ + 3 │ let v = {nonopt: ?3, opt: ?None} + 4 │ + 5 │ let f = r => + + Field nonopt is not optional in type r. Use without ? \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/fieldNotOptional.res b/jscomp/build_tests/super_errors/fixtures/fieldNotOptional.res new file mode 100644 index 0000000000..e653cbd9e6 --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/fieldNotOptional.res @@ -0,0 +1,17 @@ +type r = {nonopt: int, opt?: string} + +let v = {nonopt: ?3, opt: ?None} + +let f = r => + switch r { + | {nonopt: ?_, opt: ?_} => true + } + +type inline = A({nonopt: int, opt?: string}) + +let vi = A({nonopt: ?3, opt: ?None}) + +let fi = a => + switch a { + | A ({nonopt: ?_, opt: ?_}) => true + } \ No newline at end of file diff --git a/jscomp/ml/typecore.ml b/jscomp/ml/typecore.ml index f0d46e94b5..afc9488684 100644 --- a/jscomp/ml/typecore.ml +++ b/jscomp/ml/typecore.ml @@ -73,6 +73,7 @@ type error = | Illegal_letrec_pat | Labels_omitted of string list | Empty_record_literal + | Field_not_optional of string * type_expr exception Error of Location.t * Env.t * error exception Error_forward of Location.error @@ -308,6 +309,19 @@ let extract_concrete_variant env ty = | (p0, p, {type_kind=Type_open}) -> (p0, p, []) | _ -> raise Not_found +let label_is_optional ld = + match ld.lbl_repres with + | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name + | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name + | _ -> false + +let check_optional_attr env ld attrs loc = + let check_redundant () = + if not (label_is_optional ld) then + raise (Error (loc, env, Field_not_optional (ld.lbl_name, ld.lbl_res))); + true in + Ext_list.exists attrs (fun ({txt}, _) -> + txt = "ns.optional" && check_redundant ()) (* unification inside type_pat*) let unify_pat_types loc env ty ty' = @@ -1150,15 +1164,8 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env Some (p0, p), expected_ty with Not_found -> None, newvar () in - let label_is_optional ld = - match ld.lbl_repres with - | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name - | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name - | _ -> false in let process_optional_label (ld, pat) = - let exp_optional_attr = - Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "ns.optional") - in + let exp_optional_attr = check_optional_attr !env ld pat.ppat_attributes pat.ppat_loc in let isFromPamatch = match pat.ppat_desc with | Ppat_construct ({txt = Lident s}, _) -> String.length s >= 2 && s.[0] = '#' && s.[1] = '$' @@ -1877,15 +1884,8 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected = unify_exp env (re exp) (instance env ty_expected); exp in - let label_is_optional ld = - match ld.lbl_repres with - | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name - | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name - | _ -> false in let process_optional_label (id, ld, e) = - let exp_optional_attr = - Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "ns.optional") - in + let exp_optional_attr = check_optional_attr env ld e.pexp_attributes e.pexp_loc in if label_is_optional ld && not exp_optional_attr then let lid = mknoloc (Longident.(Ldot (Lident "*predef*", "Some"))) in let e = Ast_helper.Exp.construct ~loc:e.pexp_loc lid (Some e) @@ -3797,6 +3797,11 @@ let report_error env ppf = function (String.concat ", " labels) | Empty_record_literal -> fprintf ppf "Empty record literal {} should be type annotated or used in a record context." + | Field_not_optional (name, typ) -> + fprintf ppf + "Field @{%s@} is not optional in type %a. Use without ?" name + type_expr typ + let super_report_error_no_wrap_printing_env = report_error diff --git a/jscomp/ml/typecore.mli b/jscomp/ml/typecore.mli index 8f788b65c5..7c1cb523f4 100644 --- a/jscomp/ml/typecore.mli +++ b/jscomp/ml/typecore.mli @@ -109,6 +109,7 @@ type error = | Illegal_letrec_pat | Labels_omitted of string list | Empty_record_literal + | Field_not_optional of string * type_expr exception Error of Location.t * Env.t * error exception Error_forward of Location.error diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 1a53766017..05e5c1e98c 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -40690,6 +40690,7 @@ type error = | Illegal_letrec_pat | Labels_omitted of string list | Empty_record_literal + | Field_not_optional of string * type_expr exception Error of Location.t * Env.t * error exception Error_forward of Location.error @@ -40797,6 +40798,7 @@ type error = | Illegal_letrec_pat | Labels_omitted of string list | Empty_record_literal + | Field_not_optional of string * type_expr exception Error of Location.t * Env.t * error exception Error_forward of Location.error @@ -41032,6 +41034,19 @@ let extract_concrete_variant env ty = | (p0, p, {type_kind=Type_open}) -> (p0, p, []) | _ -> raise Not_found +let label_is_optional ld = + match ld.lbl_repres with + | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name + | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name + | _ -> false + +let check_optional_attr env ld attrs loc = + let check_redundant () = + if not (label_is_optional ld) then + raise (Error (loc, env, Field_not_optional (ld.lbl_name, ld.lbl_res))); + true in + Ext_list.exists attrs (fun ({txt}, _) -> + txt = "ns.optional" && check_redundant ()) (* unification inside type_pat*) let unify_pat_types loc env ty ty' = @@ -41874,15 +41889,8 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env Some (p0, p), expected_ty with Not_found -> None, newvar () in - let label_is_optional ld = - match ld.lbl_repres with - | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name - | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name - | _ -> false in let process_optional_label (ld, pat) = - let exp_optional_attr = - Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "ns.optional") - in + let exp_optional_attr = check_optional_attr !env ld pat.ppat_attributes pat.ppat_loc in let isFromPamatch = match pat.ppat_desc with | Ppat_construct ({txt = Lident s}, _) -> String.length s >= 2 && s.[0] = '#' && s.[1] = '$' @@ -42601,15 +42609,8 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected = unify_exp env (re exp) (instance env ty_expected); exp in - let label_is_optional ld = - match ld.lbl_repres with - | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name - | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name - | _ -> false in let process_optional_label (id, ld, e) = - let exp_optional_attr = - Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "ns.optional") - in + let exp_optional_attr = check_optional_attr env ld e.pexp_attributes e.pexp_loc in if label_is_optional ld && not exp_optional_attr then let lid = mknoloc (Longident.(Ldot (Lident "*predef*", "Some"))) in let e = Ast_helper.Exp.construct ~loc:e.pexp_loc lid (Some e) @@ -44521,6 +44522,11 @@ let report_error env ppf = function (String.concat ", " labels) | Empty_record_literal -> fprintf ppf "Empty record literal {} should be type annotated or used in a record context." + | Field_not_optional (name, typ) -> + fprintf ppf + "Field @{%s@} is not optional in type %a. Use without ?" name + type_expr typ + let super_report_error_no_wrap_printing_env = report_error diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index 57ac3378e5..d695518b4f 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -40690,6 +40690,7 @@ type error = | Illegal_letrec_pat | Labels_omitted of string list | Empty_record_literal + | Field_not_optional of string * type_expr exception Error of Location.t * Env.t * error exception Error_forward of Location.error @@ -40797,6 +40798,7 @@ type error = | Illegal_letrec_pat | Labels_omitted of string list | Empty_record_literal + | Field_not_optional of string * type_expr exception Error of Location.t * Env.t * error exception Error_forward of Location.error @@ -41032,6 +41034,19 @@ let extract_concrete_variant env ty = | (p0, p, {type_kind=Type_open}) -> (p0, p, []) | _ -> raise Not_found +let label_is_optional ld = + match ld.lbl_repres with + | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name + | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name + | _ -> false + +let check_optional_attr env ld attrs loc = + let check_redundant () = + if not (label_is_optional ld) then + raise (Error (loc, env, Field_not_optional (ld.lbl_name, ld.lbl_res))); + true in + Ext_list.exists attrs (fun ({txt}, _) -> + txt = "ns.optional" && check_redundant ()) (* unification inside type_pat*) let unify_pat_types loc env ty ty' = @@ -41874,15 +41889,8 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env Some (p0, p), expected_ty with Not_found -> None, newvar () in - let label_is_optional ld = - match ld.lbl_repres with - | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name - | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name - | _ -> false in let process_optional_label (ld, pat) = - let exp_optional_attr = - Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "ns.optional") - in + let exp_optional_attr = check_optional_attr !env ld pat.ppat_attributes pat.ppat_loc in let isFromPamatch = match pat.ppat_desc with | Ppat_construct ({txt = Lident s}, _) -> String.length s >= 2 && s.[0] = '#' && s.[1] = '$' @@ -42601,15 +42609,8 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected = unify_exp env (re exp) (instance env ty_expected); exp in - let label_is_optional ld = - match ld.lbl_repres with - | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name - | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name - | _ -> false in let process_optional_label (id, ld, e) = - let exp_optional_attr = - Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "ns.optional") - in + let exp_optional_attr = check_optional_attr env ld e.pexp_attributes e.pexp_loc in if label_is_optional ld && not exp_optional_attr then let lid = mknoloc (Longident.(Ldot (Lident "*predef*", "Some"))) in let e = Ast_helper.Exp.construct ~loc:e.pexp_loc lid (Some e) @@ -44521,6 +44522,11 @@ let report_error env ppf = function (String.concat ", " labels) | Empty_record_literal -> fprintf ppf "Empty record literal {} should be type annotated or used in a record context." + | Field_not_optional (name, typ) -> + fprintf ppf + "Field @{%s@} is not optional in type %a. Use without ?" name + type_expr typ + let super_report_error_no_wrap_printing_env = report_error diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index e67bd9090b..dabce93269 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -216862,6 +216862,7 @@ type error = | Illegal_letrec_pat | Labels_omitted of string list | Empty_record_literal + | Field_not_optional of string * type_expr exception Error of Location.t * Env.t * error exception Error_forward of Location.error @@ -216969,6 +216970,7 @@ type error = | Illegal_letrec_pat | Labels_omitted of string list | Empty_record_literal + | Field_not_optional of string * type_expr exception Error of Location.t * Env.t * error exception Error_forward of Location.error @@ -217204,6 +217206,19 @@ let extract_concrete_variant env ty = | (p0, p, {type_kind=Type_open}) -> (p0, p, []) | _ -> raise Not_found +let label_is_optional ld = + match ld.lbl_repres with + | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name + | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name + | _ -> false + +let check_optional_attr env ld attrs loc = + let check_redundant () = + if not (label_is_optional ld) then + raise (Error (loc, env, Field_not_optional (ld.lbl_name, ld.lbl_res))); + true in + Ext_list.exists attrs (fun ({txt}, _) -> + txt = "ns.optional" && check_redundant ()) (* unification inside type_pat*) let unify_pat_types loc env ty ty' = @@ -218046,15 +218061,8 @@ and type_pat_aux ~constrs ~labels ~no_existentials ~mode ~explode ~env Some (p0, p), expected_ty with Not_found -> None, newvar () in - let label_is_optional ld = - match ld.lbl_repres with - | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name - | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name - | _ -> false in let process_optional_label (ld, pat) = - let exp_optional_attr = - Ext_list.exists pat.ppat_attributes (fun ({txt },_) -> txt = "ns.optional") - in + let exp_optional_attr = check_optional_attr !env ld pat.ppat_attributes pat.ppat_loc in let isFromPamatch = match pat.ppat_desc with | Ppat_construct ({txt = Lident s}, _) -> String.length s >= 2 && s.[0] = '#' && s.[1] = '$' @@ -218773,15 +218781,8 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected = unify_exp env (re exp) (instance env ty_expected); exp in - let label_is_optional ld = - match ld.lbl_repres with - | Record_optional_labels lbls -> Ext_list.mem_string lbls ld.lbl_name - | Record_inlined {optional_labels} -> Ext_list.mem_string optional_labels ld.lbl_name - | _ -> false in let process_optional_label (id, ld, e) = - let exp_optional_attr = - Ext_list.exists e.pexp_attributes (fun ({txt },_) -> txt = "ns.optional") - in + let exp_optional_attr = check_optional_attr env ld e.pexp_attributes e.pexp_loc in if label_is_optional ld && not exp_optional_attr then let lid = mknoloc (Longident.(Ldot (Lident "*predef*", "Some"))) in let e = Ast_helper.Exp.construct ~loc:e.pexp_loc lid (Some e) @@ -220693,6 +220694,11 @@ let report_error env ppf = function (String.concat ", " labels) | Empty_record_literal -> fprintf ppf "Empty record literal {} should be type annotated or used in a record context." + | Field_not_optional (name, typ) -> + fprintf ppf + "Field @{%s@} is not optional in type %a. Use without ?" name + type_expr typ + let super_report_error_no_wrap_printing_env = report_error From 14e999e649d9721ccb47e54c1ffdc6fcd02ff8d5 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 27 Nov 2022 08:57:04 +0100 Subject: [PATCH 2/6] Add CHANGELOG entry --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd600cf4a9..5285ba1e5d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,10 +10,11 @@ > - :house: [Internal] > - :nail_care: [Polish] -# 10.1.0-rc.6 +# 10.1.0 #### :bug: Bug Fix +- Fix issue where no error was reported when ? was used for non-optional fields. https://github.com/rescript-lang/rescript-compiler/pull/5853 - Fix issue where optional fields in inline records were not supported and would cause type errors https://github.com/rescript-lang/rescript-compiler/pull/5827 # 10.1.0-rc.5 From 192bbd8210f2c5406dcebd45cecab04c70cff0c2 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sun, 27 Nov 2022 09:38:54 +0100 Subject: [PATCH 3/6] Set version to 10.1.0 (#5848) --- jscomp/common/bs_version.ml | 2 +- lib/4.06.1/rescript.ml | 2 +- lib/4.06.1/unstable/js_compiler.ml | 2 +- lib/4.06.1/unstable/js_playground_compiler.ml | 2 +- lib/4.06.1/whole_compiler.ml | 2 +- package-lock.json | 4 ++-- package.json | 2 +- packages/std/package.json | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/jscomp/common/bs_version.ml b/jscomp/common/bs_version.ml index da837bc8c9..c82bfebc25 100644 --- a/jscomp/common/bs_version.ml +++ b/jscomp/common/bs_version.ml @@ -21,6 +21,6 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let version = "10.1.0-rc.5" +let version = "10.1.0" let header = "// Generated by ReScript, PLEASE EDIT WITH CARE" let package_name = ref "rescript" diff --git a/lib/4.06.1/rescript.ml b/lib/4.06.1/rescript.ml index 63020b96bd..7ba543d166 100644 --- a/lib/4.06.1/rescript.ml +++ b/lib/4.06.1/rescript.ml @@ -4537,7 +4537,7 @@ end = struct * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let version = "10.1.0-rc.5" +let version = "10.1.0" let header = "// Generated by ReScript, PLEASE EDIT WITH CARE" let package_name = ref "rescript" diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 05e5c1e98c..e971690657 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -17685,7 +17685,7 @@ end = struct * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let version = "10.1.0-rc.5" +let version = "10.1.0" let header = "// Generated by ReScript, PLEASE EDIT WITH CARE" let package_name = ref "rescript" diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index d695518b4f..0b153a7e56 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -17685,7 +17685,7 @@ end = struct * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let version = "10.1.0-rc.5" +let version = "10.1.0" let header = "// Generated by ReScript, PLEASE EDIT WITH CARE" let package_name = ref "rescript" diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index dabce93269..e34b64f9f9 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -181875,7 +181875,7 @@ end = struct * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let version = "10.1.0-rc.5" +let version = "10.1.0" let header = "// Generated by ReScript, PLEASE EDIT WITH CARE" let package_name = ref "rescript" diff --git a/package-lock.json b/package-lock.json index fe10281e8f..c5c746a060 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rescript", - "version": "10.1.0-rc.5", + "version": "10.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rescript", - "version": "10.1.0-rc.5", + "version": "10.1.0", "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", "bin": { diff --git a/package.json b/package.json index aefb265e44..057836f40e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rescript", - "version": "10.1.0-rc.5", + "version": "10.1.0", "devDependencies": { "mocha": "^7.2.0", "nyc": "^15.0.0", diff --git a/packages/std/package.json b/packages/std/package.json index 97429b042a..23e9df180b 100644 --- a/packages/std/package.json +++ b/packages/std/package.json @@ -1,6 +1,6 @@ { "name": "@rescript/std", - "version": "10.1.0-rc.5", + "version": "10.1.0", "keywords": [ "rescript", "stdlib", From 4ec855e058410f3b3e05ba6a193cf7e4a4ff0039 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Mon, 28 Nov 2022 14:02:11 +0100 Subject: [PATCH 4/6] Set version to 10.1.1 (#5859) --- jscomp/common/bs_version.ml | 2 +- lib/4.06.1/rescript.ml | 2 +- lib/4.06.1/unstable/js_compiler.ml | 2 +- lib/4.06.1/unstable/js_playground_compiler.ml | 2 +- lib/4.06.1/whole_compiler.ml | 2 +- package-lock.json | 4 ++-- package.json | 2 +- packages/std/package.json | 2 +- 8 files changed, 9 insertions(+), 9 deletions(-) diff --git a/jscomp/common/bs_version.ml b/jscomp/common/bs_version.ml index c82bfebc25..6a9bf3bcc7 100644 --- a/jscomp/common/bs_version.ml +++ b/jscomp/common/bs_version.ml @@ -21,6 +21,6 @@ * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let version = "10.1.0" +let version = "10.1.1" let header = "// Generated by ReScript, PLEASE EDIT WITH CARE" let package_name = ref "rescript" diff --git a/lib/4.06.1/rescript.ml b/lib/4.06.1/rescript.ml index 7ba543d166..191c0a80a3 100644 --- a/lib/4.06.1/rescript.ml +++ b/lib/4.06.1/rescript.ml @@ -4537,7 +4537,7 @@ end = struct * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let version = "10.1.0" +let version = "10.1.1" let header = "// Generated by ReScript, PLEASE EDIT WITH CARE" let package_name = ref "rescript" diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index e971690657..584087a49d 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -17685,7 +17685,7 @@ end = struct * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let version = "10.1.0" +let version = "10.1.1" let header = "// Generated by ReScript, PLEASE EDIT WITH CARE" let package_name = ref "rescript" diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index 0b153a7e56..00faec4f80 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -17685,7 +17685,7 @@ end = struct * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let version = "10.1.0" +let version = "10.1.1" let header = "// Generated by ReScript, PLEASE EDIT WITH CARE" let package_name = ref "rescript" diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index e34b64f9f9..962940b980 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -181875,7 +181875,7 @@ end = struct * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -let version = "10.1.0" +let version = "10.1.1" let header = "// Generated by ReScript, PLEASE EDIT WITH CARE" let package_name = ref "rescript" diff --git a/package-lock.json b/package-lock.json index c5c746a060..28cdb61917 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "rescript", - "version": "10.1.0", + "version": "10.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "rescript", - "version": "10.1.0", + "version": "10.1.1", "hasInstallScript": true, "license": "SEE LICENSE IN LICENSE", "bin": { diff --git a/package.json b/package.json index 057836f40e..c316303c3d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "rescript", - "version": "10.1.0", + "version": "10.1.1", "devDependencies": { "mocha": "^7.2.0", "nyc": "^15.0.0", diff --git a/packages/std/package.json b/packages/std/package.json index 23e9df180b..706f48d1b5 100644 --- a/packages/std/package.json +++ b/packages/std/package.json @@ -1,6 +1,6 @@ { "name": "@rescript/std", - "version": "10.1.0", + "version": "10.1.1", "keywords": [ "rescript", "stdlib", From eab526d30cc243b3b5ee5e73bd85d781c521abd4 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Mon, 28 Nov 2022 11:46:54 +0100 Subject: [PATCH 5/6] Fix two more cases of async inline. --- jscomp/core/js_pass_tailcall_inline.ml | 2 +- jscomp/core/lam_pass_remove_alias.ml | 8 ++++++-- jscomp/test/async_inline.js | 8 ++++++++ jscomp/test/async_inline.res | 10 ++++++++++ lib/4.06.1/unstable/js_compiler.ml | 10 +++++++--- lib/4.06.1/unstable/js_playground_compiler.ml | 10 +++++++--- lib/4.06.1/whole_compiler.ml | 10 +++++++--- 7 files changed, 46 insertions(+), 12 deletions(-) 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 f7e4253932..b56ea1826b 100644 --- a/jscomp/core/lam_pass_remove_alias.ml +++ b/jscomp/core/lam_pass_remove_alias.ml @@ -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 -> @@ -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... diff --git a/jscomp/test/async_inline.js b/jscomp/test/async_inline.js index f9b240b196..917e89991e 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); } @@ -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 */ diff --git a/jscomp/test/async_inline.res b/jscomp/test/async_inline.res index f8dd74a9a2..fa7da47385 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 584087a49d..5a0a5f5c34 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -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 ); @@ -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 -> @@ -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... diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index 00faec4f80..956cbf991d 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -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 ); @@ -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 -> @@ -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... diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 962940b980..c68f33d3b9 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -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 ); @@ -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 -> @@ -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... From 039c4db06ea451ba10958cc1f3b84d09b63eb31a Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Mon, 28 Nov 2022 13:13:46 +0100 Subject: [PATCH 6/6] CHANGELOG --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5285ba1e5d..637b2f2a8c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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