Skip to content

Cherry pick fixes for 11.1.3 #6913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@
> - :house: [Internal]
> - :nail_care: [Polish]

# 11.1.3

#### :bug: Bug Fix

- Fix tag function location on compiler error. https://github.com/rescript-lang/rescript-compiler/pull/6816
- Fix Deno compatibility issues on Windows. https://github.com/rescript-lang/rescript-compiler/pull/6850
- Fix issue with infinite loops with type errors on recursive types. https://github.com/rescript-lang/rescript-compiler/pull/6867
- Ignore `@uncurry` attribute in uncurried mode, to avoid generating calls to `Curry` at runtime. https://github.com/rescript-lang/rescript-compiler/pull/6869
- Avoid generating calls to Curry when adjusting arity of uncurried functions. https://github.com/rescript-lang/rescript-compiler/pull/6870
- Fix build after calling without `-warn-error`, see https://github.com/rescript-lang/rescript-compiler/issues/6868 for more details. https://github.com/rescript-lang/rescript-compiler/pull/6877
- Fix issue with uninitialized `_param` in recursive functions with unit argument. https://github.com/rescript-lang/rescript-compiler/pull/6907

# 11.1.3-rc.1

#### :bug: Bug Fix
Expand Down
15 changes: 11 additions & 4 deletions jscomp/bsb/bsb_ninja_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type check_result =
| Bsb_bsc_version_mismatch
| Bsb_forced
| Bsb_package_kind_inconsistent
| Bsb_regenerate_required
| Other of string

let pp_check_result fmt (check_resoult : check_result) =
Expand All @@ -55,6 +56,7 @@ let pp_check_result fmt (check_resoult : check_result) =
| Bsb_bsc_version_mismatch -> "Bsc or bsb version mismatch"
| Bsb_forced -> "Bsb forced rebuild"
| Bsb_package_kind_inconsistent -> "The package was built in different mode"
| Bsb_regenerate_required -> "Bsb need regenerate build.ninja"
| Other s -> s)

let rec check_aux cwd (xs : string list) =
Expand Down Expand Up @@ -91,13 +93,14 @@ let record_global_atime buf name =
Ext_buffer.add_string_char buf (hex_of_float stamp) '\n'

let record ~(package_kind : Bsb_package_kind.t) ~per_proj_dir ~file
~(config : Bsb_config_types.t) (file_or_dirs : string list) : unit =
~(config : Bsb_config_types.t) ~(warn_as_error: string option) (file_or_dirs : string list) : unit =
let buf = Ext_buffer.create 1_000 in
Ext_buffer.add_string_char buf Bs_version.version '\n';
Ext_buffer.add_string_char buf per_proj_dir '\n';
Ext_buffer.add_string_char buf
(Bsb_package_kind.encode_no_nl package_kind)
'\n';
Ext_buffer.add_string_char buf (match warn_as_error with | Some s -> s | None -> "0") '\n';
Ext_list.iter file_or_dirs (fun f ->
Ext_buffer.add_string_char buf f '\t';
Ext_buffer.add_string_char buf
Expand All @@ -119,21 +122,25 @@ let record ~(package_kind : Bsb_package_kind.t) ~per_proj_dir ~file
Even forced, we still need walk through a little
bit in case we found a different version of compiler
*)
let check ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string) ~forced
~file : check_result =
let check ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string) ~forced ~(warn_as_error: string option) ~file : check_result =
match open_in_bin file with
(* Windows binary mode*)
| exception _ -> Bsb_file_not_exist
| ic -> (
match List.rev (Ext_io.rev_lines_of_chann ic) with
| exception _ -> Bsb_file_corrupted
| version :: source_directory :: package_kind_str :: dir_or_files -> (
| version :: source_directory :: package_kind_str :: previous_warn_as_error :: dir_or_files -> (
let warn_as_error_changed = match warn_as_error with
| None -> previous_warn_as_error <> "0"
| Some current -> current <> previous_warn_as_error in

if version <> Bs_version.version then Bsb_bsc_version_mismatch
else if per_proj_dir <> source_directory then
Bsb_source_directory_changed
else if forced then Bsb_forced (* No need walk through *)
else if Bsb_package_kind.encode_no_nl package_kind <> package_kind_str
then Bsb_package_kind_inconsistent
else if warn_as_error_changed then Bsb_regenerate_required
else
try check_aux per_proj_dir dir_or_files
with e ->
Expand Down
3 changes: 3 additions & 0 deletions jscomp/bsb/bsb_ninja_check.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type check_result =
| Bsb_bsc_version_mismatch
| Bsb_forced
| Bsb_package_kind_inconsistent
| Bsb_regenerate_required
| Other of string

val pp_check_result : Format.formatter -> check_result -> unit
Expand All @@ -47,6 +48,7 @@ val record :
per_proj_dir:string ->
file:string ->
config:Bsb_config_types.t ->
warn_as_error:string option ->
string list ->
unit
(** [record cwd file relevant_file_or_dirs]
Expand All @@ -64,6 +66,7 @@ val check :
package_kind:Bsb_package_kind.t ->
per_proj_dir:string ->
forced:bool ->
warn_as_error: string option ->
file:string ->
check_result
(** check if [build.ninja] should be regenerated *)
5 changes: 3 additions & 2 deletions jscomp/bsb/bsb_ninja_regen.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir
let lib_bs_dir = per_proj_dir // lib_artifacts_dir in
let output_deps = lib_bs_dir // bsdeps in
let check_result =
Bsb_ninja_check.check ~package_kind ~per_proj_dir ~forced ~file:output_deps
Bsb_ninja_check.check ~package_kind ~per_proj_dir ~forced ~warn_as_error ~file:output_deps
in
let config_filename, config_json =
Bsb_config_load.load_json ~per_proj_dir ~warn_legacy_config
Expand All @@ -45,6 +45,7 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir
| Good -> None (* Fast path, no need regenerate ninja *)
| Bsb_forced | Bsb_bsc_version_mismatch | Bsb_package_kind_inconsistent
| Bsb_file_corrupted | Bsb_file_not_exist | Bsb_source_directory_changed
| Bsb_regenerate_required
| Other _ ->
Bsb_log.info "@{<info>BSB check@} build spec : %a @."
Bsb_ninja_check.pp_check_result check_result;
Expand Down Expand Up @@ -94,7 +95,7 @@ let regenerate_ninja ~(package_kind : Bsb_package_kind.t) ~forced ~per_proj_dir
config;
(* PR2184: we still need record empty dir
since it may add files in the future *)
Bsb_ninja_check.record ~package_kind ~per_proj_dir ~config
Bsb_ninja_check.record ~package_kind ~per_proj_dir ~config ~warn_as_error
~file:output_deps
(config.filename :: config.file_groups.globbed_dirs);
Some config
46 changes: 41 additions & 5 deletions jscomp/build_tests/build_warn_as_error/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,52 @@ var p = require("child_process");
var assert = require("assert");
var rescript_exe = require("../../../scripts/bin_path").rescript_exe;

var o = p.spawnSync(rescript_exe, ["build", "-warn-error", "+110"], {
var o1 = p.spawnSync(rescript_exe, ["build"], {
encoding: "utf8",
cwd: __dirname,
});

var error_message = o.stdout
var first_message = o1.stdout
.split("\n")
.map(s => s.trim())
.includes("Warning number 110 (configured as error)");
.find(s => s == "Warning number 110");

if (!error_message) {
assert.fail(o.stdout);
if (!first_message) {
assert.fail(o1.stdout);
}

// Second build using -warn-error +110
var o2 = p.spawnSync(rescript_exe, ["build", "-warn-error", "+110"], {
encoding: "utf8",
cwd: __dirname,
});

var second_message = o2.stdout
.split("\n")
.map(s => s.trim())
.find(s => s == "Warning number 110 (configured as error)");

if (!second_message) {
assert.fail(o2.stdout);
}

// Third build, without -warn-error +110
// The result should not be a warning as error
var o3 = p.spawnSync(rescript_exe, ["build"], {
encoding: "utf8",
cwd: __dirname,
});

var third_message = o3.stdout
.split("\n")
.map(s => s.trim())
.find(s => s == "Dependency Finished");

if (!third_message) {
assert.fail(o3.stdout);
}

var cleanup = p.spawnSync(rescript_exe, ["clean"], {
encoding: "utf8",
cwd: __dirname,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

We've found a bug for you!
/.../fixtures/recursive_type.res:35:11-14

33 │ /* parse atom */
34 │ and atom = (k, t) => {
35 │ let _ = atom(k)
36 │ assert(false)
37 │ }

This uncurried function has type
((option<'a>, ([> #List(list<'b>)] as 'b)) => 'c, 'd) => 'c
It is applied with 1 arguments but it requires 2.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

We've found a bug for you!
/.../fixtures/unknown_tagged_template_function.res:1:11-14

1 │ let res = tagg`| 5 × 10 = ${5} |`

The value tagg can't be found
37 changes: 37 additions & 0 deletions jscomp/build_tests/super_errors/fixtures/recursive_type.res
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
@@uncurried

// test.res
type rec tt = [
| #List(list<tt>)
]
type sexp = tt

/* {2 Serialization (encoding)} */


let rec expr_starting_with = (c, k, t) =>
switch c {
| '(' => expr_list(list{}, k, t)
| c => atom(k, t)
}

/* parse list */
and expr_list = (acc, k, t) => {
switch assert(false) {
| ')' => k(None, #List(acc))
| c =>
expr_starting_with(
c,
(last, e) =>
switch last {
| _ => expr_list(list{e, ...acc}, k, t)
},
t,
)
}
}
/* parse atom */
and atom = (k, t) => {
let _ = atom(k)
assert(false)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
let res = tagg`| 5 × 10 = ${5} |`
2 changes: 1 addition & 1 deletion jscomp/common/bs_version.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "11.1.3-rc.1"
let version = "11.1.3"
let header = "// Generated by ReScript, PLEASE EDIT WITH CARE"
let package_name = ref "rescript"
1 change: 1 addition & 0 deletions jscomp/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ and compile_recursive_let ~all_bindings (cxt : Lam_compile_context.t)
]}
[Alias] may not be exact
*)
let params = if oneUnitArg then [] else params in
let ret : Lam_compile_context.return_label =
{
id;
Expand Down
6 changes: 5 additions & 1 deletion jscomp/core/lam_eta_conversion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,13 @@ let unsafe_adjust_to_arity loc ~(to_ : int) ?(from : int option) (fn : Lam.t) :
let extra_args =
Ext_list.init (to_ - from) (fun _ -> Ident.create Literals.param)
in
let rec mk_apply body vars = match vars with
| [] -> body
| var :: vars ->
mk_apply (Lam.apply body [var] ap_info) vars in
Lam.function_ ~attr:Lambda.default_function_attribute ~arity:to_
~params:(Ext_list.append params extra_args)
~body:(Lam.apply body (Ext_list.map extra_args Lam.var) ap_info)
~body:(mk_apply body (Ext_list.map extra_args Lam.var))
| _ -> (
let arity = to_ in
let extra_args =
Expand Down
4 changes: 3 additions & 1 deletion jscomp/frontend/ast_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ let iter_process_bs_string_int_unwrap_uncurry (attrs : t) =
| "bs.ignore" | "ignore" -> assign `Ignore attr
| "bs.unwrap" | "unwrap" -> assign `Unwrap attr
| "bs.uncurry" | "uncurry" ->
assign (`Uncurry (Ast_payload.is_single_int payload)) attr
if !Config.uncurried = Uncurried then
Bs_ast_invariant.mark_used_bs_attribute attr
else assign (`Uncurry (Ast_payload.is_single_int payload)) attr
| _ -> ());
!st

Expand Down
25 changes: 12 additions & 13 deletions jscomp/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3798,7 +3798,13 @@ let spellcheck_idents ppf unbound valid_idents =
spellcheck ppf (Ident.name unbound) (List.map Ident.name valid_idents)

open Format
open Printtyp
let longident = Printtyp.longident
let super_report_unification_error = Printtyp.super_report_unification_error
let report_ambiguous_type_error = Printtyp.report_ambiguous_type_error
let report_subtyping_error = Printtyp.report_subtyping_error
let type_expr ppf typ = (* print a type and avoid infinite loops *)
Printtyp.reset_and_mark_loops typ;
Printtyp.type_expr ppf typ

let report_error env ppf = function
| Polymorphic_label lid ->
Expand Down Expand Up @@ -3867,7 +3873,6 @@ let report_error env ppf = function
fprintf ppf "@]"
| Apply_non_function typ ->
(* modified *)
reset_and_mark_loops typ;
begin match (repr typ).desc with
Tarrow (_, _inputType, returnType, _) ->
let rec countNumberOfArgs count {Types.desc} = match desc with
Expand All @@ -3891,7 +3896,6 @@ let report_error env ppf = function
| l ->
fprintf ppf "with label %s" (prefixed_label_name l)
in
reset_and_mark_loops ty;
fprintf ppf
"@[<v>@[<2>The function applied to this argument has type@ %a@]@.\
This argument cannot be applied %a@]"
Expand All @@ -3908,7 +3912,6 @@ let report_error env ppf = function
fprintf ppf "The record field %a is not mutable" longident lid
| Wrong_name (eorp, ty, kind, p, name, valid_names) ->
(* modified *)
reset_and_mark_loops ty;
if Path.is_constructor_typath p then begin
fprintf ppf "@[The field %s is not part of the record \
argument for the %a constructor@]"
Expand Down Expand Up @@ -3940,7 +3943,6 @@ let report_error env ppf = function
fprintf ppf "but a %s was expected belonging to the %s type"
name kind)
| Undefined_method (ty, me, valid_methods) ->
reset_and_mark_loops ty;
fprintf ppf
"@[<v>@[This expression has type@;<1 2>%a@]@,\
It has no field %s@]" type_expr ty me;
Expand All @@ -3966,7 +3968,6 @@ let report_error env ppf = function
"Consider using a double coercion."
| Too_many_arguments (in_function, ty) ->
(* modified *)
reset_and_mark_loops ty;
if in_function then begin
fprintf ppf "@[This function expects too many arguments,@ ";
fprintf ppf "it should have type@ %a@]"
Expand All @@ -3985,11 +3986,9 @@ let report_error env ppf = function
| Nolabel -> "but its first argument is not labelled"
| l -> sprintf "but its first argument is labelled %s"
(prefixed_label_name l) in
reset_and_mark_loops ty;
fprintf ppf "@[<v>@[<2>This function should have type@ %a@]@,%s@]"
type_expr ty (label_mark l)
| Scoping_let_module(id, ty) ->
reset_and_mark_loops ty;
fprintf ppf
"This `let module' expression has type@ %a@ " type_expr ty;
fprintf ppf
Expand Down Expand Up @@ -4031,7 +4030,7 @@ let report_error env ppf = function
"Unexpected existential"
| Unqualified_gadt_pattern (tpath, name) ->
fprintf ppf "@[The GADT constructor %s of type %a@ %s.@]"
name path tpath
name Printtyp.path tpath
"must be qualified in this pattern"
| Invalid_interval ->
fprintf ppf "@[Only character intervals are supported in patterns.@]"
Expand Down Expand Up @@ -4082,20 +4081,20 @@ let report_error env ppf = function
fprintf ppf "Empty record literal {} should be type annotated or used in a record context."
| Uncurried_arity_mismatch (typ, arity, args) ->
fprintf ppf "@[<v>@[<2>This uncurried function has type@ %a@]"
type_expr typ;
type_expr typ;
fprintf ppf "@ @[It is applied with @{<error>%d@} argument%s but it requires @{<info>%d@}.@]@]"
args (if args = 0 then "" else "s") arity
| Field_not_optional (name, typ) ->
fprintf ppf
"Field @{<info>%s@} is not optional in type %a. Use without ?" name
type_expr typ
"Field @{<info>%s@} is not optional in type %a. Use without ?" name
type_expr typ


let super_report_error_no_wrap_printing_env = report_error


let report_error env ppf err =
wrap_printing_env env (fun () -> report_error env ppf err)
Printtyp.wrap_printing_env env (fun () -> report_error env ppf err)

let () =
Location.register_error_of_exn
Expand Down
Loading