Skip to content
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

Ignore -uncurried compiler flag. #6885

Merged
merged 2 commits into from
Jul 18, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
- Avoid generating calls to Curry when adjusting arity of uncurried functions. https://github.com/rescript-lang/rescript-compiler/pull/6870
- Remove `@@uncurried.swap`, which was used for internal tests. https://github.com/rescript-lang/rescript-compiler/pull/6875
- Build the compiler libraries/tests in uncurried mode. https://github.com/rescript-lang/rescript-compiler/pull/6864
- Ignore `-uncurried` command-line flag. https://github.com/rescript-lang/rescript-compiler/pull/6885

#### :nail_care: Polish

Expand Down
8 changes: 2 additions & 6 deletions jscomp/bsc/rescript_compiler_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ let process_file sourcefile ?(kind ) ppf =
The {!Location.input_name} relies on that we write the binary ast
properly
*)
let uncurried = !Config.uncurried in
setup_outcome_printer ();
let kind =
match kind with
Expand Down Expand Up @@ -78,11 +77,9 @@ let process_file sourcefile ?(kind ) ppf =
| Unknown ->
Bsc_args.bad_arg ("don't know what to do with " ^ sourcefile)
in
Config.uncurried := uncurried;
res

let reprint_source_file sourcefile =
let uncurried = !Config.uncurried in
let kind = Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile) in
let sourcefile = set_abs_input_name sourcefile in
let res = match kind with
Expand Down Expand Up @@ -119,7 +116,6 @@ let reprint_source_file sourcefile =
print_endline ("Invalid input for reprinting ReScript source. Must be a ReScript file: " ^ sourcefile);
exit 2
in
Config.uncurried := uncurried;
res

let usage = "Usage: bsc <options> <files>\nOptions are:"
Expand Down Expand Up @@ -406,8 +402,8 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =

"-nopervasives", set Clflags.nopervasives,
"*internal*";
"-uncurried", unit_call (fun () -> Config.uncurried := Uncurried),
"*internal* Set jsx module";
"-uncurried", unit_call (fun () -> ()),
"*internal* deprecated";
"-v", unit_call print_version_string,
"Print compiler version and location of standard library and exit";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
2 [2m│[0m let _ = string_of_float(34.)
3 [2m│[0m let _ = string_of_float(34.)

deprecated: PervasivesU.string_of_float
deprecated: Pervasives.string_of_float
Please use Js.Float.toString instead, string_of_float generates unparseable floats


Expand All @@ -18,7 +18,7 @@
3 [2m│[0m let _ = string_of_float(34.)
4 [2m│[0m

deprecated: PervasivesU.string_of_float
deprecated: Pervasives.string_of_float
Please use Js.Float.toString instead, string_of_float generates unparseable floats


Expand All @@ -30,5 +30,5 @@
[1;33m3[0m [2m│[0m let _ = [1;33mstring_of_float[0m(34.)
4 [2m│[0m

deprecated: PervasivesU.string_of_float
deprecated: Pervasives.string_of_float
Please use Js.Float.toString instead, string_of_float generates unparseable floats
2 changes: 1 addition & 1 deletion jscomp/build_tests/super_errors/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const fixtures = fs
.filter(fileName => path.extname(fileName) === ".res");

// const runtime = path.join(__dirname, '..', '..', 'runtime')
const prefix = `${bsc} -w +A -uncurried`;
const prefix = `${bsc} -w +A`;

const updateTests = process.argv[2] === "update";

Expand Down
15 changes: 0 additions & 15 deletions jscomp/build_tests/uncurried_printer/input.js

This file was deleted.

6 changes: 0 additions & 6 deletions jscomp/build_tests/uncurried_printer/rescript.json

This file was deleted.

1 change: 0 additions & 1 deletion jscomp/build_tests/uncurried_printer/src/a.res

This file was deleted.

2 changes: 1 addition & 1 deletion jscomp/core/res_compmisc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ let initial_env ?(modulename) () =
let initial = Env.initial_safe_string in
let env =
if !Clflags.nopervasives then initial
else open_implicit_module (if !Config.uncurried = Uncurried then "PervasivesU" else "Pervasives") initial
else open_implicit_module "Pervasives" initial
in
List.fold_left
(fun env m -> open_implicit_module m env)
Expand Down
3 changes: 1 addition & 2 deletions jscomp/ext/config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ let bs_only = ref true
let unsafe_empty_array = ref false

type uncurried = Legacy | Uncurried
let uncurried = ref Legacy

and cmi_magic_number = "Caml1999I022"
let cmi_magic_number = "Caml1999I022"

and ast_impl_magic_number = "Caml1999M022"

Expand Down
1 change: 0 additions & 1 deletion jscomp/ext/config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ val cmt_magic_number : string
val print_config : out_channel -> unit

type uncurried = Legacy | Uncurried
val uncurried : uncurried ref
7 changes: 2 additions & 5 deletions jscomp/frontend/ast_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,16 +188,13 @@ let iter_process_bs_string_int_unwrap_uncurry (attrs : t) =
st := v)
else Bs_syntaxerr.err loc Conflict_attributes
in
Ext_list.iter attrs (fun (({txt; loc = _}, (payload : _)) as attr) ->
Ext_list.iter attrs (fun (({txt; loc = _}, _) as attr) ->
match txt with
| "string" -> assign `String attr
| "int" -> assign `Int attr
| "ignore" -> assign `Ignore attr
| "unwrap" -> assign `Unwrap attr
| "uncurry" ->
if !Config.uncurried = Uncurried then
Used_attributes.mark_used_attribute attr
else assign (`Uncurry (Ast_payload.is_single_int payload)) attr
| "uncurry" -> Used_attributes.mark_used_attribute attr
| _ -> ());
!st

Expand Down
2 changes: 0 additions & 2 deletions jscomp/frontend/ast_config.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ let process_directives str =
match Ast_payload.is_single_string payload with
| Some (d, _) -> Js_config.directives := !Js_config.directives @ [d]
| None -> Bs_syntaxerr.err item.pstr_loc Expect_string_literal)
| Pstr_attribute ({txt = "uncurried"}, _) ->
Config.uncurried := Uncurried
| _ -> ())

let rec iter_on_bs_config_str (x : Parsetree.structure) =
Expand Down
13 changes: 4 additions & 9 deletions jscomp/frontend/ast_derive_projector.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ let init () =
(fun (tdcls : tdcls) _explict_nonrec ->
let handle_uncurried_accessor_tranform ~loc ~arity accessor =
(* Accessors with no params (arity of 0) are simply values and not functions *)
match Config.uncurried.contents with
| Uncurried when arity > 0 ->
Ast_uncurried.uncurried_fun ~loc ~arity accessor
| _ -> accessor
if arity > 0 then Ast_uncurried.uncurried_fun ~loc ~arity accessor
else accessor
in
let handle_tdcl tdcl =
let core_type =
Expand Down Expand Up @@ -121,11 +119,8 @@ let init () =
signature_gen =
(fun (tdcls : Parsetree.type_declaration list) _explict_nonrec ->
let handle_uncurried_type_tranform ~loc ~arity t =
match Config.uncurried.contents with
(* Accessors with no params (arity of 0) are simply values and not functions *)
| Uncurried when arity > 0 ->
Ast_uncurried.uncurried_type ~loc ~arity t
| _ -> t
if arity > 0 then Ast_uncurried.uncurried_type ~loc ~arity t
else t
in
let handle_tdcl tdcl =
let core_type =
Expand Down
4 changes: 2 additions & 2 deletions jscomp/gentype/TranslateTypeExprFromTypes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
{param_translation with type_ = Array (param_translation.type_, Mutable)}
| ["ImmutableArray"; "t"], [param_translation] ->
{param_translation with type_ = Array (param_translation.type_, Immutable)}
| [("Pervasives" | "PervasivesU"); "ref"], [param_translation] ->
| ["Pervasives"; "ref"], [param_translation] ->
{
dependencies = param_translation.dependencies;
type_ =
Expand Down Expand Up @@ -217,7 +217,7 @@ let translate_constr ~config ~params_translation ~(path : Path.t) ~type_env =
| ( ( ["React"; "element"]
| ["ReactV3"; "React"; "element"]
| ["ReasonReact"; "reactElement"]
| [("Pervasives" | "PervasivesU"); "Jsx"; "element"] ),
| ["Pervasives"; "Jsx"; "element"] ),
[] ) ->
{dependencies = []; type_ = EmitType.type_react_element}
| (["FB"; "option"] | ["option"]), [param_translation] ->
Expand Down
9 changes: 0 additions & 9 deletions jscomp/jsoo/jsoo_playground_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,13 @@ module BundleConfig = struct
mutable filename: string option;
mutable warn_flags: string;
mutable open_modules: string list;

(* This one can't be mutated since we only provide
third-party packages that were compiled for uncurried
mode *)
uncurried: bool;
}

let make () = {
module_system=Ext_module_system.Commonjs;
filename=None;
warn_flags=Bsc_warnings.defaults_w;
open_modules=[];
uncurried=(!Config.uncurried = Uncurried);
}


Expand Down Expand Up @@ -201,8 +195,6 @@ end
(* One time setup for all relevant modules *)
let () =
Bs_conditional_initial.setup_env ();
(* From now on the default setting will be uncurried mode *)
Config.uncurried := Uncurried;
Clflags.binary_annotations := false;
Clflags.color := Some Always;
Lazy.force Res_outcome_printer.setup
Expand Down Expand Up @@ -646,7 +638,6 @@ module Export = struct
);
"warn_flags",
inject @@ (Js.string config.warn_flags);
"uncurried", inject @@ (Js.bool config.uncurried);
"open_modules", inject @@ (config.open_modules |> Array.of_list |> Js.array);
|]))
);
Expand Down
2 changes: 1 addition & 1 deletion jscomp/ml/ctype.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2329,7 +2329,7 @@ and unify3 env t1 t1' t2 t2' =
link_type t2' t1;
| (Tfield _, Tfield _) -> (* special case for GADTs *)
unify_fields env t1' t2'
| (Tconstr (Pident {name="function$"}, [t_fun; _], _), Tarrow _) when !Config.uncurried = Uncurried ->
| (Tconstr (Pident {name="function$"}, [t_fun; _], _), Tarrow _) ->
(* subtype: an uncurried function is cast to a curried one *)
unify2 env t_fun t2
| _ ->
Expand Down
3 changes: 1 addition & 2 deletions jscomp/ml/printtyp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ let ident ppf id = pp_print_string ppf (ident_name id)
(* Print a path *)

let ident_pervasives = Ident.create_persistent "Pervasives"
let ident_pervasives_u = Ident.create_persistent "PervasivesU"
let printing_env = ref Env.empty
let non_shadowed_pervasive = function
| Pdot(Pident id, s, _pos) as path ->
(Ident.same id ident_pervasives || Ident.same id ident_pervasives_u) &&
(Ident.same id ident_pervasives) &&
(try Path.same path (Env.lookup_type (Lident s) !printing_env)
with Not_found -> true)
| _ -> false
Expand Down
1 change: 0 additions & 1 deletion jscomp/ml/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3076,7 +3076,6 @@ and type_argument ?type_clash_context ?recarg env sarg ty_expected' ty_expected
texp
and is_automatic_curried_application env funct =
(* When a curried function is used with uncurried application, treat it as a curried application *)
!Config.uncurried = Uncurried &&
match (expand_head env funct.exp_type).desc with
| Tarrow _ -> true
| _ -> false
Expand Down
2 changes: 1 addition & 1 deletion jscomp/others/release.ninja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

bsc_primitive_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A -uncurried
bsc_primitive_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A
bsc_flags = $bsc_primitive_flags -open Belt_internals

rule cc
Expand Down
4 changes: 2 additions & 2 deletions jscomp/runtime/release.ninja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

bsc_no_open_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A -uncurried
bsc_no_open_flags = -no-keep-locs -no-alias-deps -bs-no-version-header -bs-no-check-div-by-zero -nostdlib -bs-cross-module-opt -make-runtime -nopervasives -unsafe -w +50 -warn-error A
bsc_flags = $bsc_no_open_flags -open Bs_stdlib_mini

rule cc
Expand All @@ -10,7 +10,7 @@ rule cc_cmi
description = $in -> $out

o runtime/bs_stdlib_mini.cmi : cc runtime/bs_stdlib_mini.resi
bsc_flags = -nostdlib -nopervasives -uncurried
bsc_flags = -nostdlib -nopervasives
o runtime/js.cmj runtime/js.cmi : cc runtime/js.res
bsc_flags = $bsc_no_open_flags
o runtime/caml.cmj : cc_cmi runtime/caml.res | runtime/caml.cmi runtime/caml_int64_extern.cmj
Expand Down
Loading