[sledge] Add Theory.oriented_equality type for code readability

Summary:
Theory.solved is a list of pairs of terms representing solved
equalities. The order of the pairs is very important, which is not
apparent from the type. This diff introduces an oriented_equality type
to make this more clear.

Reviewed By: jvillard

Differential Revision: D26451303

fbshipit-source-id: 56a49e601
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent 5cdd3cd781
commit 6fb29dac90

@ -583,7 +583,7 @@ let update_rep noninterp ~from:r ~to_:r' x =
{x with rep; cls; use} {x with rep; cls; use}
(** add v ↦ t to x *) (** add v ↦ t to x *)
let propagate1 (v, t) x = let propagate1 {Theory.var= v; rep= t} x =
[%trace] [%trace]
~call:(fun {pf} -> ~call:(fun {pf} ->
pf "@ @[%a ↦ %a@]@ %a" Trm.pp v Trm.pp t pp_raw x ; pf "@ @[%a ↦ %a@]@ %a" Trm.pp v Trm.pp t pp_raw x ;
@ -985,8 +985,8 @@ let rec solve_pending (s : Theory.t) soln =
match Theory.solve a' b' {s with pending} with match Theory.solve a' b' {s with pending} with
| {solved= Some solved} as s -> | {solved= Some solved} as s ->
solve_pending {s with solved= Some []} solve_pending {s with solved= Some []}
(List.fold solved soln ~f:(fun (trm, rep) soln -> (List.fold solved soln ~f:(fun {var; rep} soln ->
Subst.compose1 ~key:trm ~data:rep soln )) Subst.compose1 ~key:var ~data:rep soln ))
| {solved= None} -> None ) | {solved= None} -> None )
| [] -> Some soln | [] -> Some soln

@ -9,18 +9,20 @@
(* Theory equation solver state ===========================================*) (* Theory equation solver state ===========================================*)
type oriented_equality = {var: Trm.t; rep: Trm.t}
type t = type t =
{ wrt: Var.Set.t { wrt: Var.Set.t
; no_fresh: bool ; no_fresh: bool
; fresh: Var.Set.t ; fresh: Var.Set.t
; solved: (Trm.t * Trm.t) list option ; solved: oriented_equality list option
; pending: (Trm.t * Trm.t) list } ; pending: (Trm.t * Trm.t) list }
let pp ppf = function let pp ppf = function
| {solved= None} -> Format.fprintf ppf "unsat" | {solved= None} -> Format.fprintf ppf "unsat"
| {solved= Some solved; fresh; pending} -> | {solved= Some solved; fresh; pending} ->
Format.fprintf ppf "%a%a : %a" Var.Set.pp_xs fresh Format.fprintf ppf "%a%a : %a" Var.Set.pp_xs fresh
(List.pp ";@ " (fun ppf (var, rep) -> (List.pp ";@ " (fun ppf {var; rep} ->
Format.fprintf ppf "@[%a ↦ %a@]" Trm.pp var Trm.pp rep )) Format.fprintf ppf "@[%a ↦ %a@]" Trm.pp var Trm.pp rep ))
solved solved
(List.pp ";@ " (fun ppf (a, b) -> (List.pp ";@ " (fun ppf (a, b) ->
@ -102,7 +104,7 @@ let orient e f =
let add_solved ~var ~rep s = let add_solved ~var ~rep s =
match s with match s with
| {solved= None} -> s | {solved= None} -> s
| {solved= Some solved} -> {s with solved= Some ((var, rep) :: solved)} | {solved= Some solved} -> {s with solved= Some ({var; rep} :: solved)}
let add_pending a b s = {s with pending= (a, b) :: s.pending} let add_pending a b s = {s with pending= (a, b) :: s.pending}

@ -7,11 +7,13 @@
(** Theory Solver *) (** Theory Solver *)
type oriented_equality = {var: Trm.t; rep: Trm.t}
type t = type t =
{ wrt: Var.Set.t { wrt: Var.Set.t
; no_fresh: bool ; no_fresh: bool
; fresh: Var.Set.t ; fresh: Var.Set.t
; solved: (Trm.t * Trm.t) list option ; solved: oriented_equality list option
; pending: (Trm.t * Trm.t) list } ; pending: (Trm.t * Trm.t) list }
val pp : t pp val pp : t pp

Loading…
Cancel
Save