Skip to content

Commit 8010360

Browse files
authored
Merge pull request #4107 from BuckleScript/continue_support_custom_refmt
enable strict-sequence && better default warning/error handling
2 parents 000bcde + 3003c8d commit 8010360

File tree

101 files changed

+836
-2135
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+836
-2135
lines changed

jscomp/bsb/bsb_config_parse.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,18 @@ let extract_refmt (map : json_map) cwd : Bsb_config_types.refmt =
218218
match Map_string.find_opt map Bsb_build_schemas.refmt with
219219
| Some (Flo {flo} as config) ->
220220
begin match flo with
221-
| "3" -> Bsb_config_types.Refmt_v3
221+
| "3" -> None
222222
| _ -> Bsb_exception.config_error config "expect version 3 only"
223223
end
224224
| Some (Str {str})
225225
->
226-
Refmt_custom
226+
Some
227227
(Bsb_build_util.resolve_bsb_magic_file
228228
~cwd ~desc:Bsb_build_schemas.refmt str).path
229229
| Some config ->
230230
Bsb_exception.config_error config "expect version 2 or 3"
231231
| None ->
232-
Refmt_none
232+
None
233233

234234
let extract_string (map : json_map) (field : string) cb =
235235
match Map_string.find_opt map field with
@@ -268,7 +268,7 @@ let extract_reason_react_jsx (map : json_map) =
268268

269269
let extract_warning (map : json_map) =
270270
match Map_string.find_opt map Bsb_build_schemas.warnings with
271-
| None -> None
271+
| None -> Bsb_warning.use_default
272272
| Some (Obj {map }) -> Bsb_warning.from_map map
273273
| Some config -> Bsb_exception.config_error config "expect an object"
274274

jscomp/bsb/bsb_config_types.ml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ type reason_react_jsx =
4040
| Jsx_v3
4141
(* string option *)
4242

43-
type refmt =
44-
| Refmt_none
45-
| Refmt_v3
46-
| Refmt_custom of string
43+
type refmt = string option
4744

4845
type gentype_config = {
4946
path : string (* resolved *)
@@ -67,7 +64,7 @@ type t =
6764
bs_dependencies : dependencies;
6865
bs_dev_dependencies : dependencies;
6966
built_in_dependency : dependency option;
70-
warning : Bsb_warning.t option;
67+
warning : Bsb_warning.t;
7168
(*TODO: maybe we should always resolve bs-platform
7269
so that we can calculate correct relative path in
7370
[.merlin]

jscomp/bsb/bsb_merlin_gen.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ let output_merlin_namespace buffer ns=
8989
let bsc_flg_to_merlin_ocamlc_flg bsc_flags =
9090
merlin_flg ^
9191
String.concat Ext_string.single_space
92-
(List.filter (fun x -> not (Ext_string.starts_with x bs_flg_prefix )) @@
93-
Literals.dash_nostdlib::bsc_flags)
92+
("-strict-sequence" :: List.filter (fun x -> not (Ext_string.starts_with x bs_flg_prefix )) (
93+
Literals.dash_nostdlib::bsc_flags))
9494

9595
(* No need for [-warn-error] in merlin *)
96-
let warning_to_merlin_flg (warning: Bsb_warning.t option) : string=
97-
merlin_flg ^ Bsb_warning.get_warning_flag warning
96+
let warning_to_merlin_flg (warning: Bsb_warning.t ) : string=
97+
merlin_flg ^ Bsb_warning.to_merlin_string warning
9898

9999

100100
let merlin_file_gen ~per_proj_dir:(per_proj_dir:string)

jscomp/bsb/bsb_ninja_gen.ml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ let output_ninja_and_namespace_map
159159
Bsb_ninja_global_vars.bsc, (Ext_filename.maybe_quote Bsb_global_paths.vendor_bsc);
160160
(* The path to [bsb_heler.exe] *)
161161
Bsb_ninja_global_vars.bsdep, (Ext_filename.maybe_quote Bsb_global_paths.vendor_bsdep) ;
162-
Bsb_ninja_global_vars.warnings, Bsb_warning.opt_warning_to_string ~toplevel warning ;
162+
Bsb_ninja_global_vars.warnings, Bsb_warning.to_bsb_string ~toplevel warning ;
163163
Bsb_ninja_global_vars.bsc_flags, (get_bsc_flags ~toplevel bsc_flags) ;
164164
Bsb_ninja_global_vars.ppx_flags, ppx_flags;
165165

@@ -215,9 +215,7 @@ let output_ninja_and_namespace_map
215215
let digest = Bsb_db_encode.write_build_cache ~dir:cwd_lib_bs bs_groups in
216216
let rules : Bsb_ninja_rule.builtin =
217217
Bsb_ninja_rule.make_custom_rules
218-
~refmt:(match refmt with
219-
| Refmt_none | Refmt_v3 -> None
220-
| Refmt_custom x -> Some x)
218+
~refmt
221219
~has_gentype:(gentype_config <> None)
222220
~has_postbuild:(js_post_build_cmd <> None)
223221
~has_ppx:(ppx_files <> [])

jscomp/bsb/bsb_warning.ml

Lines changed: 32 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -29,70 +29,25 @@ type warning_error =
2929
| Warn_error_true
3030
| Warn_error_number of string
3131

32-
type t = {
32+
type t0 = {
3333
number : string option;
3434
error : warning_error
3535
}
3636

37-
(**
38-
See the meanings of the warning codes here: https://caml.inria.fr/pub/docs/manual-ocaml/comp.html#sec281
37+
type nonrec t = t0 option
3938

40-
- 30 Two labels or constructors of the same name are defined in two mutually recursive types.
41-
- 40 Constructor or label name used out of scope.
39+
let use_default = None
4240

43-
- 6 Label omitted in function application.
44-
- 7 Method overridden.
45-
- 9 Missing fields in a record pattern. (*Not always desired, in some cases need [@@@warning "+9"] *)
46-
- 27 Innocuous unused variable: unused variable that is not bound with let nor as, and doesn’t start with an underscore (_) character.
47-
- 29 Unescaped end-of-line in a string constant (non-portable code).
48-
- 32 .. 39 Unused blabla
49-
- 44 Open statement shadows an already defined identifier.
50-
- 45 Open statement shadows an already defined label or constructor.
51-
- 48 Implicit elimination of optional arguments. https://caml.inria.fr/mantis/view.php?id=6352
52-
- 101 (bsb-specific) unsafe polymorphic comparison.
53-
*)
54-
let default_warning = "-30-40+6+7+27+32..39+44+45+101"
55-
56-
let default_warning_flag = "-w " ^ default_warning
57-
58-
let get_warning_flag x =
59-
default_warning_flag ^
41+
let to_merlin_string x =
42+
"-w " ^ Bsc_warnings.defaults_w
43+
^
6044
(match x with
6145
| Some {number =None}
6246
| None -> Ext_string.empty
6347
| Some {number = Some x} -> Ext_string.trim x )
6448

6549

66-
let warn_error = " -warn-error A"
67-
68-
let warning_to_string ~toplevel
69-
warning : string =
70-
default_warning_flag ^
71-
(match warning.number with
72-
| None ->
73-
Ext_string.empty
74-
| Some x ->
75-
let content =
76-
Ext_string.trim x in
77-
if content = "" then content
78-
else
79-
match content.[0] with
80-
| '0' .. '9' -> "+" ^ content
81-
| _ -> content
82-
) ^
83-
if toplevel then
84-
match warning.error with
85-
| Warn_error_true ->
86-
warn_error
87-
88-
| Warn_error_number y ->
89-
" -warn-error " ^ y
90-
| Warn_error_false ->
91-
Ext_string.empty
92-
else Ext_string.empty
93-
94-
95-
50+
9651
let from_map (m : Ext_json_types.t Map_string.t) =
9752
let number_opt = Map_string.find_opt m Bsb_build_schemas.number in
9853
let error_opt = Map_string.find_opt m Bsb_build_schemas.error in
@@ -117,8 +72,30 @@ let from_map (m : Ext_json_types.t Map_string.t) =
11772
in
11873
Some {number; error }
11974

120-
let opt_warning_to_string ~toplevel warning =
75+
let to_bsb_string ~toplevel warning =
12176
match warning with
122-
| None -> default_warning_flag
123-
| Some w -> warning_to_string ~toplevel w
77+
| None -> Ext_string.empty
78+
| Some warning ->
79+
"-w " ^ Bsc_warnings.defaults_w ^
80+
(match warning.number with
81+
| None ->
82+
Ext_string.empty
83+
| Some x ->
84+
let content =
85+
Ext_string.trim x in
86+
if content = "" then content
87+
else
88+
match content.[0] with
89+
| '0' .. '9' -> "+" ^ content
90+
| _ -> content
91+
) ^
92+
if toplevel then
93+
match warning.error with
94+
| Warn_error_true ->
95+
" -warn-error A"
96+
| Warn_error_number y ->
97+
" -warn-error " ^ y
98+
| Warn_error_false ->
99+
Ext_string.empty
100+
else Ext_string.empty
124101

jscomp/bsb/bsb_warning.mli

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@
2727

2828
type t
2929

30-
val get_warning_flag : t option -> string
30+
(** Extra work is need to make merlin happy *)
31+
val to_merlin_string : t -> string
3132

32-
val default_warning : string
3333

34-
val default_warning_flag : string
35-
(* default_warning, including the -w prefix, for command-line arguments *)
3634

37-
val from_map : Ext_json_types.t Map_string.t -> t option
35+
val from_map : Ext_json_types.t Map_string.t -> t
3836

39-
(** [opt_warning_to_string not_dev warning]
37+
(** [to_bsb_string not_dev warning]
4038
*)
41-
val opt_warning_to_string :
39+
val to_bsb_string :
4240
toplevel:bool ->
43-
t option ->
41+
t ->
4442
string
4543

44+
val use_default : t
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11

2-
Warning number 5
2+
We've found a bug for you!
33
/.../fixtures/warnings1.re 3:3-7
44

55
1 │ let x = (a, b) => a + b;
66
2 │ let z = () => {
7-
3 │ x(10);
7+
3 │ x(10);
88
4 │ 10
99
5 │ };
1010

11-
this function application is partial,
12-
maybe some arguments are missing.
11+
This has type:
12+
int => int
13+
But somewhere wanted:
14+
unit
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11

2-
Warning number 10
2+
We've found a bug for you!
33
/.../fixtures/warnings2.re 2:3-4
44

55
1 │ let z = () => {
6-
2 │ 10;
6+
2 │ 10;
77
3 │ 10
88
4 │ };
99

10-
This expression returns a value, but you're not doing anything with it. If this is on purpose, wrap it with `ignore`.
10+
This has type:
11+
int
12+
But somewhere wanted:
13+
unit

jscomp/core/bs_conditional_initial.ml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424

2525

2626
let setup_env () =
27+
Warnings.parse_options false Bsc_warnings.defaults_w;
28+
Warnings.parse_options true Bsc_warnings.defaults_warn_error;
2729
Clflags.dump_location := false;
2830
Clflags.compile_only := true;
2931
Clflags.bs_only := true;
@@ -35,7 +37,8 @@ let setup_env () =
3537
Clflags.unsafe_string := false;
3638
Clflags.debug := true;
3739
Clflags.record_event_when_debug := false;
38-
Clflags.binary_annotations := true;
40+
Clflags.binary_annotations := true;
41+
Clflags.strict_sequence := true;
3942
(* Turn on [-no-alias-deps] by default -- double check *)
4043
Oprint.out_ident := Outcome_printer_ns.out_ident;
4144
Builtin_attributes.check_bs_attributes_inclusion := Record_attributes_check.check_bs_attributes_inclusion;

jscomp/ext/bsc_warnings.ml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
(* Copyright (C) 2020- Authors of BuckleScript
2+
*
3+
* This program is free software: you can redistribute it and/or modify
4+
* it under the terms of the GNU Lesser General Public License as published by
5+
* the Free Software Foundation, either version 3 of the License, or
6+
* (at your option) any later version.
7+
*
8+
* In addition to the permissions granted to you by the LGPL, you may combine
9+
* or link a "work that uses the Library" with a publicly distributed version
10+
* of this file to produce a combined library or application, then distribute
11+
* that combined work under the terms of your choosing, with no requirement
12+
* to comply with the obligations normally placed on you by section 4 of the
13+
* LGPL version 3 (or the corresponding section of a later version of the LGPL
14+
* should you choose to use a later version).
15+
*
16+
* This program is distributed in the hope that it will be useful,
17+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19+
20+
*
21+
* You should have received a copy of the GNU Lesser General Public License
22+
* along with this program; if not, write to the Free Software
23+
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
24+
25+
26+
27+
(**
28+
See the meanings of the warning codes here: https://caml.inria.fr/pub/docs/manual-ocaml/comp.html#sec281
29+
30+
- 30 Two labels or constructors of the same name are defined in two mutually recursive types.
31+
- 40 Constructor or label name used out of scope.
32+
33+
- 6 Label omitted in function application.
34+
- 7 Method overridden.
35+
- 9 Missing fields in a record pattern. (*Not always desired, in some cases need [@@@warning "+9"] *)
36+
- 27 Innocuous unused variable: unused variable that is not bound with let nor as, and doesn’t start with an underscore (_) character.
37+
- 29 Unescaped end-of-line in a string constant (non-portable code).
38+
- 32 .. 39 Unused blabla
39+
- 44 Open statement shadows an already defined identifier.
40+
- 45 Open statement shadows an already defined label or constructor.
41+
- 48 Implicit elimination of optional arguments. https://caml.inria.fr/mantis/view.php?id=6352
42+
- 101 (bsb-specific) unsafe polymorphic comparison.
43+
*)
44+
let defaults_w = "-30-40+6+7+27+32..39+44+45+101"
45+
let defaults_warn_error = "-a+5+101";;

0 commit comments

Comments
 (0)