fix many, many warnings

This commit is contained in:
Simon Cruanes 2023-06-06 22:16:20 -04:00
parent 77ff1ee6a5
commit bbfbe0f770
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
14 changed files with 107 additions and 115 deletions

View file

@ -139,11 +139,15 @@ let rec find_aux f a i =
| None -> find_aux f a (i + 1) | None -> find_aux f a (i + 1)
) )
[@@@ocaml.warning "-32"]
let find_map f a = find_aux (fun _ -> f) a 0 let find_map f a = find_aux (fun _ -> f) a 0
let find = find_map let find = find_map
let find_map_i f a = find_aux f a 0 let find_map_i f a = find_aux f a 0
let findi = find_map_i let findi = find_map_i
[@@@ocaml.warning "+32"]
let find_idx p a = let find_idx p a =
find_aux find_aux
(fun i x -> (fun i x ->
@ -154,58 +158,76 @@ let find_idx p a =
a 0 a 0
let max cmp a = let max cmp a =
if Array.length a = 0 then None if Array.length a = 0 then
else Some ( None
fold else
(fun acc elt -> if cmp acc elt < 0 then elt else acc) Some
a.(0) (fold
a) (fun acc elt ->
if cmp acc elt < 0 then
elt
else
acc)
a.(0) a)
let max_exn cmp a = let max_exn cmp a =
match max cmp a with match max cmp a with
| None -> invalid_arg "CCArray.max_exn" | None -> invalid_arg "CCArray.max_exn"
| Some elt -> elt | Some elt -> elt
let argmax cmp a = let argmax cmp a =
if Array.length a = 0 then None if Array.length a = 0 then
else Some ( None
foldi else
(fun acc i elt -> if cmp a.(acc) elt < 0 then i else acc) Some
0 (foldi
a) (fun acc i elt ->
if cmp a.(acc) elt < 0 then
i
else
acc)
0 a)
let argmax_exn cmp a = let argmax_exn cmp a =
match argmax cmp a with match argmax cmp a with
| None -> invalid_arg "CCArray.argmax_exn" | None -> invalid_arg "CCArray.argmax_exn"
| Some elt -> elt | Some elt -> elt
let min cmp a = let min cmp a =
if Array.length a = 0 then None if Array.length a = 0 then
else Some ( None
fold else
(fun acc elt -> if cmp acc elt > 0 then elt else acc) Some
a.(0) (fold
a) (fun acc elt ->
if cmp acc elt > 0 then
elt
else
acc)
a.(0) a)
let min_exn cmp a = let min_exn cmp a =
match min cmp a with match min cmp a with
| None -> invalid_arg "CCArray.min_exn" | None -> invalid_arg "CCArray.min_exn"
| Some elt -> elt | Some elt -> elt
let argmin cmp a = let argmin cmp a =
if Array.length a = 0 then None if Array.length a = 0 then
else Some ( None
foldi else
(fun acc i elt -> if cmp a.(acc) elt > 0 then i else acc) Some
0 (foldi
a) (fun acc i elt ->
if cmp a.(acc) elt > 0 then
i
else
acc)
0 a)
let argmin_exn cmp a = let argmin_exn cmp a =
match argmin cmp a with match argmin cmp a with
| None -> invalid_arg "CCArray.argmin_exn" | None -> invalid_arg "CCArray.argmin_exn"
| Some elt -> elt | Some elt -> elt
let filter_map f a = let filter_map f a =
let rec aux acc i = let rec aux acc i =

View file

@ -27,6 +27,8 @@ end
include Infix include Infix
[@@@ocaml.warning "-32"]
let nan = Stdlib.nan let nan = Stdlib.nan
let infinity = Stdlib.infinity let infinity = Stdlib.infinity
let neg_infinity = Stdlib.neg_infinity let neg_infinity = Stdlib.neg_infinity
@ -68,6 +70,8 @@ let equal (a : float) b = a = b
let hash : t -> int = Hashtbl.hash let hash : t -> int = Hashtbl.hash
let compare (a : float) b = Stdlib.compare a b let compare (a : float) b = Stdlib.compare a b
[@@@ocaml.warning "+32"]
type 'a printer = Format.formatter -> 'a -> unit type 'a printer = Format.formatter -> 'a -> unit
type 'a random_gen = Random.State.t -> 'a type 'a random_gen = Random.State.t -> 'a

View file

@ -2,8 +2,12 @@
(** {1 Basic Functions} *) (** {1 Basic Functions} *)
[@@@ocaml.warning "-32"]
let opaque_identity x = x let opaque_identity x = x
[@@@ocaml.warning "+32"]
(* import standard implementations, if any *) (* import standard implementations, if any *)
include Sys include Sys
@ -14,13 +18,10 @@ include CCShims_.Stdlib
include Fun include Fun
[@@@else_] [@@@else_]
[@@@ocaml.warning "-32"]
external id : 'a -> 'a = "%identity" external id : 'a -> 'a = "%identity"
let[@inline] flip f x y = f y x
let[@inline] const x _ = x
let[@inline] negate f x = not (f x)
let[@inline] protect ~finally f = let[@inline] protect ~finally f =
try try
let x = f () in let x = f () in
@ -30,6 +31,12 @@ let[@inline] protect ~finally f =
finally (); finally ();
raise e raise e
[@@@ocaml.warning "+32"]
let[@inline] flip f x y = f y x
let[@inline] const x _ = x
let[@inline] negate f x = not (f x)
[@@@endif] [@@@endif]
let compose f g x = g (f x) let compose f g x = g (f x)

View file

@ -111,10 +111,14 @@ val to_float : t -> float
(** [to_float] is the same as [float_of_int] (** [to_float] is the same as [float_of_int]
@since 3.0*) @since 3.0*)
[@@@ocaml.warning "-32"]
val of_float : float -> t val of_float : float -> t
(** [to_float] is the same as [int_of_float] (** [to_float] is the same as [int_of_float]
@since 3.0*) @since 3.0*)
[@@@ocaml.warning "+32"]
val to_string : t -> string val to_string : t -> string
(** [to_string x] returns the string representation of the integer [x], in signed decimal. (** [to_string x] returns the string representation of the integer [x], in signed decimal.
@since 0.13 *) @since 0.13 *)

View file

@ -6,6 +6,8 @@ open CCShims_
(* backport new functions from stdlib here *) (* backport new functions from stdlib here *)
[@@@ocaml.warning "-32"]
let nth_opt l n = let nth_opt l n =
if n < 0 then invalid_arg "nth_opt"; if n < 0 then invalid_arg "nth_opt";
let rec aux l n = let rec aux l n =
@ -46,6 +48,8 @@ let rec assq_opt x = function
| (y, v) :: _ when Stdlib.( == ) x y -> Some v | (y, v) :: _ when Stdlib.( == ) x y -> Some v
| _ :: tail -> assq_opt x tail | _ :: tail -> assq_opt x tail
[@@@ocaml.warning "+32"]
(* end of backport *) (* end of backport *)
[@@@ifge 4.8] [@@@ifge 4.8]

View file

@ -33,18 +33,6 @@ val is_empty : _ t -> bool
(** [is_empty l] returns [true] iff [l = []]. (** [is_empty l] returns [true] iff [l = []].
@since 0.11 *) @since 0.11 *)
val map : ('a -> 'b) -> 'a t -> 'b t
(** [map f [a0; a1; …; an]] applies function [f] in turn to [a0; a1; …; an].
Safe version of {!List.map}. *)
val ( >|= ) : 'a t -> ('a -> 'b) -> 'b t
(** [l >|= f] is the infix version of [map] with reversed arguments.
@since 0.5 *)
val append : 'a t -> 'a t -> 'a t
(** [append l1 l2] returns the list that is the concatenation of [l1] and [l2].
Safe version of {!List.append}. *)
val cons_maybe : 'a option -> 'a t -> 'a t val cons_maybe : 'a option -> 'a t -> 'a t
(** [cons_maybe (Some x) l] is [x :: l]. (** [cons_maybe (Some x) l] is [x :: l].
[cons_maybe None l] is [l]. [cons_maybe None l] is [l].
@ -55,21 +43,6 @@ val cons' : 'a t -> 'a -> 'a t
functions such as {!List.fold_left} or {!Array.fold_left}. functions such as {!List.fold_left} or {!Array.fold_left}.
@since 3.3 *) @since 3.3 *)
val ( @ ) : 'a t -> 'a t -> 'a t
(** [l1 @ l2] is like [append l1 l2].
Concatenate the two lists [l1] and [l2]. *)
val filter : ('a -> bool) -> 'a t -> 'a t
(** [filter p l] returns all the elements of the list [l]
that satisfy the predicate [p]. The order of the elements
in the input list [l] is preserved.
Safe version of {!List.filter}. *)
val fold_right : ('a -> 'b -> 'b) -> 'a t -> 'b -> 'b
(** [fold_right f [a1; …; an] b] is
[f a1 (f a2 ( (f an b) ))].
Safe version of {!List.fold_right}. *)
val fold_while : ('a -> 'b -> 'a * [ `Stop | `Continue ]) -> 'a -> 'b t -> 'a val fold_while : ('a -> 'b -> 'a * [ `Stop | `Continue ]) -> 'a -> 'b t -> 'a
(** [fold_while f init l] folds until a stop condition via [('a, `Stop)] is (** [fold_while f init l] folds until a stop condition via [('a, `Stop)] is
indicated by the accumulator. indicated by the accumulator.
@ -408,18 +381,9 @@ val mguard : bool -> unit t
]} ]}
@since 3.1 *) @since 3.1 *)
val ( <*> ) : ('a -> 'b) t -> 'a t -> 'b t
(** [funs <*> l] is [product (fun f x -> f x) funs l]. *)
val ( <$> ) : ('a -> 'b) -> 'a t -> 'b t
(** [(<$>)] is [map]. *)
val return : 'a -> 'a t val return : 'a -> 'a t
(** [return x] is [x]. *) (** [return x] is [x]. *)
val ( >>= ) : 'a t -> ('a -> 'b t) -> 'b t
(** [l >>= f] is [flat_map f l]. *)
val take : int -> 'a t -> 'a t val take : int -> 'a t -> 'a t
(** [take n l] takes the [n] first elements of the list [l], drop the rest. *) (** [take n l] takes the [n] first elements of the list [l], drop the rest. *)
@ -722,15 +686,6 @@ val range' : int -> int -> int t
(** [range' i j] is like {!range} but the second bound [j] is excluded. (** [range' i j] is like {!range} but the second bound [j] is excluded.
For instance [range' 0 5 = [0;1;2;3;4]]. *) For instance [range' 0 5 = [0;1;2;3;4]]. *)
val ( -- ) : int -> int -> int t
(** [i -- j] is the list of integers from [i] to [j] included.
Infix alias for [range]. *)
val ( --^ ) : int -> int -> int t
(** [i --^ j] is the list of integers from [i] to [j] excluded.
Infix alias for [range'].
@since 0.17 *)
val replicate : int -> 'a -> 'a t val replicate : int -> 'a -> 'a t
(** [replicate n x] replicates the given element [x] [n] times. *) (** [replicate n x] replicates the given element [x] [n] times. *)

View file

@ -178,6 +178,8 @@ module Make (O : Map.OrderedType) = struct
(* backport functions from recent stdlib. (* backport functions from recent stdlib.
they will be shadowed by inclusion of [S] if present. *) they will be shadowed by inclusion of [S] if present. *)
[@@@ocaml.warning "-32"]
let union f a b = let union f a b =
M.merge M.merge
(fun k v1 v2 -> (fun k v1 v2 ->
@ -230,6 +232,8 @@ module Make (O : Map.OrderedType) = struct
| None -> raise Not_found | None -> raise Not_found
| Some (k, v) -> k, v | Some (k, v) -> k, v
[@@@ocaml.warning "+32"]
(* === include M. (* === include M.
This will shadow some values depending on OCaml's current version This will shadow some values depending on OCaml's current version
=== *) === *)

View file

@ -338,7 +338,6 @@ let parsing what p =
} }
let empty = { run = (fun st ~ok ~err:_ -> ok st ()) } let empty = { run = (fun st ~ok ~err:_ -> ok st ()) }
let nop = empty
let any_char = { run = (fun st ~ok ~err -> consume_ st ~ok ~err) } let any_char = { run = (fun st ~ok ~err -> consume_ st ~ok ~err) }
let char c : _ t = let char c : _ t =
@ -811,8 +810,6 @@ let split_list_at_most ~on_char n : slice list t =
in in
loop [] n loop [] n
let split_list ~on_char : _ t = split_list_at_most ~on_char max_int
let split_2 ~on_char : _ t = let split_2 ~on_char : _ t =
split_list_at_most ~on_char 3 >>= function split_list_at_most ~on_char 3 >>= function
| [ a; b ] -> return (a, b) | [ a; b ] -> return (a, b)
@ -948,8 +945,6 @@ let parse_file_exn p file =
| Error e -> raise (ParseError e) | Error e -> raise (ParseError e)
module U = struct module U = struct
let sep_ = sep
let list ?(start = "[") ?(stop = "]") ?(sep = ";") p = let list ?(start = "[") ?(stop = "]") ?(sep = ";") p =
string start *> skip_white string start *> skip_white
*> sep_until *> sep_until

View file

@ -108,11 +108,6 @@ let get_or_failwith = function
| Ok x -> x | Ok x -> x
| Error msg -> failwith msg | Error msg -> failwith msg
let get_lazy default_fn x =
match x with
| Ok x -> x
| Error e -> default_fn e
let map_or f e ~default = let map_or f e ~default =
match e with match e with
| Ok x -> f x | Ok x -> f x

View file

@ -94,11 +94,6 @@ val get_exn : ('a, _) t -> 'a
val get_or : ('a, _) t -> default:'a -> 'a val get_or : ('a, _) t -> default:'a -> 'a
(** [get_or e ~default] returns [x] if [e = Ok x], [default] otherwise. *) (** [get_or e ~default] returns [x] if [e = Ok x], [default] otherwise. *)
val get_lazy : ('e -> 'a) -> ('a, 'e) t -> 'a
(** [get_lazy f e] returns [x] if [e = Ok x], [f msg] if [e = Error msg].
This is similar to {!CCOption.get_lazy}.
@since 3.0 *)
val get_or_failwith : ('a, string) t -> 'a val get_or_failwith : ('a, string) t -> 'a
(** [get_or_failwith e] returns [x] if [e = Ok x], fails otherwise. (** [get_or_failwith e] returns [x] if [e = Ok x], fails otherwise.
@raise Failure with [msg] if [e = Error msg]. @raise Failure with [msg] if [e = Error msg].

View file

@ -101,6 +101,8 @@ module Make (O : Map.OrderedType) = struct
(* backport functions from recent stdlib. (* backport functions from recent stdlib.
they will be shadowed by inclusion of [S] if present. *) they will be shadowed by inclusion of [S] if present. *)
[@@@ocaml.warning "-32"]
let find_opt x s = try Some (S.find x s) with Not_found -> None let find_opt x s = try Some (S.find x s) with Not_found -> None
let choose_opt s = try Some (S.choose s) with Not_found -> None let choose_opt s = try Some (S.choose s) with Not_found -> None
let min_elt_opt s = try Some (S.min_elt s) with Not_found -> None let min_elt_opt s = try Some (S.min_elt s) with Not_found -> None
@ -151,17 +153,23 @@ module Make (O : Map.OrderedType) = struct
| None -> raise Not_found | None -> raise Not_found
| Some x -> x | Some x -> x
[@@@ocaml.warning "+32"]
include S include S
(* Use find_last which is linear time on OCaml < 4.05 *) (* Use find_last which is linear time on OCaml < 4.05 *)
let find_last_map f m = let find_last_map f m =
let res = ref None in let res = ref None in
let _ = find_last_opt let _ =
(fun x -> find_last_opt
match f x with (fun x ->
| None -> false match f x with
| Some y -> res := Some y; true) | None -> false
m in | Some y ->
res := Some y;
true)
m
in
!res !res
let add_seq seq set = let add_seq seq set =

View file

@ -10,8 +10,17 @@ type uchar = Uchar.t
type 'a gen = unit -> 'a option type 'a gen = unit -> 'a option
type 'a iter = ('a -> unit) -> unit type 'a iter = ('a -> unit) -> unit
(* compat shim *)
[@@@ocaml.warning "-32"]
let equal (a : string) b = Stdlib.( = ) a b let equal (a : string) b = Stdlib.( = ) a b
let hash : string -> int = Hashtbl.hash let hash : string -> int = Hashtbl.hash
[@@@ocaml.warning "+32"]
(* end compat shim *)
let pp = Format.pp_print_string let pp = Format.pp_print_string
include String include String

View file

@ -500,15 +500,6 @@ let flat_map f v =
iter (fun x -> iter (push v') (f x)) v; iter (fun x -> iter (push v') (f x)) v;
v' v'
let flat_map_iter f v =
let v' = create () in
iter
(fun x ->
let seq = f x in
append_iter v' seq)
v;
v'
let flat_map_seq f v = let flat_map_seq f v =
let v' = create () in let v' = create () in
iter iter

View file

@ -6,8 +6,7 @@
(preprocess (preprocess
(action (action
(run %{project_root}/src/core/cpp/cpp.exe %{input-file}))) (run %{project_root}/src/core/cpp/cpp.exe %{input-file})))
(flags :standard -warn-error -a+8 -w -32-70 -safe-string -strict-sequence (flags :standard -nolabels -open CCMonomorphic)
-nolabels -open CCMonomorphic)
(libraries seq either containers.monomorphic)) (libraries seq either containers.monomorphic))
(ocamllex (ocamllex