Skip to content

Commit

Permalink
Make Digest type abstract (ocaml#1623)
Browse files Browse the repository at this point in the history
* Make Digest type abstract

Signed-off-by: Rudi Grinberg <[email protected]>

* Rename Digest.to_string to to_string_raw

Signed-off-by: Rudi Grinberg <[email protected]>

* Rename to_hex to to_string

Signed-off-by: Rudi Grinberg <[email protected]>

* Make Deps.trace return digests

Signed-off-by: Rudi Grinberg <[email protected]>
  • Loading branch information
rgrinberg authored Dec 11, 2018
1 parent a583d1b commit b515a86
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/action_exec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ let rec exec t ~ectx ~dir ~env ~stdout_to ~stderr_to =
Digest.string
(Marshal.to_string data [])
in
exec_echo stdout_to s
exec_echo stdout_to (Digest.to_string_raw s)
| Diff { optional; file1; file2; mode } ->
let compare_files =
match mode with
Expand Down
6 changes: 3 additions & 3 deletions src/build_system.ml
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ let rec compile_rule t ?(copy_source=false) pre_rule =
in
let sandbox_dir =
if sandbox then
Some (Path.relative sandbox_dir (Digest.to_hex rule_digest))
Some (Path.relative sandbox_dir (Digest.to_string rule_digest))
else
None
in
Expand Down Expand Up @@ -1007,7 +1007,7 @@ and load_dir_step2_exn t ~dir ~collector ~lazy_generators =
{ Dir_status. stamp; action; locks ; context ; loc ; env } ->
let path =
Path.extend_basename base_path
~suffix:("-" ^ Digest.to_hex stamp)
~suffix:("-" ^ Digest.to_string stamp)
in
let rule =
Pre_rule.make ~locks ~context:(Some context) ~env ?loc
Expand Down Expand Up @@ -1218,7 +1218,7 @@ let stamp_file_for_files_of t ~dir ~ext =
|> String.Map.of_list_multi
in
{ files_by_ext
; dir_hash = Path.to_string dir |> Digest.string |> Digest.to_hex
; dir_hash = Path.to_string dir |> Digest.string |> Digest.to_string
; stamps = String.Map.empty
})
in
Expand Down
6 changes: 4 additions & 2 deletions src/deps.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ let paths t = t.paths
let trace_path fn =
(Path.to_string fn, Utils.Cached_digest.file fn)

let unset = lazy (Digest.string "unset")

let trace_var env var =
let value =
match Env.get env var with
| None -> "unset"
| Some v -> Digest.string v |> Digest.to_hex
| None -> Lazy.force unset
| Some v -> Digest.string v
in
(var, value)

Expand Down
2 changes: 1 addition & 1 deletion src/deps.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ val add_env_var : t -> string -> t

(** [trace t] is an abstract value that is guaranteed to change if the set of
dependencies denoted by t changes, modulo hash collisions. *)
val trace : t -> Env.t -> (string * string) list
val trace : t -> Env.t -> (string * Digest.t) list

(** Return the path dependencies only. *)
val paths : t -> Path.Set.t
Expand Down
4 changes: 3 additions & 1 deletion src/dune_lang/atom.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Stdune

type t = A of string [@@unboxed]

let invalid_argf fmt = Printf.ksprintf invalid_arg fmt
Expand Down Expand Up @@ -51,5 +53,5 @@ let print ((A s) as t) syntax =
let of_int i = of_string (string_of_int i)
let of_float x = of_string (string_of_float x)
let of_bool x = of_string (string_of_bool x)
let of_digest d = of_string (Digest.to_hex d)
let of_digest d = of_string (Digest.to_string d)
let of_int64 i = of_string (Int64.to_string i)
2 changes: 2 additions & 0 deletions src/dune_lang/atom.mli
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
open Stdune

type t = private A of string [@@unboxed]

val is_valid_dune : string -> bool
Expand Down
4 changes: 2 additions & 2 deletions src/preprocessing.ml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ end = struct
| Some x -> x
| None ->
die "I don't know what ppx rewriters set %s correspond to."
(Digest.to_hex y)
(Digest.to_string y)
end

let pped_path path ~suffix =
Expand Down Expand Up @@ -457,7 +457,7 @@ let gen_rules sctx components =
| _ -> ()

let ppx_driver_exe sctx libs ~dir_kind =
let key = Digest.to_hex (Key.of_libs ~dir_kind libs |> Key.encode) in
let key = Digest.to_string (Key.of_libs ~dir_kind libs |> Key.encode) in
ppx_exe sctx ~key ~dir_kind

module Compat_ppx_exe_kind = struct
Expand Down
8 changes: 4 additions & 4 deletions src/report_error.ml
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ let report_with_backtrace exn =
| Some p -> p
| None -> exn_printer exn

let reported = ref String.Set.empty
let reported = ref Digest.Set.empty

let clear_cache () =
reported := String.Set.empty
reported := Digest.Set.empty

let () = Hooks.End_of_build.always clear_cache

Expand All @@ -123,10 +123,10 @@ let report exn =
let s = Buffer.contents err_buf in
(* Hash to avoid keeping huge errors in memory *)
let hash = Digest.string s in
if String.Set.mem !reported hash then
if Digest.Set.mem !reported hash then
Buffer.clear err_buf
else begin
reported := String.Set.add !reported hash;
reported := Digest.Set.add !reported hash;
if p.backtrace || !Clflags.debug_backtraces then
Format.fprintf ppf "Backtrace:\n%s"
(Printexc.raw_backtrace_to_string backtrace);
Expand Down
1 change: 1 addition & 0 deletions src/stdune/caml/dune_caml.ml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Char = Char
module Result = Result
module Hashtbl = MoreLabels.Hashtbl
module Lexing = Lexing
module Digest = Digest

type ('a, 'error) result = ('a, 'error) Result.t =
| Ok of 'a
Expand Down
17 changes: 17 additions & 0 deletions src/stdune/digest.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
type t = string

module D = Dune_caml.Digest

module Set = String.Set

let file p = D.file (Path.to_string p)

let compare x y = Ordering.of_int (D.compare x y)

let to_string = D.to_hex

let from_hex = D.from_hex

let string = D.string

let to_string_raw s = s
15 changes: 15 additions & 0 deletions src/stdune/digest.mli
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
type t

module Set : Set.S with type elt = t

val compare : t -> t -> Ordering.t

val to_string : t -> string

val from_hex : string -> t

val file : Path.t -> t

val string : string -> t

val to_string_raw : t -> string
1 change: 1 addition & 0 deletions src/stdune/stdune.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ module Proc = Proc
module Type_eq = Type_eq
module Nothing = Nothing
module Bin = Bin
module Digest = Digest

external reraise : exn -> _ = "%reraise"

Expand Down
2 changes: 1 addition & 1 deletion src/utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ module Cached_digest = struct
if stat.Unix.st_kind = Unix.S_DIR then
dir_digest stat
else
Digest.file (Path.to_string fn)
Digest.file fn

let refresh fn =
let path = Path.to_string fn in
Expand Down

0 comments on commit b515a86

Please sign in to comment.