Skip to content

Commit b5ed75f

Browse files
committed
Added context to bdep solve
1 parent 8565990 commit b5ed75f

4 files changed

Lines changed: 48 additions & 8 deletions

File tree

examples/mapreduce_paper.ec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ admit.
107107
admit.
108108
qed.
109109

110-
lemma xor_left_eq_xor_right : forall (w: W8.t), xor_left w = xor_right w.
110+
lemma xor_left_eq_xor_right (w: W8.t) : xor_left w = xor_right w.
111111
proof.
112112
bdep solve.
113113
qed.

src/ecCircuits.ml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ module type CircuitInterface = sig
134134
type cache
135135
val update_cache : cache -> lpattern -> circuit -> cache
136136
val cache_get : cache -> ident -> circuit
137+
val cache_add : cache -> ident -> circuit -> cache
137138
val empty_cache : cache
138139
val cache_map : (ident -> circuit -> circuit) -> cache -> cache
139140
end
@@ -809,6 +810,9 @@ module MakeCircuitInterfaceFromCBackend(Backend: CBackend) : CircuitInterface =
809810
with Not_found ->
810811
assert false (* FIXME: Error handling *)
811812

813+
let cache_add (cache: cache) (idn: ident) (c: circuit) : cache =
814+
Map.add idn c cache
815+
812816
let empty_cache : cache =
813817
Map.empty
814818

@@ -1706,10 +1710,10 @@ let (op_cache : circuit Mp.t ref) = ref Mp.empty
17061710

17071711
let circuit_of_form
17081712
?(pstate : pstate = empty_pstate) (* Program variable values *)
1713+
?(cache : cache = empty_cache)
17091714
(hyps : hyps)
17101715
(f_ : EcAst.form)
17111716
: circuit =
1712-
let cache = empty_cache in
17131717

17141718
let rec doit (cache: cache) (hyps: hyps) (f_: form) : hyps * circuit =
17151719
let env = toenv hyps in
@@ -2131,6 +2135,10 @@ let circuit_mapreduce ?(perm : (int -> int) option) (c: circuit) (w_in: width) (
21312135

21322136
type circuit = ExampleInterface.circuit
21332137
type pstate = ExampleInterface.PState.pstate
2138+
type cache = ExampleInterface.LocalCache.cache
2139+
let cache_get = cache_get
2140+
let cache_add = cache_add
2141+
let empty_cache = empty_cache
21342142
let circuit_to_string (c: circuit) : string = assert false
21352143
let pstate_get = pstate_get
21362144
let pstate_get_opt = pstate_get_opt

src/ecCircuits.mli

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module Map = Batteries.Map
1111
(* -------------------------------------------------------------------- *)
1212
type circuit
1313
type pstate
14+
type cache
1415

1516
(* -------------------------------------------------------------------- *)
1617
exception CircError of string
@@ -27,6 +28,11 @@ val pstate_get : pstate -> symbol -> circuit
2728
val pstate_get_opt : pstate -> symbol -> circuit option
2829
val pstate_get_all : pstate -> circuit list
2930

31+
(* Cache utilities *)
32+
val cache_get : cache -> ident -> circuit
33+
val cache_add : cache -> ident -> circuit -> cache
34+
val empty_cache : cache
35+
3036
(* Transform circuits *)
3137
val circuit_ueq : circuit -> circuit -> circuit
3238
val circuit_aggregate : circuit list -> circuit
@@ -43,7 +49,7 @@ val circ_taut : circuit -> bool
4349

4450
(* Generate circuits *)
4551
(* Form processors *)
46-
val circuit_of_form : ?pstate:pstate -> hyps -> form -> circuit
52+
val circuit_of_form : ?pstate:pstate -> ?cache:cache -> hyps -> form -> circuit
4753
val circ_simplify_form_bitstring_equality :
4854
?mem:EcMemory.memory ->
4955
?pstate:pstate ->

src/phl/ecPhlBDep.ml

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,10 +1000,36 @@ let process_bdep_eval (bdeinfo: bdep_eval_info) (tc: tcenv1) =
10001000
let tc = EcPhlConseq.t_hoareS_conseq_nm pre post tc in
10011001
FApi.t_last (t_bdep_eval n m inpvs outvs lane frange sign) tc
10021002

1003+
(* TODO: Figure out how to not repeat computations here? *)
10031004
let t_bdep_solve
10041005
(tc : tcenv1) =
1005-
if circ_taut (circuit_of_form (FApi.tc1_hyps tc) (FApi.tc1_goal tc)) then
1006-
FApi.close (!@ tc) VBdep
1007-
else
1008-
tc_error (FApi.tc1_penv tc) "Failed to solve goal through circuit reasoning@\n"
1009-
1006+
begin
1007+
let hyps = (FApi.tc1_hyps tc) in
1008+
let goal = (FApi.tc1_goal tc) in
1009+
let ctxt = tohyps hyps in
1010+
assert (ctxt.h_tvar = []);
1011+
let ctxt = ctxt.h_local in
1012+
let goal = List.fold_left (fun goal (id, lk) ->
1013+
match lk with
1014+
| EcBaseLogic.LD_var (t, Some f) ->
1015+
begin try
1016+
ignore (circuit_of_form hyps (f_forall [(id, GTty t)] f));
1017+
f_forall [(id, GTty t)] (f_and goal (f_eq (f_local id t) f))
1018+
with _ -> f_forall [(id, GTty t)] goal
1019+
end
1020+
| EcBaseLogic.LD_var (t, None) -> f_forall [(id, GTty t)] goal
1021+
| EcBaseLogic.LD_hyp f ->
1022+
begin try
1023+
ignore (circuit_of_form hyps f);
1024+
f_and f goal
1025+
with _ -> goal
1026+
end
1027+
| EcBaseLogic.LD_mem _
1028+
| EcBaseLogic.LD_modty _
1029+
| EcBaseLogic.LD_abs_st _ -> assert false
1030+
) goal ctxt in
1031+
if circ_taut (circuit_of_form hyps goal) then
1032+
FApi.close (!@ tc) VBdep
1033+
else
1034+
tc_error (FApi.tc1_penv tc) "Failed to solve goal through circuit reasoning@\n"
1035+
end

0 commit comments

Comments
 (0)