Skip to content

Commit

Permalink
Auto-format vendored OCaml sources like in compiler repo
Browse files Browse the repository at this point in the history
  • Loading branch information
cknitt committed Nov 1, 2024
1 parent 8849a58 commit 384bcff
Show file tree
Hide file tree
Showing 208 changed files with 31,093 additions and 30,987 deletions.
17 changes: 15 additions & 2 deletions .ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
analysis/vendor/compiler-libs-406/*
analysis/vendor/res_outcome_printer/*
analysis/vendor/js_parser/**
analysis/vendor/ml/cmt_format.ml
analysis/vendor/ml/parser.ml
analysis/vendor/ml/pprintast.ml
analysis/vendor/ext/bs_hash_stubs.ml
analysis/vendor/ext/js_reserved_map.ml
analysis/vendor/ext/ext_string.ml
analysis/vendor/ext/ext_string.mli
analysis/vendor/ext/ext_sys.ml
analysis/vendor/ext/hash.cppo.ml
analysis/vendor/ext/hash_set.cppo.ml
analysis/vendor/ext/map.cppo.ml
analysis/vendor/ext/ordered_hash_map.cppo.ml
analysis/vendor/ext/set.cppo.ml
analysis/vendor/ext/vec.cppo.ml
1 change: 0 additions & 1 deletion analysis/vendor/.ocamlformat

This file was deleted.

1 change: 0 additions & 1 deletion analysis/vendor/ext/.ocamlformat

This file was deleted.

11 changes: 5 additions & 6 deletions analysis/vendor/ext/bsb_db.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,16 @@ type info =
| Impl
| Impl_intf


type module_info = {
mutable info : info;
dir : string;
case : bool;
name_sans_extension : string;
mutable info: info;
dir: string;
case: bool;
name_sans_extension: string;
}

type map = module_info Map_string.t

type 'a cat = { mutable lib : 'a; mutable dev : 'a }
type 'a cat = {mutable lib: 'a; mutable dev: 'a}

type t = map cat
(** indexed by the group *)
11 changes: 5 additions & 6 deletions analysis/vendor/ext/bsb_db.mli
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,16 @@ type info =
| Impl
| Impl_intf


type module_info = {
mutable info : info;
dir : string;
case : bool;
name_sans_extension : string;
mutable info: info;
dir: string;
case: bool;
name_sans_extension: string;
}

type map = module_info Map_string.t

type 'a cat = { mutable lib : 'a; mutable dev : 'a }
type 'a cat = {mutable lib: 'a; mutable dev: 'a}

type t = map cat

Expand Down
76 changes: 38 additions & 38 deletions analysis/vendor/ext/bsc_args.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,35 +64,35 @@ let usage_b (buf : Ext_buffer.t) ~usage (speclist : t) =
while !cur < doc_length do
match String.index_from_opt doc !cur '\n' with
| None ->
if !cur <> 0 then (
buf +> "\n";
buf +> String.make (!max_col + 4) ' ');
buf +> String.sub doc !cur (String.length doc - !cur);
cur := doc_length
if !cur <> 0 then (
buf +> "\n";
buf +> String.make (!max_col + 4) ' ');
buf +> String.sub doc !cur (String.length doc - !cur);
cur := doc_length
| Some new_line_pos ->
if !cur <> 0 then (
buf +> "\n";
buf +> String.make (!max_col + 4) ' ');
buf +> String.sub doc !cur (new_line_pos - !cur);
cur := new_line_pos + 1
if !cur <> 0 then (
buf +> "\n";
buf +> String.make (!max_col + 4) ' ');
buf +> String.sub doc !cur (new_line_pos - !cur);
cur := new_line_pos + 1
done;
buf +> "\n"))

let stop_raise ~usage ~(error : error) (speclist : t) =
let b = Ext_buffer.create 200 in
(match error with
| Unknown ("-help" | "--help" | "-h") ->
usage_b b ~usage speclist;
Ext_buffer.output_buffer stdout b;
exit 0
usage_b b ~usage speclist;
Ext_buffer.output_buffer stdout b;
exit 0
| Unknown s ->
b +> "Unknown option \"";
b +> s;
b +> "\".\n"
b +> "Unknown option \"";
b +> s;
b +> "\".\n"
| Missing s ->
b +> "Option \"";
b +> s;
b +> "\" needs an argument.\n");
b +> "Option \"";
b +> s;
b +> "\" needs an argument.\n");
usage_b b ~usage speclist;
bad_arg (Ext_buffer.contents b)

Expand All @@ -106,25 +106,25 @@ let parse_exn ~usage ~argv ?(start = 1) ?(finish = Array.length argv)
if s <> "" && s.[0] = '-' then
match Ext_spec.assoc3 speclist s with
| Some action -> (
match action with
| Unit_dummy -> ()
| Unit r -> (
match r with
| Unit_set r -> r := true
| Unit_clear r -> r := false
| Unit_call f -> f ()
| Unit_lazy f -> Lazy.force f)
| String f -> (
if !current >= finish then
stop_raise ~usage ~error:(Missing s) speclist
else
let arg = argv.(!current) in
incr current;
match f with
| String_call f -> f arg
| String_set u -> u := arg
| String_optional_set s -> s := Some arg
| String_list_add s -> s := arg :: !s))
match action with
| Unit_dummy -> ()
| Unit r -> (
match r with
| Unit_set r -> r := true
| Unit_clear r -> r := false
| Unit_call f -> f ()
| Unit_lazy f -> Lazy.force f)
| String f -> (
if !current >= finish then
stop_raise ~usage ~error:(Missing s) speclist
else
let arg = argv.(!current) in
incr current;
match f with
| String_call f -> f arg
| String_set u -> u := arg
| String_optional_set s -> s := Some arg
| String_list_add s -> s := arg :: !s))
| None -> stop_raise ~usage ~error:(Unknown s) speclist
else rev_list := s :: !rev_list
done;
Expand Down
4 changes: 2 additions & 2 deletions analysis/vendor/ext/config.mli
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ val version : string
val standard_library : string
(* The directory containing the standard libraries *)

val syntax_kind : [ `ml | `rescript ] ref
val syntax_kind : [`ml | `rescript] ref

val bs_only : bool ref

Expand All @@ -48,4 +48,4 @@ val cmt_magic_number : string
val print_config : out_channel -> unit

type uncurried = Legacy | Uncurried | Swap
val uncurried : uncurried ref
val uncurried : uncurried ref
112 changes: 58 additions & 54 deletions analysis/vendor/ext/ext_array.ml
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,15 @@ let reverse a =
let reverse_of_list = function
| [] -> [||]
| hd :: tl ->
let len = List.length tl in
let a = Array.make (len + 1) hd in
let rec fill i = function
| [] -> a
| hd :: tl ->
Array.unsafe_set a i hd;
fill (i - 1) tl
in
fill (len - 1) tl
let len = List.length tl in
let a = Array.make (len + 1) hd in
let rec fill i = function
| [] -> a
| hd :: tl ->
Array.unsafe_set a i hd;
fill (i - 1) tl
in
fill (len - 1) tl

let filter a f =
let arr_len = Array.length a in
Expand All @@ -76,7 +76,9 @@ let filter_map a (f : _ -> _ option) =
if i = arr_len then reverse_of_list acc
else
let v = Array.unsafe_get a i in
match f v with Some v -> aux (v :: acc) (i + 1) | None -> aux acc (i + 1)
match f v with
| Some v -> aux (v :: acc) (i + 1)
| None -> aux acc (i + 1)
in
aux [] 0

Expand All @@ -101,7 +103,9 @@ let rec tolist_aux a f i res =
if i < 0 then res
else
tolist_aux a f (i - 1)
(match f a.!(i) with Some v -> v :: res | None -> res)
(match f a.!(i) with
| Some v -> v :: res
| None -> res)

let to_list_map a f = tolist_aux a f (Array.length a - 1) []

Expand All @@ -110,50 +114,50 @@ let to_list_map_acc a acc f = tolist_aux a f (Array.length a - 1) acc
let of_list_map a f =
match a with
| [] -> [||]
| [ a0 ] ->
let b0 = f a0 in
[| b0 |]
| [ a0; a1 ] ->
let b0 = f a0 in
let b1 = f a1 in
[| b0; b1 |]
| [ a0; a1; a2 ] ->
let b0 = f a0 in
let b1 = f a1 in
let b2 = f a2 in
[| b0; b1; b2 |]
| [ a0; a1; a2; a3 ] ->
let b0 = f a0 in
let b1 = f a1 in
let b2 = f a2 in
let b3 = f a3 in
[| b0; b1; b2; b3 |]
| [ a0; a1; a2; a3; a4 ] ->
let b0 = f a0 in
let b1 = f a1 in
let b2 = f a2 in
let b3 = f a3 in
let b4 = f a4 in
[| b0; b1; b2; b3; b4 |]
| [a0] ->
let b0 = f a0 in
[|b0|]
| [a0; a1] ->
let b0 = f a0 in
let b1 = f a1 in
[|b0; b1|]
| [a0; a1; a2] ->
let b0 = f a0 in
let b1 = f a1 in
let b2 = f a2 in
[|b0; b1; b2|]
| [a0; a1; a2; a3] ->
let b0 = f a0 in
let b1 = f a1 in
let b2 = f a2 in
let b3 = f a3 in
[|b0; b1; b2; b3|]
| [a0; a1; a2; a3; a4] ->
let b0 = f a0 in
let b1 = f a1 in
let b2 = f a2 in
let b3 = f a3 in
let b4 = f a4 in
[|b0; b1; b2; b3; b4|]
| a0 :: a1 :: a2 :: a3 :: a4 :: tl ->
let b0 = f a0 in
let b1 = f a1 in
let b2 = f a2 in
let b3 = f a3 in
let b4 = f a4 in
let len = List.length tl + 5 in
let arr = Array.make len b0 in
Array.unsafe_set arr 1 b1;
Array.unsafe_set arr 2 b2;
Array.unsafe_set arr 3 b3;
Array.unsafe_set arr 4 b4;
let rec fill i = function
| [] -> arr
| hd :: tl ->
Array.unsafe_set arr i (f hd);
fill (i + 1) tl
in
fill 5 tl
let b0 = f a0 in
let b1 = f a1 in
let b2 = f a2 in
let b3 = f a3 in
let b4 = f a4 in
let len = List.length tl + 5 in
let arr = Array.make len b0 in
Array.unsafe_set arr 1 b1;
Array.unsafe_set arr 2 b2;
Array.unsafe_set arr 3 b3;
Array.unsafe_set arr 4 b4;
let rec fill i = function
| [] -> arr
| hd :: tl ->
Array.unsafe_set arr i (f hd);
fill (i + 1) tl
in
fill 5 tl

(**
{[
Expand Down
8 changes: 2 additions & 6 deletions analysis/vendor/ext/ext_buffer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@

(* Extensible buffers *)

type t = {
mutable buffer : bytes;
mutable position : int;
mutable length : int;
}
type t = {mutable buffer: bytes; mutable position: int; mutable length: int}

let create n =
let n = if n < 1 then 1 else n in
let s = Bytes.create n in
{ buffer = s; position = 0; length = n }
{buffer = s; position = 0; length = n}

let contents b = Bytes.sub_string b.buffer 0 b.position
(* let to_bytes b = Bytes.sub b.buffer 0 b.position *)
Expand Down
2 changes: 1 addition & 1 deletion analysis/vendor/ext/ext_bytes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@

external unsafe_blit_string : string -> int -> bytes -> int -> int -> unit
= "caml_blit_string"
[@@noalloc]
[@@noalloc]
2 changes: 1 addition & 1 deletion analysis/vendor/ext/ext_bytes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@

external unsafe_blit_string : string -> int -> bytes -> int -> int -> unit
= "caml_blit_string"
[@@noalloc]
[@@noalloc]
4 changes: 3 additions & 1 deletion analysis/vendor/ext/ext_char.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
*)

let valid_hex x =
match x with '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' -> true | _ -> false
match x with
| '0' .. '9' | 'a' .. 'f' | 'A' .. 'F' -> true
| _ -> false

let is_lower_case c =
(c >= 'a' && c <= 'z')
Expand Down
10 changes: 5 additions & 5 deletions analysis/vendor/ext/ext_color.ml
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ let code_of_style = function
(** TODO: add more styles later *)
let style_of_tag s =
match s with
| Format.String_tag "error" -> [ Bold; FG Red ]
| Format.String_tag "warning" -> [ Bold; FG Magenta ]
| Format.String_tag "info" -> [ Bold; FG Yellow ]
| Format.String_tag "dim" -> [ Dim ]
| Format.String_tag "filename" -> [ FG Cyan ]
| Format.String_tag "error" -> [Bold; FG Red]
| Format.String_tag "warning" -> [Bold; FG Magenta]
| Format.String_tag "info" -> [Bold; FG Yellow]
| Format.String_tag "dim" -> [Dim]
| Format.String_tag "filename" -> [FG Cyan]
| _ -> []

let ansi_of_tag s =
Expand Down
9 changes: 1 addition & 8 deletions analysis/vendor/ext/ext_file_extensions.ml
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
type valid_input =
| Res
| Resi
| Intf_ast
| Impl_ast
| Mlmap
| Cmi
| Unknown
type valid_input = Res | Resi | Intf_ast | Impl_ast | Mlmap | Cmi | Unknown

(** This is per-file based,
when [ocamlc] [-c -o another_dir/xx.cmi]
Expand Down
Loading

0 comments on commit 384bcff

Please sign in to comment.