ocamlformat

This commit is contained in:
Simon Cruanes 2024-12-13 00:17:53 -05:00
parent b140a50c46
commit cad41d70d6
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
26 changed files with 89 additions and 92 deletions

View file

@ -68,7 +68,7 @@ jobs:
strategy: strategy:
matrix: matrix:
ocaml-compiler: ocaml-compiler:
- '5.1' - '5.2'
runs-on: 'ubuntu-latest' runs-on: 'ubuntu-latest'
steps: steps:
- uses: actions/checkout@main - uses: actions/checkout@main
@ -79,6 +79,6 @@ jobs:
dune-cache: true dune-cache: true
allow-prerelease-opam: true allow-prerelease-opam: true
- run: opam install ocamlformat.0.24.1 - run: opam install ocamlformat.0.26.2
- run: opam exec -- make format-check - run: opam exec -- make format-check

View file

@ -1,4 +1,4 @@
version = 0.24.1 version = 0.26.2
profile=conventional profile=conventional
margin=80 margin=80
if-then-else=k-r if-then-else=k-r

View file

@ -77,9 +77,9 @@ let int = hash_int_
let bool b = let bool b =
hash_int_ hash_int_
(if b then (if b then
1 1
else else
2) 2)
let char x = hash_int_ (Char.code x) let char x = hash_int_ (Char.code x)

View file

@ -248,7 +248,7 @@ val partition_map :
('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> ('a -> [< `Left of 'b | `Right of 'c | `Drop ]) ->
'a list -> 'a list ->
'b list * 'c list 'b list * 'c list
[@@ocaml.deprecated "use CCList.partition_filter_map instead"] [@@ocaml.deprecated "use CCList.partition_filter_map instead"]
(** @deprecated use {!partition_filter_map} instead (** @deprecated use {!partition_filter_map} instead
@since 0.11 *) @since 0.11 *)

View file

@ -281,7 +281,7 @@ val partition_map :
f:('a -> [< `Left of 'b | `Right of 'c | `Drop ]) -> f:('a -> [< `Left of 'b | `Right of 'c | `Drop ]) ->
'a list -> 'a list ->
'b list * 'c list 'b list * 'c list
[@@ocaml.deprecated "use CCList.partition_filter_map instead"] [@@ocaml.deprecated "use CCList.partition_filter_map instead"]
(** @deprecated use {!partition_filter_map} instead *) (** @deprecated use {!partition_filter_map} instead *)
val group_by : ?hash:('a -> int) -> ?eq:('a -> 'a -> bool) -> 'a t -> 'a list t val group_by : ?hash:('a -> int) -> ?eq:('a -> 'a -> bool) -> 'a t -> 'a list t

View file

@ -107,7 +107,7 @@ val value : 'a t -> default:'a -> 'a
@since 2.8 *) @since 2.8 *)
val get_exn : 'a t -> 'a val get_exn : 'a t -> 'a
[@@ocaml.deprecated "use CCOption.get_exn_or instead"] [@@ocaml.deprecated "use CCOption.get_exn_or instead"]
(** [get_exn o] returns [x] if [o] is [Some x] or fails if [o] is [None]. (** [get_exn o] returns [x] if [o] is [Some x] or fails if [o] is [None].
@raise Invalid_argument if the option is [None]. @raise Invalid_argument if the option is [None].
@deprecated use {!get_exn_or} instead @deprecated use {!get_exn_or} instead

View file

@ -13,7 +13,7 @@ val poly : 'a t
@since 3.6 *) @since 3.6 *)
val compare : 'a t val compare : 'a t
[@@deprecated "use CCOrd.poly instead, this name is too general"] [@@deprecated "use CCOrd.poly instead, this name is too general"]
(** Polymorphic "magic" comparison. (** Polymorphic "magic" comparison.
@deprecated since 3.6 in favor of {!poly}. The reason is that @deprecated since 3.6 in favor of {!poly}. The reason is that
[compare] is easily shadowed, can shadow other comparators, and is just [compare] is easily shadowed, can shadow other comparators, and is just

View file

@ -404,7 +404,7 @@ val optional : _ t -> unit t
@since 3.6 *) @since 3.6 *)
val try_ : 'a t -> 'a t val try_ : 'a t -> 'a t
[@@deprecated "plays no role anymore, just replace [try foo] with [foo]"] [@@deprecated "plays no role anymore, just replace [try foo] with [foo]"]
(** [try_ p] is just like [p] (it used to play a role in backtracking (** [try_ p] is just like [p] (it used to play a role in backtracking
semantics but no more). semantics but no more).

View file

@ -498,7 +498,7 @@ let find_internal_i_ p v =
else ( else (
let x = v.vec.(i) in let x = v.vec.(i) in
if p x then if p x then
i,x i, x
else else
check (i + 1) check (i + 1)
) )

View file

@ -407,9 +407,9 @@ let pp out bv =
iter bv (fun _i b -> iter bv (fun _i b ->
Format.pp_print_char out Format.pp_print_char out
(if b then (if b then
'1' '1'
else else
'0')); '0'));
Format.pp_print_string out "}" Format.pp_print_string out "}"
module Internal_ = struct module Internal_ = struct

View file

@ -199,8 +199,8 @@ module A_SPARSE = struct
arr.(real_idx) <- x; arr.(real_idx) <- x;
if real_idx > 0 then Array.blit a.arr 0 arr 0 real_idx; if real_idx > 0 then Array.blit a.arr 0 arr 0 real_idx;
(if real_idx < n then (if real_idx < n then
let open Stdlib in let open Stdlib in
Array.blit a.arr real_idx arr (real_idx + 1) (n - real_idx)); Array.blit a.arr real_idx arr (real_idx + 1) (n - real_idx));
{ a with bits; arr } { a with bits; arr }
) else if (* replace element at [real_idx] *) ) else if (* replace element at [real_idx] *)
mut then ( mut then (
@ -230,8 +230,8 @@ module A_SPARSE = struct
let arr = Array.make Stdlib.(n + 1) x in let arr = Array.make Stdlib.(n + 1) x in
if real_idx > 0 then Array.blit a.arr 0 arr 0 real_idx; if real_idx > 0 then Array.blit a.arr 0 arr 0 real_idx;
(if real_idx < n then (if real_idx < n then
let open Stdlib in let open Stdlib in
Array.blit a.arr real_idx arr (real_idx + 1) (n - real_idx)); Array.blit a.arr real_idx arr (real_idx + 1) (n - real_idx));
{ a with bits; arr } { a with bits; arr }
) else ( ) else (
let x = f a.arr.(real_idx) in let x = f a.arr.(real_idx) in

View file

@ -66,11 +66,10 @@ let rec cut_depth n t () =
(** {2 Graph Traversals} *) (** {2 Graph Traversals} *)
(** Abstract Set structure *) (** Abstract Set structure *)
class type ['a] pset = class type ['a] pset = object
object method add : 'a -> 'a pset
method add : 'a -> 'a pset method mem : 'a -> bool
method mem : 'a -> bool end
end
let set_of_cmp (type elt) ~cmp () = let set_of_cmp (type elt) ~cmp () =
let module S = Set.Make (struct let module S = Set.Make (struct

View file

@ -49,11 +49,10 @@ val cut_depth : int -> 'a t -> 'a t
(** {2 Graph Traversals} *) (** {2 Graph Traversals} *)
(** Abstract Set structure *) (** Abstract Set structure *)
class type ['a] pset = class type ['a] pset = object
object method add : 'a -> 'a pset
method add : 'a -> 'a pset method mem : 'a -> bool
method mem : 'a -> bool end
end
val set_of_cmp : cmp:('a -> 'a -> int) -> unit -> 'a pset val set_of_cmp : cmp:('a -> 'a -> int) -> unit -> 'a pset
(** Build a set structure given a total ordering. *) (** Build a set structure given a total ordering. *)

View file

@ -295,9 +295,9 @@ module Make (H : HashedType) : S with type key = H.t = struct
{ {
length = length =
(if is_new then (if is_new then
t.length + 1 t.length + 1
else else
t.length); t.length);
arr = Arr a; arr = Arr a;
} }
in in

View file

@ -225,12 +225,12 @@ module Make (W : WORD) : S with type char_ = W.char_ and type key = W.t = struct
let rebuild' new_child = let rebuild' new_child =
rebuild rebuild
(if is_empty new_child then (if is_empty new_child then
t t
else ( else (
let map = M.singleton c new_child in let map = M.singleton c new_child in
let map = M.add c' t' map in let map = M.add c' t' map in
_mk_node None map _mk_node None map
)) ))
in in
empty, rebuild' empty, rebuild'
) )
@ -242,9 +242,9 @@ module Make (W : WORD) : S with type char_ = W.char_ and type key = W.t = struct
let rebuild' new_child = let rebuild' new_child =
rebuild rebuild
(if is_empty new_child then (if is_empty new_child then
_mk_node value (M.remove c map) _mk_node value (M.remove c map)
else else
_mk_node value (M.add c new_child map)) _mk_node value (M.add c new_child map))
in in
t', rebuild' t', rebuild'
with Not_found -> with Not_found ->

View file

@ -37,9 +37,8 @@ val ( >=. ) : float -> float -> bool
(** {2 Shadow Dangerous Operators} *) (** {2 Shadow Dangerous Operators} *)
val ( == ) : [ `Consider_using_CCEqual_physical ] val ( == ) : [ `Consider_using_CCEqual_physical ]
[@@ocaml.deprecated "Please use CCEqual.physical or Stdlib.(==) instead."] [@@ocaml.deprecated "Please use CCEqual.physical or Stdlib.(==) instead."]
val ( != ) : [ `Consider_using_CCEqual_physical ] val ( != ) : [ `Consider_using_CCEqual_physical ]
[@@ocaml.deprecated [@@ocaml.deprecated "Please use [not CCEqual.physical] or Stdlib.(!=) instead."]
"Please use [not CCEqual.physical] or Stdlib.(!=) instead."]
(** @since 2.1 *) (** @since 2.1 *)

View file

@ -455,9 +455,9 @@ let of_seq ?(sep = nil) f seq : t =
| Seq.Cons (x, tl) -> | Seq.Cons (x, tl) ->
let x = f x in let x = f x in
(if first then (if first then
x x
else else
sep ^ x) sep ^ x)
^ loop false tl ^ loop false tl
in in
loop true seq loop true seq

View file

@ -61,9 +61,9 @@ let gen_c : Cbor.t Q.Gen.t =
in in
frequency frequency
(if size > 0 then (if size > 0 then
base @ rec_ base @ rec_
else else
base) base)
let rec shrink (c : Cbor.t) : Cbor.t Q.Iter.t = let rec shrink (c : Cbor.t) : Cbor.t Q.Iter.t =
let open Q.Iter in let open Q.Iter in

View file

@ -183,10 +183,11 @@ let arb_csexp_arb =
let genstr = Q.Gen.(string_size ~gen:genchar (0 -- 15)) in let genstr = Q.Gen.(string_size ~gen:genchar (0 -- 15)) in
Q.make ~print:Sexp0.to_string ~shrink:shrink_csexp (gen_csexp genstr) Q.make ~print:Sexp0.to_string ~shrink:shrink_csexp (gen_csexp genstr)
module Make (X : sig module Make
val arb : Csexp.t Q.arbitrary (X : sig
end) val arb : Csexp.t Q.arbitrary
() = end)
() =
struct struct
open X;; open X;;

View file

@ -162,9 +162,9 @@ q
let e = edit_distance s1 s2 in let e = edit_distance s1 s2 in
let e' = edit_distance ~cutoff:3 s1 s2 in let e' = edit_distance ~cutoff:3 s1 s2 in
(if e' < 3 then (if e' < 3 then
e = e' e = e'
else else
e >= 3) e >= 3)
&& &&
if e <= 3 then if e <= 3 then
e = e' e = e'

View file

@ -26,8 +26,8 @@ let arb_uchar =
let rec gen = let rec gen =
lazy lazy
(let open Q.Gen in (let open Q.Gen in
Q.Gen.int_range Uchar.(to_int min) Uchar.(to_int max) >>= fun n -> Q.Gen.int_range Uchar.(to_int min) Uchar.(to_int max) >>= fun n ->
try return (Uchar.of_int n) with _ -> Lazy.force gen) try return (Uchar.of_int n) with _ -> Lazy.force gen)
in in
Q.make Q.make
~print:(fun c -> Printf.sprintf "<uchar '%d'>" (Uchar.to_int c)) ~print:(fun c -> Printf.sprintf "<uchar '%d'>" (Uchar.to_int c))

View file

@ -640,9 +640,9 @@ module Op = struct
@@ List.flatten @@ List.flatten
[ [
(if size > 0 then (if size > 0 then
nonzero nonzero
else else
[]); []);
[ [
1, return Clear; 1, return Clear;
1, return Clear_and_shrink; 1, return Clear_and_shrink;
@ -747,16 +747,16 @@ module Ref_ = struct
| Set_bool (i, b) -> | Set_bool (i, b) ->
apply_op self apply_op self
(if b then (if b then
Set i Set i
else else
Reset i) Reset i)
| Flip i -> | Flip i ->
self.size <- max self.size (i + 1); self.size <- max self.size (i + 1);
apply_op self apply_op self
(if Intset.mem i self.set then (if Intset.mem i self.set then
Reset i Reset i
else else
Set i) Set i)
| Clear -> self.set <- Intset.empty | Clear -> self.set <- Intset.empty
| Clear_and_shrink -> | Clear_and_shrink ->
self.set <- Intset.empty; self.set <- Intset.empty;

View file

@ -173,12 +173,12 @@ module Op = struct
1, return (Check_to_gen, size); 1, return (Check_to_gen, size);
]; ];
(if size > 0 then (if size > 0 then
[ [
1, return (Pop, size - 1); 1, return (Pop, size - 1);
(1, 0 -- (size - 1) >|= fun x -> Check_get x, size); (1, 0 -- (size - 1) >|= fun x -> Check_get x, size);
] ]
else else
[]); []);
[ [
( 1, ( 1,
small_list gen_x >|= fun l -> small_list gen_x >|= fun l ->

View file

@ -108,15 +108,14 @@ let t1 = H.of_list [ 1, "a"; 2, "b1" ] in
let t2 = H.of_list [ 2, "b2"; 3, "c" ] in let t2 = H.of_list [ 2, "b2"; 3, "c" ] in
let t = let t =
H.merge H.merge
~f: ~f:(fun _ -> function
(fun _ -> function | `Right v2 -> Some v2
| `Right v2 -> Some v2 | `Left v1 -> Some v1
| `Left v1 -> Some v1 | `Both (s1, s2) ->
| `Both (s1, s2) -> if s1 < s2 then
if s1 < s2 then Some s1
Some s1 else
else Some s2)
Some s2)
t1 t2 t1 t2
in in
assert_equal ~printer:string_of_int 3 (H.length t); assert_equal ~printer:string_of_int 3 (H.length t);

View file

@ -118,9 +118,9 @@ let rec sorted ~rev = function
| [] | [ _ ] -> true | [] | [ _ ] -> true
| x :: (y :: _ as tl) -> | x :: (y :: _ as tl) ->
(if rev then (if rev then
x >= y x >= y
else else
x <= y) x <= y)
&& sorted ~rev tl && sorted ~rev tl
let gen_str = Q.small_printable_string;; let gen_str = Q.small_printable_string;;

View file

@ -242,12 +242,12 @@ module Op = struct
1, return (Check_rev_iter, size); 1, return (Check_rev_iter, size);
]; ];
(if size > 0 then (if size > 0 then
[ [
1, return (Pop, size - 1); 1, return (Pop, size - 1);
(1, 0 -- (size - 1) >|= fun x -> Check_get x, size); (1, 0 -- (size - 1) >|= fun x -> Check_get x, size);
] ]
else else
[]); []);
[ [
( 1, ( 1,
small_list gen_x >|= fun l -> small_list gen_x >|= fun l ->