Skip to content

Commit

Permalink
chore(ocamlformat): use the janestreet profile (ocaml#8319)
Browse files Browse the repository at this point in the history
We often have to push changes between the public repository and the internal version that Jane Street is using.
Switching to the janestreet profile makes this much easier in terms of conflict resolution.

Signed-off-by: Etienne Millon <me@emillon.org>
  • Loading branch information
emillon authored Aug 4, 2023
1 parent aaf6305 commit cb8f84e
Show file tree
Hide file tree
Showing 982 changed files with 37,439 additions and 34,645 deletions.
11 changes: 1 addition & 10 deletions .ocamlformat
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
version=0.26.0
profile=conventional
profile=janestreet
ocaml-version=4.08.0
break-separators=before
dock-collection-brackets=false
doc-comments=before
let-and=sparse
type-decl=sparse
cases-exp-indent=2
break-cases=fit-or-vertical
parse-docstrings=true
module-item-spacing=sparse
1 change: 1 addition & 0 deletions .ocamlformat-ignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
boot/libs.ml
src/dune_rules/assets.ml
src/dune_rules/setup.defaults.ml
163 changes: 88 additions & 75 deletions bench/bench.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,22 @@ module Output = struct

type bench =
{ name : string
; metrics :
(string * [ measurement | `List of measurement list ] * string) list
; metrics : (string * [ measurement | `List of measurement list ] * string) list
}

let json_of_bench { name; metrics } : Json.t =
let metrics =
List.map metrics ~f:(fun (name, value, units) ->
let value =
match value with
| `Int i -> `Int i
| `Float f -> `Float f
| `List xs -> `List (xs :> Json.t list)
in
`Assoc
[ ("name", `String name)
; ("value", value)
; ("units", `String units)
])
let value =
match value with
| `Int i -> `Int i
| `Float f -> `Float f
| `List xs -> `List (xs :> Json.t list)
in
`Assoc [ "name", `String name; "value", value; "units", `String units ])
in
`Assoc [ ("name", `String name); ("metrics", `List metrics) ]
`Assoc [ "name", `String name; "metrics", `List metrics ]
;;

type t =
{ config : (string * Json.t) list
Expand All @@ -48,22 +44,22 @@ module Output = struct
}

let to_json { config; version; results } : Json.t =
let assoc = [ ("results", `List (List.map results ~f:json_of_bench)) ] in
let assoc = [ "results", `List (List.map results ~f:json_of_bench) ] in
let assoc = ("version", `Int version) :: assoc in
let assoc =
match config with
| [] -> assoc
| _ :: _ -> ("config", `Assoc config) :: assoc
in
`Assoc assoc
;;
end

let git =
lazy
(let path =
Env.get Env.initial "PATH" |> Option.value_exn |> Bin.parse_path
in
(let path = Env.get Env.initial "PATH" |> Option.value_exn |> Bin.parse_path in
Bin.which ~path "git" |> Option.value_exn)
;;

let dune = Path.of_string (Filename.concat Fpath.initial_cwd Sys.argv.(1))

Expand All @@ -74,31 +70,37 @@ module Package = struct
}

let uri { org; name } = sprintf "https://github.com/%s/%s" org name

let make org name = { org; name }

let clone t =
let stdout_to = Process.Io.make_stdout Swallow in
let stderr_to = Process.Io.make_stderr Swallow in
let stdin_from = Process.Io.(null In) in
Process.run Strict ~display:Quiet ~stdout_to ~stderr_to ~stdin_from
Process.run
Strict
~display:Quiet
~stdout_to
~stderr_to
~stdin_from
(Lazy.force git)
[ "clone"; uri t ]
;;
end

let duniverse =
let pkg = Package.make in
[ pkg "ocaml-dune" "dune-bench" ]
;;

let prepare_workspace () =
Fiber.parallel_iter duniverse ~f:(fun (pkg : Package.t) ->
Fpath.rm_rf pkg.name;
Console.printf "cloning %s/%s" pkg.org pkg.name;
Fiber.finalize
(fun () -> Package.clone pkg)
~finally:(fun () ->
Fiber.return
@@ Console.printf "finished cloning %s/%s" pkg.org pkg.name))
Fpath.rm_rf pkg.name;
Console.printf "cloning %s/%s" pkg.org pkg.name;
Fiber.finalize
(fun () -> Package.clone pkg)
~finally:(fun () ->
Fiber.return @@ Console.printf "finished cloning %s/%s" pkg.org pkg.name))
;;

let dune_build ~name ~sandbox =
let stdin_from = Process.(Io.null In) in
Expand All @@ -108,7 +110,12 @@ let dune_build ~name ~sandbox =
let open Fiber.O in
(* Build with timings and gc stats *)
let+ times =
Process.run_with_times dune ~display:Quiet ~stdin_from ~stdout_to ~stderr_to
Process.run_with_times
dune
~display:Quiet
~stdin_from
~stdout_to
~stderr_to
([ "build"
; "@install"
; "--release"
Expand All @@ -117,37 +124,42 @@ let dune_build ~name ~sandbox =
; "--dump-gc-stats"
; Path.to_string gc_dump
]
@
match sandbox with
| `Yes -> [ "--sandbox"; "hardlink" ]
| `No -> [])
@
match sandbox with
| `Yes -> [ "--sandbox"; "hardlink" ]
| `No -> [])
in
(* Read the gc stats from the dump file *)
Dune_lang.Parser.parse_string ~mode:Single ~fname:(Path.to_string gc_dump)
Dune_lang.Parser.parse_string
~mode:Single
~fname:(Path.to_string gc_dump)
(Io.read_file gc_dump)
|> Dune_lang.Decoder.parse Dune_util.Gc.decode Univ_map.empty
|> Metrics.make times
;;

let dune_clean () =
let stdin_from = Process.(Io.null In) in
let stdout_to = Process.Io.make_stdout Swallow in
let stderr_to = Process.Io.make_stderr Swallow in
Process.run Strict ~display:Quiet ~stdout_to ~stderr_to ~stdin_from dune
[ "clean" ]
Process.run Strict ~display:Quiet ~stdout_to ~stderr_to ~stdin_from dune [ "clean" ]
;;

let run_bench ~sandbox =
let open Fiber.O in
let* clean = dune_build ~name:"clean" ~sandbox in
let+ zero =
let rec zero acc n =
if n = 0 then Fiber.return (List.rev acc)
if n = 0
then Fiber.return (List.rev acc)
else
let* time = dune_build ~name:("zero" ^ string_of_int n) ~sandbox in
zero (time :: acc) (pred n)
in
zero [] 5
in
(clean, zero)
clean, zero
;;

type ('float, 'int) bench_results =
{ size : int
Expand All @@ -160,43 +172,47 @@ type ('float, 'int) bench_results =
let tag_results { size; clean; zero; clean_sandbox; zero_sandbox } =
let tag data = Metrics.map ~f:(fun t -> `Float t) ~g:(fun t -> `Int t) data in
let list_tag data =
List.map data ~f:tag |> Metrics.unzip
List.map data ~f:tag
|> Metrics.unzip
|> Metrics.map ~f:(fun x -> `List x) ~g:(fun x -> `List x)
in
(`Int size, tag clean, list_tag zero, tag clean_sandbox, list_tag zero_sandbox)
`Int size, tag clean, list_tag zero, tag clean_sandbox, list_tag zero_sandbox
;;

(** Display all clean and null builds with a few exceptions:
- fragments - not consistent between builds
- stack_size - not very useful
- forced_collections - only available in OCaml >= 4.12 *)
let display_clean_and_zero ~name_suffix
({ elapsed_time
; user_cpu_time
; system_cpu_time
; minor_words
; promoted_words
; major_words
; minor_collections
; major_collections
; heap_words
; heap_chunks
; live_words
; live_blocks
; free_words
; free_blocks
; largest_free
; fragments = _
; compactions
; top_heap_words
; stack_size = _
} :
_ Metrics.t) (zero : _ Metrics.t) =
let display_clean_and_zero
~name_suffix
({ elapsed_time
; user_cpu_time
; system_cpu_time
; minor_words
; promoted_words
; major_words
; minor_collections
; major_collections
; heap_words
; heap_chunks
; live_words
; live_blocks
; free_words
; free_blocks
; largest_free
; fragments = _
; compactions
; top_heap_words
; stack_size = _
} :
_ Metrics.t)
(zero : _ Metrics.t)
=
(* Display single what stat clean and null build *)
let display what units clean zero =
{ Output.name = what ^ name_suffix
; metrics =
[ ("[Clean] " ^ what, clean, units); ("[Null] " ^ what, zero, units) ]
; metrics = [ "[Clean] " ^ what, clean, units; "[Null] " ^ what, zero, units ]
}
in
[ display "Build Time" "Seconds" elapsed_time zero.elapsed_time
Expand All @@ -205,10 +221,8 @@ let display_clean_and_zero ~name_suffix
; display "Minor Words" "Approx. Words" minor_words zero.minor_words
; display "Promoted Words" "Approx. Words" promoted_words zero.promoted_words
; display "Major Words" "Approx. Words" major_words zero.major_words
; display "Minor Collections" "Collections" minor_collections
zero.minor_collections
; display "Major Collections" "Collections" major_collections
zero.major_collections
; display "Minor Collections" "Collections" minor_collections zero.minor_collections
; display "Major Collections" "Collections" major_collections zero.major_collections
; display "Heap Words" "Words" heap_words zero.heap_words
; display "Heap Chunks" "Chunks" heap_chunks zero.heap_chunks
; display "Live Words" "Words" live_words zero.live_words
Expand All @@ -219,21 +233,18 @@ let display_clean_and_zero ~name_suffix
; display "Compactions" "Compactions" compactions zero.compactions
; display "Top Heap Words" "Words" top_heap_words zero.top_heap_words
]
;;

let format_results bench_results =
(* tagging data for json conversion *)
let size, clean, zero, clean_sandbox, zero_sandbox =
tag_results bench_results
in
let size, clean, zero, clean_sandbox, zero_sandbox = tag_results bench_results in
(* bench results *)
[ { Output.name = "Misc"
; metrics = [ ("Size of _boot/dune.exe", size, "Bytes") ]
}
]
[ { Output.name = "Misc"; metrics = [ "Size of _boot/dune.exe", size, "Bytes" ] } ]
(* clean and null builds *)
@ display_clean_and_zero ~name_suffix:"" clean zero
(* clean and null builds with sandbox *)
@ display_clean_and_zero ~name_suffix:" [sandbox]" clean_sandbox zero_sandbox
;;

let () =
Dune_util.Log.init ~file:No_log_file ();
Expand All @@ -256,7 +267,8 @@ let () =
stat.st_size
in
let results =
Scheduler.Run.go config ~on_event:(fun _ _ -> ()) @@ fun () ->
Scheduler.Run.go config ~on_event:(fun _ _ -> ())
@@ fun () ->
let open Fiber.O in
(* Prepare the workspace *)
let* () = prepare_workspace () in
Expand All @@ -277,3 +289,4 @@ let () =
let output = { Output.config = []; version; results } in
print_string (Json.to_string (Output.to_json output));
flush stdout
;;
4 changes: 3 additions & 1 deletion bench/gen_synthetic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ let write_modules basedir num_modules =
let f = open_out (sprintf "%s.ml" modname) in
close_out f
done
;;

let dune = {|
(library
Expand All @@ -18,6 +19,7 @@ let write basedir =
output_string f dune;
let () = close_out f in
write_modules basedir
;;

let () =
let basedir = ref "." in
Expand All @@ -29,5 +31,5 @@ let () =
]
(fun d -> basedir := d)
(sprintf "usage: %s [basedir]" (Filename.basename Sys.argv.(0)));

write !basedir !num_modules
;;
Loading

0 comments on commit cb8f84e

Please sign in to comment.