[sledge] Minor simplifications using Set and Map iterators

Reviewed By: jvillard

Differential Revision: D24313893

fbshipit-source-id: 8275b3127
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent 920c553902
commit 2083e3ee86

@ -95,8 +95,8 @@ let used_globals pgm preanalyze : Domain_used_globals.r =
(Llair.Reg.Map.map summary_table ~f:Llair.Reg.Set.union_list)
else
Declared
(IArray.fold pgm.globals Llair.Reg.Set.empty ~f:(fun g ->
Llair.Reg.Set.add g.reg ))
(Llair.Reg.Set.of_iter
(Iter.map ~f:(fun g -> g.reg) (IArray.to_iter pgm.globals)))
let analyze =
let%map_open bound =

@ -12,6 +12,7 @@ module Import = struct
end
let mem elt seq ~eq = mem ~eq ~x:elt seq
let map seq ~f = map ~f seq
let sort seq ~cmp = sort ~cmp seq
let sort_uniq seq ~cmp = sort_uniq ~cmp seq
let sorted seq ~cmp = sorted ~cmp seq

@ -12,6 +12,7 @@ module Import : sig
end
val mem : 'a -> 'a t -> eq:('a -> 'a -> bool) -> bool
val map : 'a t -> f:('a -> 'b) -> 'b t
val sort : 'a t -> cmp:('a -> 'a -> int) -> 'a t
val sort_uniq : 'a t -> cmp:('a -> 'a -> int) -> 'a t
val sorted : 'a t -> cmp:('a -> 'a -> int) -> bool

@ -162,6 +162,9 @@ end) : S with type key = Key.t = struct
let keys = M.keys
let values = M.values
let to_iter = M.to_iter
let to_list = M.to_list
let of_iter = M.of_iter
let of_list = M.of_list
let to_iter2 l r =
let seq = ref Iter.empty in

@ -112,6 +112,9 @@ module type S = sig
val keys : 'a t -> key iter
val values : 'a t -> 'a iter
val to_iter : 'a t -> (key * 'a) iter
val to_list : 'a t -> (key * 'a) list
val of_iter : (key * 'a) iter -> 'a t
val of_list : (key * 'a) list -> 'a t
val to_iter2 :
'a t

@ -33,15 +33,13 @@ struct
let sexp_of_t s =
List.sexp_of_t
(Sexplib.Conv.sexp_of_pair Elt.sexp_of_t Mul.sexp_of_t)
(Iter.to_list (M.to_iter s))
(M.to_list s)
let t_of_sexp elt_of_sexp sexp =
List.fold_left
~f:(fun m (key, data) -> M.add_exn ~key ~data m)
M.of_list
(List.t_of_sexp
(Sexplib.Conv.pair_of_sexp elt_of_sexp Mul.t_of_sexp)
sexp)
M.empty
let pp sep pp_elt fs s =
List.pp sep pp_elt fs (Iter.to_list (M.to_iter s))

@ -80,6 +80,7 @@ end) : S with type elt = Elt.t = struct
let for_all s ~f = S.for_all f s
let fold s z ~f = S.fold f s z
let to_iter = S.to_iter
let of_iter = S.of_iter
let pp ?pre ?suf ?(sep = (",@ " : (unit, unit) fmt)) pp_elt fs x =
List.pp ?pre ?suf sep pp_elt fs (S.elements x)

@ -60,6 +60,7 @@ module type S = sig
(** {1 Convert} *)
val to_iter : t -> elt iter
val of_iter : elt iter -> t
(** {1 Pretty-print} *)

@ -853,9 +853,7 @@ let v_to_ses : var -> Ses.Var.t =
fun v -> Ses.Var.identified ~id:(Var.id v) ~name:(Var.name v)
let vs_to_ses : Var.Set.t -> Ses.Var.Set.t =
fun vs ->
Var.Set.fold vs Ses.Var.Set.empty ~f:(fun v ->
Ses.Var.Set.add (v_to_ses v) )
fun vs -> Ses.Var.Set.of_iter (Iter.map ~f:v_to_ses (Var.Set.to_iter vs))
let rec arith_to_ses poly =
Arith.fold_monomials poly Ses.Term.zero ~f:(fun mono coeff e ->
@ -936,8 +934,7 @@ let v_of_ses : Ses.Var.t -> var =
fun v -> Var.identified ~id:(Ses.Var.id v) ~name:(Ses.Var.name v)
let vs_of_ses : Ses.Var.Set.t -> Var.Set.t =
fun vs ->
Ses.Var.Set.fold ~f:(fun v -> Var.Set.add (v_of_ses v)) vs Var.Set.empty
fun vs -> Var.Set.of_iter (Iter.map ~f:v_of_ses (Ses.Var.Set.to_iter vs))
let uap1 f = ap1t (fun x -> _Apply f [|x|])
let uap2 f = ap2t (fun x y -> _Apply f [|x; y|])

@ -16,9 +16,7 @@ let reg r =
let global = Llair.Reg.is_global r in
Var.program ~name ~global
let regs rs =
Llair.Reg.Set.fold ~f:(fun r -> Var.Set.add (reg r)) rs Var.Set.empty
let regs rs = Var.Set.of_iter (Iter.map ~f:reg (Llair.Reg.Set.to_iter rs))
let uap0 f = T.apply f [||]
let uap1 f a = T.apply f [|a|]
let uap2 f a b = T.apply f [|a; b|]

@ -94,12 +94,8 @@ module Make (T : REPR) = struct
|> check (fun ({sub; _}, _) -> invariant sub)
let fold sub z ~f = Map.fold ~f:(fun ~key ~data -> f key data) sub z
let domain sub =
Map.fold ~f:(fun ~key ~data:_ -> Set.add key) sub Set.empty
let range sub =
Map.fold ~f:(fun ~key:_ ~data -> Set.add data) sub Set.empty
let domain sub = Set.of_iter (Map.keys sub)
let range sub = Set.of_iter (Map.values sub)
let invert sub =
Map.fold sub empty ~f:(fun ~key ~data sub' ->

Loading…
Cancel
Save