[sledge] Add Set.Provide_pp

Reviewed By: jvillard

Differential Revision: D25756559

fbshipit-source-id: fa55750d9
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent 8943e0eb6d
commit 0ebc74ae8c

@ -118,11 +118,20 @@ end) : S with type elt = Elt.t = struct
let to_iter = S.to_iter let to_iter = S.to_iter
let of_iter = S.of_iter let of_iter = S.of_iter
let pp ?pre ?suf ?(sep = (",@ " : (unit, unit) fmt)) pp_elt fs x = let pp_full ?pre ?suf ?(sep = (",@ " : (unit, unit) fmt)) pp_elt fs x =
List.pp ?pre ?suf sep pp_elt fs (S.elements x) List.pp ?pre ?suf sep pp_elt fs (S.elements x)
let pp_diff pp_elt fs (xs, ys) = module Provide_pp (Elt : sig
type t = elt
val pp : t pp
end) =
struct
let pp = pp_full Elt.pp
let pp_diff fs (xs, ys) =
let lose = diff xs ys and gain = diff ys xs in let lose = diff xs ys and gain = diff ys xs in
if not (is_empty lose) then Format.fprintf fs "-- %a" (pp pp_elt) lose ; if not (is_empty lose) then Format.fprintf fs "-- %a" pp lose ;
if not (is_empty gain) then Format.fprintf fs "++ %a" (pp pp_elt) gain if not (is_empty gain) then Format.fprintf fs "++ %a" pp gain
end
end end

@ -25,6 +25,27 @@ module type S = sig
end end
with type t := t with type t := t
(** {1 Pretty-print} *)
val pp_full :
?pre:(unit, unit) fmt
-> ?suf:(unit, unit) fmt
-> ?sep:(unit, unit) fmt
-> elt pp
-> t pp
module Provide_pp (_ : sig
type t = elt
val pp : t pp
end) : sig
type t
val pp : t pp
val pp_diff : (t * t) pp
end
with type t := t
(** {1 Construct} *) (** {1 Construct} *)
val empty : t val empty : t
@ -75,15 +96,4 @@ module type S = sig
val to_iter : t -> elt iter val to_iter : t -> elt iter
val of_iter : elt iter -> t val of_iter : elt iter -> t
(** {1 Pretty-print} *)
val pp :
?pre:(unit, unit) fmt
-> ?suf:(unit, unit) fmt
-> ?sep:(unit, unit) fmt
-> elt pp
-> t pp
val pp_diff : elt pp -> (t * t) pp
end end

@ -211,21 +211,23 @@ module Make (Opts : Domain_intf.Opts) (Dom : Domain_intf.Dom) = struct
type elt = {depth: int; edge: Edge.t; state: Dom.t; depths: Depths.t} type elt = {depth: int; edge: Edge.t; state: Dom.t; depths: Depths.t}
[@@deriving compare, sexp_of] [@@deriving compare, sexp_of]
module Elts = Set.Make (struct module Elt = struct
type t = elt [@@deriving compare, sexp_of] type t = elt [@@deriving compare, sexp_of]
end)
type t = {queue: elt FHeap.t; removed: Elts.t} let pp ppf {depth; edge} =
let pp_elt ppf {depth; edge} =
Format.fprintf ppf "%i: %a" depth Edge.pp edge Format.fprintf ppf "%i: %a" depth Edge.pp edge
end
module Elts = Set.Make (Elt)
type t = {queue: elt FHeap.t; removed: Elts.t}
let pp ppf {queue; removed} = let pp ppf {queue; removed} =
let rev_elts = let rev_elts =
FHeap.fold queue ~init:[] ~f:(fun rev_elts elt -> FHeap.fold queue ~init:[] ~f:(fun rev_elts elt ->
if Elts.mem elt removed then rev_elts else elt :: rev_elts ) if Elts.mem elt removed then rev_elts else elt :: rev_elts )
in in
Format.fprintf ppf "@[%a@]" (List.pp " ::@ " pp_elt) Format.fprintf ppf "@[%a@]" (List.pp " ::@ " Elt.pp)
(List.rev rev_elts) (List.rev rev_elts)
let create () = let create () =

@ -193,15 +193,15 @@ module Term = struct
one step. *) one step. *)
module T = struct module T = struct
type t = exp [@@deriving compare, equal, sexp] type t = exp [@@deriving compare, equal, sexp]
let ppx = ppx
let pp = pp
end end
include T include T
module Set = Set.Make (T) module Set = Set.Make (T)
module Map = Map.Make (T) module Map = Map.Make (T)
let ppx = ppx
let pp = pp
(* variables *) (* variables *)
let var v = `Trm (v : var :> trm) let var v = `Trm (v : var :> trm)

@ -43,11 +43,11 @@ let ppx strength fs fml =
else pp_arith_op p_c op n_d else pp_arith_op p_c op n_d
in in
let pp_join sep pos neg = let pp_join sep pos neg =
pf "(%a%t%a)" (Set.pp ~sep pp) pos pf "(%a%t%a)" (Set.pp_full ~sep pp) pos
(fun ppf -> (fun ppf ->
if (not (Set.is_empty pos)) && not (Set.is_empty neg) then if (not (Set.is_empty pos)) && not (Set.is_empty neg) then
Format.fprintf ppf sep ) Format.fprintf ppf sep )
(Set.pp ~sep (fun fs fml -> pp fs (_Not fml))) (Set.pp_full ~sep (fun fs fml -> pp fs (_Not fml)))
neg neg
in in
match fml with match fml with

@ -9,6 +9,7 @@ open Var_intf
(** Variables, parameterized over their representation *) (** Variables, parameterized over their representation *)
module Make (T : REPR) = struct module Make (T : REPR) = struct
module T = struct
include T include T
type nonrec strength = t strength type nonrec strength = t strength
@ -22,10 +23,14 @@ module Make (T : REPR) = struct
if id = 0 then Trace.pp_styled `Bold "%%%s" ppf name if id = 0 then Trace.pp_styled `Bold "%%%s" ppf name
else Format.fprintf ppf "%%%s%a" name pp_id id else Format.fprintf ppf "%%%s%a" name pp_id id
| Some `Universal -> Trace.pp_styled `Bold "%%%s%a" ppf name pp_id id | Some `Universal -> Trace.pp_styled `Bold "%%%s%a" ppf name pp_id id
| Some `Existential -> Trace.pp_styled `Cyan "%%%s%a" ppf name pp_id id | Some `Existential ->
Trace.pp_styled `Cyan "%%%s%a" ppf name pp_id id
| Some `Anonymous -> Trace.pp_styled `Cyan "_" ppf | Some `Anonymous -> Trace.pp_styled `Cyan "_" ppf
let pp = ppx (fun _ -> None) let pp = ppx (fun _ -> None)
end
include T
module Map = struct module Map = struct
include NS.Map.Make (T) include NS.Map.Make (T)
@ -33,13 +38,12 @@ module Make (T : REPR) = struct
end end
module Set = struct module Set = struct
let pp_t = pp module S = NS.Set.Make (T)
include S
include NS.Set.Make (T)
include Provide_of_sexp (T) include Provide_of_sexp (T)
include Provide_pp (T)
let ppx strength vs = pp (ppx strength) vs let ppx strength vs = S.pp_full (ppx strength) vs
let pp vs = pp pp_t vs
let pp_xs fs xs = let pp_xs fs xs =
if not (is_empty xs) then if not (is_empty xs) then

@ -36,6 +36,7 @@ module type VAR = sig
val ppx : strength -> t pp val ppx : strength -> t pp
val pp : t pp val pp : t pp
val pp_xs : t pp val pp_xs : t pp
val pp_diff : (t * t) pp
end end
val id : t -> int val id : t -> int

@ -73,28 +73,16 @@ module T = struct
| Ap3 of op3 * Typ.t * t * t * t | Ap3 of op3 * Typ.t * t * t * t
| ApN of opN * Typ.t * t iarray | ApN of opN * Typ.t * t iarray
[@@deriving compare, equal, hash, sexp] [@@deriving compare, equal, hash, sexp]
end
include T
module Set = struct let demangle = ref (fun _ -> None)
include Set.Make (T)
include Provide_hash (T)
include Provide_of_sexp (T)
end
module Map = Map.Make (T) let pp_demangled ppf name =
module Tbl = HashTable.Make (T)
let demangle = ref (fun _ -> None)
let pp_demangled ppf name =
match !demangle name with match !demangle name with
| Some demangled when not (String.equal name demangled) -> | Some demangled when not (String.equal name demangled) ->
Format.fprintf ppf "“%s”" demangled Format.fprintf ppf "“%s”" demangled
| _ -> () | _ -> ()
let pp_op2 fs op = let pp_op2 fs op =
let pf fmt = Format.fprintf fs fmt in let pf fmt = Format.fprintf fs fmt in
match op with match op with
| Eq -> pf "=" | Eq -> pf "="
@ -124,7 +112,7 @@ let pp_op2 fs op =
| Ashr -> pf "ashr" | Ashr -> pf "ashr"
| Update idx -> pf "[_|%i→_]" idx | Update idx -> pf "[_|%i→_]" idx
let rec pp fs exp = let rec pp fs exp =
let pf fmt = let pf fmt =
Format.pp_open_box fs 2 ; Format.pp_open_box fs 2 ;
Format.kfprintf (fun fs -> Format.pp_close_box fs ()) fs fmt Format.kfprintf (fun fs -> Format.pp_close_box fs ()) fs fmt
@ -157,7 +145,7 @@ let rec pp fs exp =
| ApN (Record, _, elts) -> pf "{%a}" pp_record elts | ApN (Record, _, elts) -> pf "{%a}" pp_record elts
[@@warning "-9"] [@@warning "-9"]
and pp_record fs elts = and pp_record fs elts =
match match
String.init (IArray.length elts) ~f:(fun i -> String.init (IArray.length elts) ~f:(fun i ->
match IArray.get elts i with match IArray.get elts i with
@ -166,7 +154,20 @@ and pp_record fs elts =
| _ -> raise_notrace (Invalid_argument "not a string") ) | _ -> raise_notrace (Invalid_argument "not a string") )
with with
| s -> Format.fprintf fs "@[<h>%s@]" (String.escaped s) | s -> Format.fprintf fs "@[<h>%s@]" (String.escaped s)
| exception _ -> Format.fprintf fs "@[<hv>%a@]" (IArray.pp ",@ " pp) elts | exception _ ->
Format.fprintf fs "@[<hv>%a@]" (IArray.pp ",@ " pp) elts
end
include T
module Set = struct
include Set.Make (T)
include Provide_hash (T)
include Provide_of_sexp (T)
end
module Map = Map.Make (T)
module Tbl = HashTable.Make (T)
(** Invariant *) (** Invariant *)
@ -281,18 +282,13 @@ and typ_of exp =
typ typ
[@@warning "-9"] [@@warning "-9"]
let pp_exp = pp
(** Registers are the expressions constructed by [Reg] *) (** Registers are the expressions constructed by [Reg] *)
module Reg = struct module Reg = struct
include T include T
let pp = pp
module Set = struct module Set = struct
include Set include Set
include Provide_pp (T)
let pp = Set.pp pp_exp
end end
let invariant x = let invariant x =
@ -313,12 +309,9 @@ end
module Global = struct module Global = struct
include T include T
let pp = pp
module Set = struct module Set = struct
include Set include Set
include Provide_pp (T)
let pp = Set.pp pp_exp
end end
let invariant x = let invariant x =
@ -339,7 +332,6 @@ end
module Function = struct module Function = struct
include T include T
let pp = pp
let name = function Function x -> x.name | r -> violates invariant r let name = function Function x -> x.name | r -> violates invariant r
let typ = function Function x -> x.typ | r -> violates invariant r let typ = function Function x -> x.typ | r -> violates invariant r

@ -182,8 +182,7 @@ let pp_us ?vs fs us =
[%Trace.fprintf fs "@<2>∀ @[%a@] .@ " Var.Set.pp us] [%Trace.fprintf fs "@<2>∀ @[%a@] .@ " Var.Set.pp us]
| Some vs -> | Some vs ->
if not (Var.Set.equal vs us) then if not (Var.Set.equal vs us) then
[%Trace.fprintf [%Trace.fprintf fs "@<2>∀ @[%a@] .@ " Var.Set.pp_diff (vs, us)]
fs "@<2>∀ @[%a@] .@ " (Var.Set.pp_diff Var.pp) (vs, us)]
let rec pp_ ?var_strength ?vs ancestor_xs parent_ctx fs let rec pp_ ?var_strength ?vs ancestor_xs parent_ctx fs
{us; xs; ctx; pure; heap; djns} = {us; xs; ctx; pure; heap; djns} =

Loading…
Cancel
Save