Skip to content

Commit a1d7364

Browse files
committed
Move all the uncurried config to module Config.
The Config module is used by the compiler, so the `uncurried` setting needs to be reset on each file as tests compile several files on a single command line (actual project builds don't).
1 parent d07a9ec commit a1d7364

13 files changed

+27
-25
lines changed

jscomp/bsc/rescript_compiler_main.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ let process_file sourcefile ?(kind ) ppf =
5151
The {!Location.input_name} relies on that we write the binary ast
5252
properly
5353
*)
54+
let uncurried = !Config.uncurried in
5455
let kind =
5556
match kind with
5657
| None -> Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile)
5758
| Some kind -> kind in
58-
match kind with
59+
let res = match kind with
5960
| Ml ->
6061
let sourcefile = set_abs_input_name sourcefile in
6162
setup_compiler_printer `ml;
@@ -103,6 +104,9 @@ let process_file sourcefile ?(kind ) ppf =
103104
Format.pp_print_newline Format.std_formatter ()
104105
| Unknown ->
105106
Bsc_args.bad_arg ("don't know what to do with " ^ sourcefile)
107+
in
108+
Config.uncurried := uncurried;
109+
res
106110
let usage = "Usage: bsc <options> <files>\nOptions are:"
107111

108112
let ppf = Format.err_formatter
@@ -406,7 +410,7 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
406410

407411
"-nopervasives", set Clflags.nopervasives,
408412
"*internal*";
409-
"-uncurried", unit_call (fun () -> Res_uncurried.init := Swap; Config.use_automatic_curried_application := true),
413+
"-uncurried", unit_call (fun () -> Config.uncurried := Uncurried),
410414
"*internal* Set jsx module";
411415
"-v", unit_call print_version_string,
412416
"Print compiler version and location of standard library and exit";

jscomp/core/res_compmisc.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let initial_env () =
4646
let initial = Env.initial_safe_string in
4747
let env =
4848
if !Clflags.nopervasives then initial
49-
else open_implicit_module (if !Config.use_automatic_curried_application then "PervasivesU" else "Pervasives") initial
49+
else open_implicit_module (if !Config.uncurried = Uncurried then "PervasivesU" else "Pervasives") initial
5050
in
5151
List.fold_left
5252
(fun env m -> open_implicit_module m env)

jscomp/ext/config.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ let bs_only = ref true
1313

1414
let unsafe_empty_array = ref false
1515

16-
let use_automatic_curried_application = ref false
16+
type uncurried = Legacy | Uncurried | Swap
17+
let uncurried = ref Legacy
1718

1819
and cmi_magic_number = "Caml1999I022"
1920

jscomp/ext/config.mli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,5 @@ val cmt_magic_number : string
4747

4848
val print_config : out_channel -> unit
4949

50-
val use_automatic_curried_application : bool ref
50+
type uncurried = Legacy | Uncurried | Swap
51+
val uncurried : uncurried ref

jscomp/frontend/ast_config.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ let process_directives str =
4444
| Pstr_attribute ({ txt = "directive" },
4545
PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) ->
4646
Js_config.directives := !Js_config.directives @ [d]
47-
| Pstr_attribute ({txt = "uncurried"}, _) -> Config.use_automatic_curried_application := true
47+
| Pstr_attribute ({txt = "uncurried"}, _) -> Config.uncurried := Uncurried
4848
| _ -> ())
4949

5050
let rec iter_on_bs_config_str (x : Parsetree.structure) =

jscomp/ml/ctype.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2341,7 +2341,7 @@ let rec unify (env:Env.t ref) t1 t2 =
23412341
with Cannot_expand ->
23422342
unify2 env t1 t2
23432343
end
2344-
| (Tconstr (Pident {name="function$"}, [tFun; _], _), Tarrow _) when !Config.use_automatic_curried_application ->
2344+
| (Tconstr (Pident {name="function$"}, [tFun; _], _), Tarrow _) when !Config.uncurried = Uncurried ->
23452345
(* subtype: an uncurried function is cast to a curried one *)
23462346
unify2 env tFun t2
23472347
| _ ->

jscomp/ml/typecore.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2980,7 +2980,7 @@ and type_argument ?recarg env sarg ty_expected' ty_expected =
29802980
texp
29812981
and is_automatic_curried_application env funct =
29822982
(* When a curried function is used with uncurried application, treat it as a curried application *)
2983-
!Config.use_automatic_curried_application &&
2983+
!Config.uncurried = Uncurried &&
29842984
match (expand_head env funct.exp_type).desc with
29852985
| Tarrow _ -> true
29862986
| _ -> false

res_syntax/src/res_core.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6409,10 +6409,10 @@ and parseStandaloneAttribute p =
64096409
let attrId =
64106410
match attrId.txt with
64116411
| "uncurried.swap" ->
6412-
p.uncurried_config <- Res_uncurried.Swap;
6412+
p.uncurried_config <- Config.Swap;
64136413
attrId
64146414
| "uncurried" ->
6415-
p.uncurried_config <- Res_uncurried.Uncurried;
6415+
p.uncurried_config <- Config.Uncurried;
64166416
attrId
64176417
| _ -> attrId
64186418
in

res_syntax/src/res_multi_printer.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let getUncurriedFromBsconfig ~filename =
4545
words |> List.exists (fun word -> word = "uncurried")
4646
&& words |> List.exists (fun word -> word = "true"))
4747
in
48-
if uncurried then Res_uncurried.init := Uncurried
48+
if uncurried then Config.uncurried := Uncurried
4949

5050
(* print res files to res syntax *)
5151
let printRes ~ignoreParseErrors ~isInterface ~filename =

res_syntax/src/res_parser.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type t = {
2222
mutable diagnostics: Diagnostics.t list;
2323
mutable comments: Comment.t list;
2424
mutable regions: regionStatus ref list;
25-
mutable uncurried_config: Res_uncurried.config;
25+
mutable uncurried_config: Config.uncurried;
2626
}
2727

2828
let err ?startPos ?endPos p error =
@@ -122,7 +122,7 @@ let make ?(mode = ParseForTypeChecker) src filename =
122122
diagnostics = [];
123123
comments = [];
124124
regions = [ref Report];
125-
uncurried_config = !Res_uncurried.init;
125+
uncurried_config = !Config.uncurried;
126126
}
127127
in
128128
parserState.scanner.err <-

res_syntax/src/res_parser.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type t = {
2121
mutable diagnostics: Diagnostics.t list;
2222
mutable comments: Comment.t list;
2323
mutable regions: regionStatus ref list;
24-
mutable uncurried_config: Res_uncurried.config;
24+
mutable uncurried_config: Config.uncurried;
2525
}
2626

2727
val make : ?mode:mode -> string -> string -> t

res_syntax/src/res_printer.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,9 @@ let printOptionalLabel attrs =
575575
module State = struct
576576
let customLayoutThreshold = 2
577577

578-
type t = {customLayout: int; mutable uncurried_config: Res_uncurried.config}
578+
type t = {customLayout: int; mutable uncurried_config: Config.uncurried}
579579

580-
let init () = {customLayout = 0; uncurried_config = !Res_uncurried.init}
580+
let init () = {customLayout = 0; uncurried_config = !Config.uncurried}
581581

582582
let nextCustomLayout t = {t with customLayout = t.customLayout + 1}
583583

@@ -5277,10 +5277,10 @@ and printAttribute ?(standalone = false) ~state
52775277
let id =
52785278
match id.txt with
52795279
| "uncurried.swap" ->
5280-
state.uncurried_config <- Res_uncurried.Swap;
5280+
state.uncurried_config <- Config.Swap;
52815281
id
52825282
| "uncurried" ->
5283-
state.uncurried_config <- Res_uncurried.Uncurried;
5283+
state.uncurried_config <- Config.Uncurried;
52845284
id
52855285
| _ -> id
52865286
in

res_syntax/src/res_uncurried.ml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,16 @@
1-
type config = Legacy | Swap | Uncurried
2-
3-
let init = ref Legacy
4-
51
let isSwap = function
6-
| Legacy -> false
2+
| Config.Legacy -> false
73
| Swap -> true
84
| Uncurried -> true
95

106
(* For parsing *)
117
let fromDotted ~dotted = function
12-
| Legacy -> dotted
8+
| Config.Legacy -> dotted
139
| Swap -> not dotted
1410
| Uncurried -> true
1511

1612
(* For printing *)
1713
let getDotted ~uncurried = function
18-
| Legacy -> uncurried
14+
| Config.Legacy -> uncurried
1915
| Swap -> not uncurried
2016
| Uncurried -> false

0 commit comments

Comments
 (0)