[sledge] Allow more flexibility in Trace.trace breaking

Reviewed By: jvillard

Differential Revision: D25756584

fbshipit-source-id: b555b1d77
master
Josh Berdine 4 years ago committed by Facebook GitHub Bot
parent 93abf301c9
commit 11c8ba21be

@ -134,7 +134,7 @@ let rec apron_texpr_of_llair_exp exp q =
let assign reg exp q =
[%Trace.call fun {pf} ->
pf "{%a}@\n%a := %a" pp q Llair.Reg.pp reg Llair.Exp.pp exp]
pf "@ {%a}@\n%a := %a" pp q Llair.Reg.pp reg Llair.Exp.pp exp]
;
let lval = apron_var_of_reg reg in
( match apron_texpr_of_llair_exp exp q with

@ -316,7 +316,7 @@ let rec xlate_type : x -> Llvm.lltype -> Typ.t =
| Void | Label | Metadata -> assert false
in
LltypeTbl.find_or_add memo_type llt ~default:(fun () ->
[%Trace.call fun {pf} -> pf "%a" pp_lltype llt]
[%Trace.call fun {pf} -> pf "@ %a" pp_lltype llt]
;
xlate_type_ llt
|>
@ -538,7 +538,7 @@ and xlate_value ?(inline = false) : x -> Llvm.llvalue -> Inst.t list * Exp.t
fail "xlate_value: %a" pp_llvalue llv ()
in
ValTbl.find_or_add memo_value (inline, llv) ~default:(fun () ->
[%Trace.call fun {pf} -> pf "%a" pp_llvalue llv]
[%Trace.call fun {pf} -> pf "@ %a" pp_llvalue llv]
;
xlate_value_ llv
|>
@ -547,7 +547,7 @@ and xlate_value ?(inline = false) : x -> Llvm.llvalue -> Inst.t list * Exp.t
and xlate_opcode : x -> Llvm.llvalue -> Llvm.Opcode.t -> Inst.t list * Exp.t
=
fun x llv opcode ->
[%Trace.call fun {pf} -> pf "%a" pp_llvalue llv]
[%Trace.call fun {pf} -> pf "@ %a" pp_llvalue llv]
;
let xlate_rand i = xlate_value x (Llvm.operand llv i) in
let typ = lazy (xlate_type x (Llvm.type_of llv)) in
@ -699,7 +699,7 @@ and xlate_opcode : x -> Llvm.llvalue -> Llvm.Opcode.t -> Inst.t list * Exp.t
else
let rec xlate_indices i =
[%Trace.call fun {pf} ->
pf "%i %a" i pp_llvalue (Llvm.operand llv i)]
pf "@ %i %a" i pp_llvalue (Llvm.operand llv i)]
;
let pre_i, arg_i = xlate_rand i in
let idx =
@ -762,7 +762,7 @@ and xlate_opcode : x -> Llvm.llvalue -> Llvm.Opcode.t -> Inst.t list * Exp.t
and xlate_global : x -> Llvm.llvalue -> GlobalDefn.t =
fun x llg ->
GlobTbl.find_or_add memo_global llg ~default:(fun () ->
[%Trace.call fun {pf} -> pf "%a" pp_llvalue llg]
[%Trace.call fun {pf} -> pf "@ %a" pp_llvalue llg]
;
let g = Global.mk (xlate_type x (Llvm.type_of llg)) (find_name llg) in
let loc = find_loc llg in
@ -1039,7 +1039,7 @@ let xlate_instr :
-> ((Llair.inst list * Llair.term -> code) -> code)
-> code =
fun pop x instr continue ->
[%Trace.call fun {pf} -> pf "%a" pp_llvalue instr]
[%Trace.call fun {pf} -> pf "@ %a" pp_llvalue instr]
;
let continue insts_term_to_code =
[%Trace.retn
@ -1436,7 +1436,7 @@ let skip_phis : Llvm.llbasicblock -> _ Llvm.llpos =
let xlate_block : pop_thunk -> x -> Llvm.llbasicblock -> Llair.block list =
fun pop x blk ->
[%Trace.call fun {pf} -> pf "%a" pp_llblock blk]
[%Trace.call fun {pf} -> pf "@ %a" pp_llblock blk]
;
let lbl = label_of_block blk in
let pos = skip_phis blk in
@ -1469,7 +1469,7 @@ let xlate_function_decl x llfunc typ k =
let xlate_function : x -> Llvm.llvalue -> Llair.func =
fun x llf ->
[%Trace.call fun {pf} -> pf "%a" pp_llvalue llf]
[%Trace.call fun {pf} -> pf "@ %a" pp_llvalue llf]
;
undef_count := 0 ;
let typ = xlate_type x (Llvm.type_of llf) in
@ -1541,7 +1541,7 @@ let transform ~internalize : Llvm.llmodule -> unit =
Llvm.PassManager.dispose pm
let read_and_parse llcontext bc_file =
[%Trace.call fun {pf} -> pf "%s" bc_file]
[%Trace.call fun {pf} -> pf "@ %s" bc_file]
;
let llmemorybuffer =
try Llvm.MemoryBuffer.of_file bc_file
@ -1606,7 +1606,7 @@ let cleanup llmodule llcontext =
let translate ~models ~fuzzer ~internalize : string list -> Llair.program =
fun inputs ->
[%Trace.call fun {pf} ->
pf "%a" (List.pp "@ " Format.pp_print_string) inputs]
pf "@ %a" (List.pp "@ " Format.pp_print_string) inputs]
;
Llvm.install_fatal_error_handler invalid_llvm ;
let llcontext = Llvm.global_context () in

@ -133,7 +133,7 @@ let x_context {asserts; var_env} =
let check_unsat (_, asserts, ctx) =
[%Trace.call fun {pf} ->
pf "%a@ %a@ %a" Formula.pp asserts Context.pp ctx Context.pp_raw ctx]
pf "@ %a@ %a@ %a" Formula.pp asserts Context.pp ctx Context.pp_raw ctx]
;
( Context.is_unsat ctx
|| Formula.equal Formula.ff

@ -28,7 +28,7 @@
{[
let func arg =
[%trace]
~call:(fun {pf} -> pf "%a" pp_arg_type arg)
~call:(fun {pf} -> pf "@ %a" pp_arg_type arg)
~retn:(fun {pf} -> pf "%a" pp_result_type)
@@ fun () -> func arg
]}
@ -37,7 +37,7 @@
{[
let func arg =
[%Trace.call fun {pf} -> pf "%a" pp_arg_type arg]
[%Trace.call fun {pf} -> pf "@ %a" pp_arg_type arg]
;
func arg
|>

@ -176,7 +176,7 @@ let infok mod_name fun_name k =
let incf mod_name fun_name fmt =
if not (enabled mod_name fun_name) then Format.ifprintf fs fmt
else (
Format.fprintf fs "@\n@[<2>@[<hv 2>( %s:@ " fun_name ;
Format.fprintf fs "@\n@[<2>@[<hv 2>( %s:" fun_name ;
Format.kfprintf (fun fs -> Format.fprintf fs "@]") fs fmt )
let decf mod_name fun_name fmt =

@ -99,7 +99,7 @@ module Make (Opts : Domain_intf.Opts) (Dom : Domain_intf.Dom) = struct
|> check invariant
let push_call (Llair.{return; throw} as call) from_call stk =
[%Trace.call fun {pf} -> pf "%a" pp stk]
[%Trace.call fun {pf} -> pf "@ %a" pp stk]
;
let rec count_f_in_stack acc f = function
| Return {stk= next_frame; dst= dest_block} ->
@ -313,7 +313,7 @@ module Make (Opts : Domain_intf.Opts) (Dom : Domain_intf.Dom) = struct
let Llair.{callee; actuals; areturn; return; recursive} = call in
let Llair.{name; formals; freturn; locals; entry} = callee in
[%Trace.call fun {pf} ->
pf "%a from %a with state@ %a" Llair.Function.pp name
pf "@ %a from %a with state@ %a" Llair.Function.pp name
Llair.Function.pp return.dst.parent.name Dom.pp state]
;
let dnf_states =
@ -380,7 +380,7 @@ module Make (Opts : Domain_intf.Opts) (Dom : Domain_intf.Dom) = struct
let exec_return stk pre_state (block : Llair.block) exp =
let Llair.{name; formals; freturn; locals} = block.parent in
[%Trace.call fun {pf} -> pf "from: %a" Llair.Function.pp name]
[%Trace.call fun {pf} -> pf "@ from: %a" Llair.Function.pp name]
;
let summarize post_state =
if not Opts.function_summaries then post_state
@ -419,7 +419,7 @@ module Make (Opts : Domain_intf.Opts) (Dom : Domain_intf.Dom) = struct
let exec_throw stk pre_state (block : Llair.block) exc =
let func = block.parent in
[%Trace.call fun {pf} -> pf "from %a" Llair.Function.pp func.name]
[%Trace.call fun {pf} -> pf "@ from %a" Llair.Function.pp func.name]
;
let unwind formals scope from_call state =
Dom.retn formals (Some func.fthrow) from_call
@ -506,7 +506,7 @@ module Make (Opts : Domain_intf.Opts) (Dom : Domain_intf.Dom) = struct
fun pgm stk state block ->
[%trace]
~call:(fun {pf} ->
pf "#%i %%%s in %a" block.sort_index block.lbl Llair.Function.pp
pf "@ #%i %%%s in %a" block.sort_index block.lbl Llair.Function.pp
block.parent.name )
~retn:(fun {pf} _ ->
pf "#%i %%%s in %a" block.sort_index block.lbl Llair.Function.pp

@ -64,8 +64,8 @@ module Make (State_domain : State_domain_sig) = struct
(entry, current) =
[%Trace.call fun {pf} ->
pf
"@[<v>@[actuals: (@[%a@])@ formals: (@[%a@])@]@ locals: {@[%a@]}@ \
globals: {@[%a@]}@ current: %a@]"
"@ @[<v>@[actuals: (@[%a@])@ formals: (@[%a@])@]@ locals: \
{@[%a@]}@ globals: {@[%a@]}@ current: %a@]"
(IArray.pp ",@ " Llair.Exp.pp)
actuals
(IArray.pp ",@ " Llair.Reg.pp)
@ -82,18 +82,18 @@ module Make (State_domain : State_domain_sig) = struct
[%Trace.retn fun {pf} (reln, _) -> pf "@,%a" pp reln]
let post locals {state_from_call; caller_entry} (_, current) =
[%Trace.call fun {pf} -> pf "locals: %a" Llair.Reg.Set.pp locals]
[%Trace.call fun {pf} -> pf "@ locals: %a" Llair.Reg.Set.pp locals]
;
(caller_entry, State_domain.post locals state_from_call current)
|>
[%Trace.retn fun {pf} -> pf "@,%a" pp]
[%Trace.retn fun {pf} -> pf "%a" pp]
let retn formals freturn {caller_entry; state_from_call} (_, current) =
[%Trace.call fun {pf} -> pf "@,%a" State_domain.pp current]
[%Trace.call fun {pf} -> pf "@ %a" State_domain.pp current]
;
(caller_entry, State_domain.retn formals freturn state_from_call current)
|>
[%Trace.retn fun {pf} -> pf "@,%a" pp]
[%Trace.retn fun {pf} -> pf "%a" pp]
let dnf (entry, current) =
List.map ~f:(fun c -> (entry, c)) (State_domain.dnf current)

@ -35,7 +35,7 @@ let init globals =
| _ -> q )
let join p q =
[%Trace.call fun {pf} -> pf "%a@ %a" pp p pp q]
[%Trace.call fun {pf} -> pf "@ %a@ %a" pp p pp q]
;
Some (Sh.or_ p q) |> Option.map ~f:simplify
|>
@ -80,7 +80,7 @@ let value_determined_by ctx us a =
Term.Set.subset (Term.Set.of_iter (Term.atoms b)) ~of_:us )
let garbage_collect (q : Sh.t) ~wrt =
[%Trace.call fun {pf} -> pf "%a" pp q]
[%Trace.call fun {pf} -> pf "@ %a" pp q]
;
(* only support DNF for now *)
assert (List.is_empty q.djns) ;
@ -142,7 +142,7 @@ type from_call = {areturn: Var.t option; unshadow: Var.Subst.t; frame: Sh.t}
let call ~summaries ~globals ~actuals ~areturn ~formals ~freturn ~locals q =
[%Trace.call fun {pf} ->
pf
"@[<hv>actuals: (@[%a@])@ formals: (@[%a@])@ locals: {@[%a@]}@ \
"@ @[<hv>actuals: (@[%a@])@ formals: (@[%a@])@ locals: {@[%a@]}@ \
globals: {@[%a@]}@ q: %a@]"
(IArray.pp ",@ " Llair.Exp.pp)
actuals
@ -184,7 +184,7 @@ let call ~summaries ~globals ~actuals ~areturn ~formals ~freturn ~locals q =
(** Leave scope of locals: existentially quantify locals. *)
let post locals _ q =
[%Trace.call fun {pf} ->
pf "@[<hv>locals: {@[%a@]}@ q: %a@]" Llair.Reg.Set.pp locals Sh.pp q]
pf "@ @[<hv>locals: {@[%a@]}@ q: %a@]" Llair.Reg.Set.pp locals Sh.pp q]
;
Sh.exists (X.regs locals) q |> simplify
|>
@ -195,7 +195,7 @@ let post locals _ q =
restore the shadowed variables. *)
let retn formals freturn {areturn; unshadow; frame} q =
[%Trace.call fun {pf} ->
pf "@[<v>formals: {@[%a@]}%a%a@ unshadow: %a@ q: %a@ frame: %a@]"
pf "@ @[<v>formals: {@[%a@]}%a%a@ unshadow: %a@ q: %a@ frame: %a@]"
(IArray.pp ", " Llair.Reg.pp)
formals
(Option.pp "@ freturn: %a" Llair.Reg.pp)
@ -250,7 +250,7 @@ let pp_summary fs {xs; foot; post} =
let create_summary ~locals ~formals ~entry ~current:(post : Sh.t) =
[%Trace.call fun {pf} ->
pf "formals %a@ entry: %a@ current: %a"
pf "@ formals %a@ entry: %a@ current: %a"
(IArray.pp ",@ " Llair.Reg.pp)
formals pp entry pp post]
;
@ -282,7 +282,7 @@ let create_summary ~locals ~formals ~entry ~current:(post : Sh.t) =
[%Trace.retn fun {pf} (fs, _) -> pf "@,%a" pp_summary fs]
let apply_summary q ({xs; foot; post} as fs) =
[%Trace.call fun {pf} -> pf "fs: %a@ q: %a" pp_summary fs pp q]
[%Trace.call fun {pf} -> pf "@ fs: %a@ q: %a" pp_summary fs pp q]
;
let xs_in_q = Var.Set.inter xs q.Sh.us in
let xs_in_fv_q = Var.Set.inter xs (Sh.fv q) in

@ -37,7 +37,7 @@ let exec_move reg_exps st =
IArray.fold ~f:(fun (_, rhs) -> used_globals rhs) reg_exps st
let exec_inst inst st =
[%Trace.call fun {pf} -> pf "pre:{%a} %a" pp st Llair.Inst.pp inst]
[%Trace.call fun {pf} -> pf "@ pre:{%a} %a" pp st Llair.Inst.pp inst]
;
Some (Llair.Inst.fold_exps ~f:used_globals inst st)
|>
@ -65,7 +65,7 @@ let apply_summary st summ = Some (Llair.Global.Set.union st summ)
let by_function : Domain_intf.used_globals -> Llair.Function.t -> t =
fun s fn ->
[%Trace.call fun {pf} -> pf "%a" Llair.Function.pp fn]
[%Trace.call fun {pf} -> pf "@ %a" Llair.Function.pp fn]
;
( match s with
| Declared set -> set

@ -648,8 +648,8 @@ let check_preserve_us (q0 : Sh.t) (q1 : Sh.t) =
explicitly-quantified pre *)
let exec_spec_ (xs, pre) (gs, {foot; sub; ms; post}) =
([%Trace.call fun {pf} ->
pf "@[%a@]@ @[<2>%a@,@[<hv>{%a %a}@;<1 -1>%a--@ {%a }@]@]" Sh.pp pre
Sh.pp_us gs Sh.pp foot
pf "@ @[%a@]@ @[<2>%a@,@[<hv>{%a %a}@;<1 -1>%a--@ {%a }@]@]" Sh.pp
pre Sh.pp_us gs Sh.pp foot
(fun fs sub ->
if not (Var.Subst.is_empty sub) then
Format.fprintf fs "∧ %a" Var.Subst.pp sub )
@ -720,7 +720,7 @@ let exec_specs pre specs =
let assume pre cnd =
[%trace]
~call:(fun {pf} -> pf "%a" Formula.pp cnd)
~call:(fun {pf} -> pf "@ %a" Formula.pp cnd)
~retn:(fun {pf} -> pf "%a" Sh.pp)
@@ fun () -> Sh.and_ cnd pre

@ -285,7 +285,7 @@ struct
let map poly ~f =
[%trace]
~call:(fun {pf} -> pf "%a" pp poly)
~call:(fun {pf} -> pf "@ %a" pp poly)
~retn:(fun {pf} -> pf "%a" pp)
@@ fun () ->
( if is_noninterpreted poly then poly
@ -321,7 +321,7 @@ struct
let solve_for_mono rejected_poly coeff mono poly =
[%trace]
~call:(fun {pf} ->
pf "0 = %a + (%a×%a) + %a" pp rejected_poly Q.pp coeff Mono.pp
pf "@ 0 = %a + (%a×%a) + %a" pp rejected_poly Q.pp coeff Mono.pp
mono pp poly )
~retn:(fun {pf} s ->
pf "%a"
@ -339,7 +339,7 @@ struct
that [r + p = m - q] *)
let rec solve_poly rejected poly =
[%trace]
~call:(fun {pf} -> pf "0 = (%a) + (%a)" pp rejected pp poly)
~call:(fun {pf} -> pf "@ 0 = (%a) + (%a)" pp rejected pp poly)
~retn:(fun {pf} s ->
pf "%a"
(Option.pp "%a" (fun fs (v, q) ->
@ -355,7 +355,7 @@ struct
let solve_zero_eq ?for_ e =
[%trace]
~call:(fun {pf} ->
pf "0 = %a%a" Trm.pp e (Option.pp " for %a" Trm.pp) for_ )
pf "@ 0 = %a%a" Trm.pp e (Option.pp " for %a" Trm.pp) for_ )
~retn:(fun {pf} s ->
pf "%a"
(Option.pp "%a" (fun fs (c, r) ->

@ -101,14 +101,14 @@ end = struct
(** apply a substitution to maximal non-interpreted subterms *)
let rec norm s a =
[%trace]
~call:(fun {pf} -> pf "%a" Trm.pp a)
~call:(fun {pf} -> pf "@ %a" Trm.pp a)
~retn:(fun {pf} -> pf "%a" Trm.pp)
@@ fun () ->
if is_interpreted a then Trm.map ~f:(norm s) a else apply s a
(** compose two substitutions *)
let compose r s =
[%Trace.call fun {pf} -> pf "%a@ %a" pp r pp s]
[%Trace.call fun {pf} -> pf "@ %a@ %a" pp r pp s]
;
( if is_empty s then r
else
@ -178,7 +178,7 @@ end = struct
ks fv(τ) = . *)
let partition_valid xs s =
[%trace]
~call:(fun {pf} -> pf "%a@ %a" Var.Set.pp_xs xs pp s)
~call:(fun {pf} -> pf "@ %a@ %a" Var.Set.pp_xs xs pp s)
~retn:(fun {pf} (t, ks, u) ->
pf "%a@ %a@ %a" pp t Var.Set.pp_xs ks pp u )
@@ fun () ->
@ -252,7 +252,7 @@ let fresh name (wrt, xs, s) =
let solve_poly ?f p q s =
[%trace]
~call:(fun {pf} -> pf "%a = %a" Trm.pp p Trm.pp q)
~call:(fun {pf} -> pf "@ %a = %a" Trm.pp p Trm.pp q)
~retn:(fun {pf} -> function
| Some (_, xs, s) -> pf "%a%a" Var.Set.pp_xs xs Subst.pp s
| None -> pf "false" )
@ -271,7 +271,7 @@ let solve_poly ?f p q s =
let rec solve_extract ?f a o l b s =
[%trace]
~call:(fun {pf} ->
pf "%a = %a@ %a%a" Trm.pp
pf "@ %a = %a@ %a%a" Trm.pp
(Trm.extract ~seq:a ~off:o ~len:l)
Trm.pp b Var.Set.pp_xs (snd3 s) Subst.pp (trd3 s) )
~retn:(fun {pf} -> function
@ -297,7 +297,7 @@ let rec solve_extract ?f a o l b s =
and solve_concat ?f a0V b m s =
[%trace]
~call:(fun {pf} ->
pf "%a = %a@ %a%a" Trm.pp (Trm.concat a0V) Trm.pp b Var.Set.pp_xs
pf "@ %a = %a@ %a%a" Trm.pp (Trm.concat a0V) Trm.pp b Var.Set.pp_xs
(snd3 s) Subst.pp (trd3 s) )
~retn:(fun {pf} -> function
| Some (_, xs, s) -> pf "%a%a" Var.Set.pp_xs xs Subst.pp s
@ -314,8 +314,8 @@ and solve_concat ?f a0V b m s =
and solve_ ?f d e s =
[%Trace.call fun {pf} ->
pf "%a@[%a@ %a@ %a@]" Var.Set.pp_xs (snd3 s) Trm.pp d Trm.pp e Subst.pp
(trd3 s)]
pf "@ %a@[%a@ %a@ %a@]" Var.Set.pp_xs (snd3 s) Trm.pp d Trm.pp e
Subst.pp (trd3 s)]
;
( match orient (norm s d) (norm s e) with
(* e' = f' ==> true when e' ≡ f' *)
@ -402,7 +402,7 @@ and solve_ ?f d e s =
| None -> pf "false"]
let solve ?f ~wrt ~xs d e =
[%Trace.call fun {pf} -> pf "%a@ %a" Trm.pp d Trm.pp e]
[%Trace.call fun {pf} -> pf "@ %a@ %a" Trm.pp d Trm.pp e]
;
( solve_ ?f d e (wrt, xs, Subst.empty)
|>= fun (_, xs, s) ->
@ -565,7 +565,7 @@ let unsat = {empty with sat= false}
(** [lookup r a] is [b'] if [a ~ b = b'] for some equation [b = b'] in rep *)
let lookup r a =
([%Trace.call fun {pf} -> pf "%a" Trm.pp a]
([%Trace.call fun {pf} -> pf "@ %a" Trm.pp a]
;
Iter.find_map (Subst.to_iter r.rep) ~f:(fun (b, b') ->
Option.return_if (semi_congruent r a b) b' )
@ -576,7 +576,7 @@ let lookup r a =
(** rewrite a term into canonical form using rep and, for non-interpreted
terms, congruence composed with rep *)
let rec canon r a =
[%Trace.call fun {pf} -> pf "%a" Trm.pp a]
[%Trace.call fun {pf} -> pf "@ %a" Trm.pp a]
;
( match classify a with
| Atomic -> Subst.apply r.rep a
@ -592,7 +592,7 @@ let rec canon r a =
let canon_f r b =
[%trace]
~call:(fun {pf} -> pf "%a@ %a" Fml.pp b pp_raw r)
~call:(fun {pf} -> pf "@ %a@ %a" Fml.pp b pp_raw r)
~retn:(fun {pf} -> pf "%a" Fml.pp)
@@ fun () -> Fml.map_trms ~f:(canon r) b
@ -614,7 +614,7 @@ let extend a r =
if rep == r.rep then r else {r with rep} |> check pre_invariant
let merge ~wrt a b r =
[%Trace.call fun {pf} -> pf "%a@ %a@ %a" Trm.pp a Trm.pp b pp r]
[%Trace.call fun {pf} -> pf "@ %a@ %a@ %a" Trm.pp a Trm.pp b pp r]
;
( match solve ~wrt ~xs:r.xs a b with
| Some (xs, s) ->
@ -649,7 +649,7 @@ let rec close ~wrt r =
| None -> r
let close ~wrt r =
[%Trace.call fun {pf} -> pf "%a" pp r]
[%Trace.call fun {pf} -> pf "@ %a" pp r]
;
close ~wrt r
|>
@ -683,7 +683,7 @@ let is_empty {sat; rep} =
let is_unsat {sat} = not sat
let implies r b =
[%Trace.call fun {pf} -> pf "%a@ %a" Fml.pp b pp r]
[%Trace.call fun {pf} -> pf "@ %a@ %a" Fml.pp b pp r]
;
Fml.equal Fml.tt (canon_f r b)
|>
@ -727,7 +727,7 @@ let iter_uses_of t r ~f = fold_uses_of r t () ~f:(fun use () -> f use)
let uses_of t r = Iter.from_labelled_iter (iter_uses_of t r)
let apply_subst wrt s r =
[%Trace.call fun {pf} -> pf "%a@ %a" Subst.pp s pp r]
[%Trace.call fun {pf} -> pf "@ %a@ %a" Subst.pp s pp r]
;
( if Subst.is_empty s then r
else
@ -744,7 +744,7 @@ let apply_subst wrt s r =
invariant r']
let union wrt r s =
[%Trace.call fun {pf} -> pf "@[<hv 1> %a@ @<2>∧ %a@]" pp r pp s]
[%Trace.call fun {pf} -> pf "@ @[<hv 1> %a@ @<2>∧ %a@]" pp r pp s]
;
( if not r.sat then r
else if not s.sat then s
@ -760,7 +760,7 @@ let union wrt r s =
invariant r']
let inter wrt r s =
[%Trace.call fun {pf} -> pf "@[<hv 1> %a@ @<2> %a@]" pp r pp s]
[%Trace.call fun {pf} -> pf "@ @[<hv 1> %a@ @<2> %a@]" pp r pp s]
;
( if not s.sat then r
else if not r.sat then s
@ -802,7 +802,7 @@ let rec add_ wrt b r =
| Pos _ | Not _ | Or _ | Iff _ | Cond _ | Lit _ -> r
let add us b r =
[%Trace.call fun {pf} -> pf "%a@ %a" Fml.pp b pp r]
[%Trace.call fun {pf} -> pf "@ %a@ %a" Fml.pp b pp r]
;
add_ us b r |> extract_xs
|>
@ -821,7 +821,7 @@ let dnf f =
Fml.fold_dnf ~meet1 ~join1 ~top ~bot f
let rename r sub =
[%Trace.call fun {pf} -> pf "@[%a@]@ %a" Var.Subst.pp sub pp r]
[%Trace.call fun {pf} -> pf "@ @[%a@]@ %a" Var.Subst.pp sub pp r]
;
let rep =
Subst.map_entries ~f:(Trm.map_vars ~f:(Var.Subst.apply sub)) r.rep
@ -861,7 +861,7 @@ type 'a zom = Zero | One of 'a | Many
[fv kill us]; solve [p = q] for [kill]; extend subst mapping [kill]
to the solution *)
let solve_poly_eq us p' q' subst =
[%Trace.call fun {pf} -> pf "%a = %a" Trm.pp p' Trm.pp q']
[%Trace.call fun {pf} -> pf "@ %a = %a" Trm.pp p' Trm.pp q']
;
let diff = Trm.sub p' q' in
let max_solvables_not_ito_us =
@ -881,7 +881,7 @@ let solve_poly_eq us p' q' subst =
pf "@[%a@]" Subst.pp_diff (subst, Option.value subst' ~default:subst)]
let solve_seq_eq ~wrt us e' f' subst =
[%Trace.call fun {pf} -> pf "%a = %a" Trm.pp e' Trm.pp f']
[%Trace.call fun {pf} -> pf "@ %a = %a" Trm.pp e' Trm.pp f']
;
let f x u =
(not (Var.Set.subset (Trm.fv x) ~of_:us))
@ -911,7 +911,7 @@ let solve_seq_eq ~wrt us e' f' subst =
let solve_interp_eq ~wrt us e' (cls, subst) =
[%Trace.call fun {pf} ->
pf "trm: @[%a@]@ cls: @[%a@]@ subst: @[%a@]" Trm.pp e' pp_cls cls
pf "@ trm: @[%a@]@ cls: @[%a@]@ subst: @[%a@]" Trm.pp e' pp_cls cls
Subst.pp subst]
;
List.find_map cls ~f:(fun f ->
@ -930,7 +930,7 @@ let solve_interp_eq ~wrt us e' (cls, subst) =
[fv u us xs] *)
let rec solve_interp_eqs ~wrt us (cls, subst) =
[%Trace.call fun {pf} ->
pf "cls: @[%a@]@ subst: @[%a@]" pp_cls cls Subst.pp subst]
pf "@ cls: @[%a@]@ subst: @[%a@]" pp_cls cls Subst.pp subst]
;
let rec solve_interp_eqs_ cls' (cls, subst) =
match cls with
@ -969,7 +969,7 @@ let dom_trm e =
[fv u us xs] *)
let solve_uninterp_eqs us (cls, subst) =
[%Trace.call fun {pf} ->
pf "cls: @[%a@]@ subst: @[%a@]" pp_cls cls Subst.pp subst]
pf "@ cls: @[%a@]@ subst: @[%a@]" pp_cls cls Subst.pp subst]
;
let compare e f =
[%compare: kind * Trm.t] (classify e, e) (classify f, f)
@ -1036,7 +1036,7 @@ let solve_uninterp_eqs us (cls, subst) =
let solve_class ~wrt us us_xs ~key:rep ~data:cls (classes, subst) =
let classes0 = classes in
[%Trace.call fun {pf} ->
pf "rep: @[%a@]@ cls: @[%a@]@ subst: @[%a@]" Trm.pp rep pp_cls cls
pf "@ rep: @[%a@]@ cls: @[%a@]@ subst: @[%a@]" Trm.pp rep pp_cls cls
Subst.pp subst]
;
let cls, cls_not_ito_us_xs =
@ -1059,7 +1059,7 @@ let solve_class ~wrt us us_xs ~key:rep ~data:cls (classes, subst) =
pp_diff_clss (classes0, classes')]
let solve_concat_extracts_eq r x =
[%Trace.call fun {pf} -> pf "%a@ %a" Trm.pp x pp r]
[%Trace.call fun {pf} -> pf "@ %a@ %a" Trm.pp x pp r]
;
let uses =
fold_uses_of r x [] ~f:(fun use uses ->
@ -1122,7 +1122,7 @@ let solve_for_xs r us xs =
and [fv u us] or else [fv u us xs]. *)
let solve_classes ~wrt r xs (classes, subst, us) =
[%Trace.call fun {pf} ->
pf "us: {@[%a@]}@ xs: {@[%a@]}" Var.Set.pp us Var.Set.pp xs]
pf "@ us: {@[%a@]}@ xs: {@[%a@]}" Var.Set.pp us Var.Set.pp xs]
;
let rec solve_classes_ (classes0, subst0, us_xs) =
let classes, subst =
@ -1151,7 +1151,7 @@ let pp_vss fs vss =
[fv u v] *)
let solve_for_vars vss r =
[%Trace.call fun {pf} ->
pf "%a@ @[%a@]" pp_vss vss pp r ;
pf "@ %a@ @[%a@]" pp_vss vss pp r ;
invariant r]
;
let wrt = Var.Set.union_list vss in
@ -1185,7 +1185,7 @@ let solve_for_vars vss r =
let trivial vs r =
[%trace]
~call:(fun {pf} -> pf "%a@ %a" Var.Set.pp_xs vs pp_raw r)
~call:(fun {pf} -> pf "@ %a@ %a" Var.Set.pp_xs vs pp_raw r)
~retn:(fun {pf} ks -> pf "%a" Var.Set.pp_xs ks)
@@ fun () ->
Var.Set.fold vs Var.Set.empty ~f:(fun v ks ->
@ -1198,7 +1198,7 @@ let trivial vs r =
let trim ks r =
[%trace]
~call:(fun {pf} -> pf "%a@ %a" Var.Set.pp_xs ks pp_raw r)
~call:(fun {pf} -> pf "@ %a@ %a" Var.Set.pp_xs ks pp_raw r)
~retn:(fun {pf} r' ->
pf "%a" pp_raw r' ;
assert (Var.Set.disjoint ks (fv r')) )
@ -1243,7 +1243,7 @@ let trim ks r =
let apply_and_elim ~wrt xs s r =
[%trace]
~call:(fun {pf} -> pf "%a%a@ %a" Var.Set.pp_xs xs Subst.pp s pp_raw r)
~call:(fun {pf} -> pf "@ %a%a@ %a" Var.Set.pp_xs xs Subst.pp s pp_raw r)
~retn:(fun {pf} (zs, r', ks) ->
pf "%a@ %a@ %a" Var.Set.pp_xs zs pp_raw r' Var.Set.pp_xs ks ;
assert (Var.Set.subset ks ~of_:xs) ;

@ -261,7 +261,7 @@ end = struct
let rec _Extract ~seq ~off ~len =
[%trace]
~call:(fun {pf} -> pf "%a" pp (Extract {seq; off; len}))
~call:(fun {pf} -> pf "@ %a" pp (Extract {seq; off; len}))
~retn:(fun {pf} -> pf "%a" pp)
@@ fun () ->
(* _[_,0) ==> ⟨⟩ *)
@ -326,7 +326,7 @@ end = struct
and _Concat xs =
[%trace]
~call:(fun {pf} -> pf "%a" pp (Concat xs))
~call:(fun {pf} -> pf "@ %a" pp (Concat xs))
~retn:(fun {pf} -> pf "%a" pp)
@@ fun () ->
(* (α^(β^γ)) ==> (α^β^γ) *)

@ -319,7 +319,7 @@ let is_false q = match q.djns with [[]] -> true | _ -> false
let exists_fresh xs q =
[%Trace.call fun {pf} ->
pf "{@[%a@]}@ %a" Var.Set.pp xs pp q ;
pf "@ {@[%a@]}@ %a" Var.Set.pp xs pp q ;
assert (
Var.Set.disjoint xs q.us
|| fail "Sh.exists_fresh xs ∩ q.us: %a" Var.Set.pp
@ -331,7 +331,7 @@ let exists_fresh xs q =
[%Trace.retn fun {pf} -> pf "%a" pp]
let exists xs q =
[%Trace.call fun {pf} -> pf "{@[%a@]}@ %a" Var.Set.pp xs pp q]
[%Trace.call fun {pf} -> pf "@ {@[%a@]}@ %a" Var.Set.pp xs pp q]
;
assert (
Var.Set.subset xs ~of_:q.us
@ -381,7 +381,7 @@ let rec apply_subst sub q =
and rename_ Var.Subst.{sub; dom; rng} q =
[%Trace.call fun {pf} ->
pf "@[%a@]@ %a" Var.Subst.pp sub pp q ;
pf "@ @[%a@]@ %a" Var.Subst.pp sub pp q ;
assert (Var.Set.subset dom ~of_:q.us)]
;
let q = extend_us rng q in
@ -394,7 +394,7 @@ and rename_ Var.Subst.{sub; dom; rng} q =
assert (Var.Set.disjoint q'.us (Var.Subst.domain sub))]
and rename sub q =
[%Trace.call fun {pf} -> pf "@[%a@]@ %a" Var.Subst.pp sub pp q]
[%Trace.call fun {pf} -> pf "@ @[%a@]@ %a" Var.Subst.pp sub pp q]
;
rename_ (Var.Subst.restrict_dom sub q.us) q
|>
@ -406,7 +406,7 @@ and rename sub q =
(** freshen existentials, preserving vocabulary *)
and freshen_xs q ~wrt =
[%Trace.call fun {pf} ->
pf "{@[%a@]}@ %a" Var.Set.pp wrt pp q ;
pf "@ {@[%a@]}@ %a" Var.Set.pp wrt pp q ;
assert (Var.Set.subset q.us ~of_:wrt)]
;
let Var.Subst.{sub; dom; rng}, _ = Var.Subst.freshen q.xs ~wrt in
@ -429,7 +429,7 @@ and extend_us us q =
|> check invariant
let freshen q ~wrt =
[%Trace.call fun {pf} -> pf "{@[%a@]}@ %a" Var.Set.pp wrt pp q]
[%Trace.call fun {pf} -> pf "@ {@[%a@]}@ %a" Var.Set.pp wrt pp q]
;
let xsub, _ = Var.Subst.freshen q.us ~wrt:(Var.Set.union wrt q.xs) in
let q' = extend_us wrt (rename_ xsub q) in
@ -442,7 +442,7 @@ let freshen q ~wrt =
assert (Var.Set.disjoint wrt (fv q'))]
let bind_exists q ~wrt =
[%Trace.call fun {pf} -> pf "{@[%a@]}@ %a" Var.Set.pp wrt pp q]
[%Trace.call fun {pf} -> pf "@ {@[%a@]}@ %a" Var.Set.pp wrt pp q]
;
let q' =
if Var.Set.is_empty wrt then q
@ -461,7 +461,7 @@ let and_ctx_ ctx q =
if Context.is_unsat ctx then false_ q.us else exists_fresh xs {q with ctx}
let and_ctx ctx q =
[%Trace.call fun {pf} -> pf "%a@ %a" Context.pp ctx pp q]
[%Trace.call fun {pf} -> pf "@ %a@ %a" Context.pp ctx pp q]
;
(if is_false q then q else and_ctx_ ctx (extend_us (Context.fv ctx) q))
|>
@ -471,7 +471,7 @@ let and_ctx ctx q =
let star q1 q2 =
[%trace]
~call:(fun {pf} -> pf "(%a)@ (%a)" pp q1 pp q2)
~call:(fun {pf} -> pf "@ (%a)@ (%a)" pp q1 pp q2)
~retn:(fun {pf} q ->
pf "%a" pp q ;
invariant q ;
@ -509,7 +509,7 @@ let starN = function
| q :: qs -> List.fold ~f:star qs q
let or_ q1 q2 =
[%Trace.call fun {pf} -> pf "(%a)@ (%a)" pp_raw q1 pp_raw q2]
[%Trace.call fun {pf} -> pf "@ (%a)@ (%a)" pp_raw q1 pp_raw q2]
;
( match (q1, q2) with
| _ when is_false q1 -> extend_us q1.us q2
@ -541,7 +541,7 @@ let orN = function
| q :: qs -> List.fold ~f:or_ qs q
let pure (p : Formula.t) =
[%Trace.call fun {pf} -> pf "%a" Formula.pp p]
[%Trace.call fun {pf} -> pf "@ %a" Formula.pp p]
;
Iter.fold (Context.dnf p) (false_ Var.Set.empty)
~f:(fun (xs, pure, ctx) q ->
@ -558,7 +558,7 @@ let and_ b q =
star (pure (Formula.map_terms ~f:(Context.normalize q.ctx) b)) q
let and_subst subst q =
[%Trace.call fun {pf} -> pf "%a@ %a" Context.Subst.pp subst pp q]
[%Trace.call fun {pf} -> pf "@ %a@ %a" Context.Subst.pp subst pp q]
;
Context.Subst.fold_eqs ~f:and_ subst q
|>
@ -567,7 +567,7 @@ let and_subst subst q =
invariant q]
let subst sub q =
[%Trace.call fun {pf} -> pf "@[%a@]@ %a" Var.Subst.pp sub pp q]
[%Trace.call fun {pf} -> pf "@ @[%a@]@ %a" Var.Subst.pp sub pp q]
;
let dom, eqs =
Var.Subst.fold sub (Var.Set.empty, Formula.tt)
@ -618,7 +618,7 @@ let fold_dnf ~conj ~disj sjn (xs, conjuncts) disjuncts =
add_disjunct Iter.empty sjn (xs, conjuncts) disjuncts
let dnf q =
[%Trace.call fun {pf} -> pf "%a" pp q]
[%Trace.call fun {pf} -> pf "@ %a" pp q]
;
let conj sjn conjuncts = sjn :: conjuncts in
let disj (xs, conjuncts) disjuncts =
@ -639,7 +639,7 @@ let rec pure_approx q =
Formula.orN (List.map djn ~f:pure_approx) :: p ) )
let pure_approx q =
[%Trace.call fun {pf} -> pf "%a" pp q]
[%Trace.call fun {pf} -> pf "@ %a" pp q]
;
pure_approx q
|>
@ -677,7 +677,7 @@ let is_unsat q =
(** Simplify *)
let rec norm_ s q =
[%Trace.call fun {pf} -> pf "@[%a@]@ %a" Context.Subst.pp s pp_raw q]
[%Trace.call fun {pf} -> pf "@ @[%a@]@ %a" Context.Subst.pp s pp_raw q]
;
map q ~f_sjn:(norm_ s)
~f_ctx:(Context.apply_subst (Var.Set.union q.us q.xs) s)
@ -689,7 +689,7 @@ let rec norm_ s q =
invariant q']
let norm s q =
[%Trace.call fun {pf} -> pf "@[%a@]@ %a" Context.Subst.pp s pp_raw q]
[%Trace.call fun {pf} -> pf "@ @[%a@]@ %a" Context.Subst.pp s pp_raw q]
;
(if Context.Subst.is_empty s then q else norm_ s q)
|>
@ -700,7 +700,7 @@ let norm s q =
(** rename existentially quantified variables to avoid shadowing, and reduce
quantifier scopes by sinking them as low as possible into disjunctions *)
let rec freshen_nested_xs us q =
[%Trace.call fun {pf} -> pf "%a" pp q]
[%Trace.call fun {pf} -> pf "@ %a" pp q]
;
(* trim xs to those that appear in the stem and sink the rest *)
let fv_stem = fv {q with xs= Var.Set.empty; djns= []} in
@ -727,7 +727,7 @@ let rec freshen_nested_xs us q =
invariant q']
let rec propagate_context_ ancestor_vs ancestor_ctx q =
[%Trace.call fun {pf} -> pf "(%a)@ %a" Context.pp ancestor_ctx pp q]
[%Trace.call fun {pf} -> pf "@ (%a)@ %a" Context.pp ancestor_ctx pp q]
;
(* extend vocabulary with variables in scope above *)
let ancestor_vs = Var.Set.union ancestor_vs (Var.Set.union q.us q.xs) in
@ -763,7 +763,7 @@ let rec propagate_context_ ancestor_vs ancestor_ctx q =
invariant q']
let propagate_context ancestor_vs ancestor_ctx q =
[%Trace.call fun {pf} -> pf "(%a)@ %a" Context.pp ancestor_ctx pp q]
[%Trace.call fun {pf} -> pf "@ (%a)@ %a" Context.pp ancestor_ctx pp q]
;
propagate_context_ ancestor_vs ancestor_ctx q
|>
@ -778,7 +778,7 @@ let pp_vss fs vss =
let remove_absent_xs ks q =
[%trace]
~call:(fun {pf} -> pf "%a%a" Var.Set.pp_xs ks pp q)
~call:(fun {pf} -> pf "@ %a%a" Var.Set.pp_xs ks pp q)
~retn:(fun {pf} -> pf "%a" pp)
@@ fun () ->
let ks = Var.Set.inter ks q.xs in
@ -800,7 +800,7 @@ let remove_absent_xs ks q =
let rec simplify_ us rev_xss survived ancestor_subst q =
[%Trace.call fun {pf} ->
pf "%a@ %a@ %a" pp_vss (List.rev rev_xss) Context.Subst.pp
pf "@ %a@ %a@ %a" pp_vss (List.rev rev_xss) Context.Subst.pp
ancestor_subst pp_raw q]
;
assert (not (is_false q)) ;
@ -866,7 +866,7 @@ let rec simplify_ us rev_xss survived ancestor_subst q =
invariant q']
let simplify q =
[%Trace.call fun {pf} -> pf "%a" pp_raw q]
[%Trace.call fun {pf} -> pf "@ %a" pp_raw q]
;
( if is_false q then false_ q.us
else

@ -657,7 +657,7 @@ let excise_dnf : Sh.t -> Var.Set.t -> Sh.t -> Sh.t option =
(Sh.false_ (Var.Set.union minuend.us xs))
~f:(fun minuend remainders ->
[%trace]
~call:(fun {pf} -> pf "@[<2>minuend@ %a@]" Sh.pp minuend)
~call:(fun {pf} -> pf "@ @[<2>minuend@ %a@]" Sh.pp minuend)
~retn:(fun {pf} -> pf "%a" (Option.pp "%a" Sh.pp))
@@ fun () ->
let zs, min = Sh.bind_exists minuend ~wrt:xs in
@ -666,7 +666,7 @@ let excise_dnf : Sh.t -> Var.Set.t -> Sh.t -> Sh.t option =
let+ remainder =
List.find_map dnf_subtrahend ~f:(fun sub ->
[%trace]
~call:(fun {pf} -> pf "@[<2>subtrahend@ %a@]" Sh.pp sub)
~call:(fun {pf} -> pf "@ @[<2>subtrahend@ %a@]" Sh.pp sub)
~retn:(fun {pf} -> pf "%a" (Option.pp "%a" Sh.pp))
@@ fun () ->
let sub = Sh.and_ctx min.ctx (Sh.extend_us us sub) in
@ -678,7 +678,7 @@ let infer_frame : Sh.t -> Var.Set.t -> Sh.t -> Sh.t option =
fun minuend xs subtrahend ->
[%trace]
~call:(fun {pf} ->
pf "@[<hv>%a@ \\- %a%a@]" Sh.pp minuend Var.Set.pp_xs xs Sh.pp
pf "@ @[<hv>%a@ \\- %a%a@]" Sh.pp minuend Var.Set.pp_xs xs Sh.pp
subtrahend )
~retn:(fun {pf} r ->
pf "%a" (Option.pp "%a" Sh.pp) r ;

Loading…
Cancel
Save