@@ -57,32 +57,6 @@ let circ_of_qsymbol (hyps: hyps) (qs: qsymbol) : circuit =
57
57
fc
58
58
with CircError err ->
59
59
raise (BDepError err)
60
-
61
-
62
- let initial_pstate_of_vars (env : env ) (invs : variable list ) : cinput list * (symbol, circuit) Map.t =
63
- let pstate : (symbol, circuit) Map.t = Map. empty in
64
-
65
- let inps = List. map (EcCircuits. input_of_variable env) invs in
66
- let inpcs, inps = List. split inps in
67
- (* List.iter (fun c -> Format.eprintf "Inp: %s @." (cinput_to_string c)) inps; *)
68
- let inpcs = List. combine inpcs @@ List. map (fun v -> v.v_name) invs in
69
-
70
- inps, List. fold_left
71
- (fun pstate (inp , v ) -> Map. add v inp pstate)
72
- pstate inpcs
73
-
74
- (* Generates pstate : (symbol, circuit) Map from program
75
- Throws: BDepError on failure
76
- *)
77
- let pstate_of_prog (hyps : hyps ) (mem : memory ) (proc : stmt ) (invs : variable list ) : (symbol, circuit) Map.t =
78
- let inps, pstate = initial_pstate_of_vars (toenv hyps) (invs) in
79
-
80
- let pstate = try
81
- List. fold_left (EcCircuits. process_instr hyps mem) pstate proc.s_node
82
- with CircError err ->
83
- raise (BDepError err)
84
- in
85
- Map. map (fun c -> assert (c.inps = [] ); {c with inps= inps}) pstate
86
60
87
61
88
62
(* -------------------------------------------------------------------- *)
@@ -117,7 +91,11 @@ let mapreduce
117
91
118
92
let tm = time tm " Precondition circuit generation done" in
119
93
120
- let pstate = pstate_of_prog hyps mem proc invs in
94
+ let pstate = try
95
+ EcCircuits. pstate_of_prog hyps mem proc.s_node invs
96
+ with CircError err ->
97
+ raise (BDepError err)
98
+ in
121
99
122
100
let tm = time tm " Program circuit generation done" in
123
101
@@ -126,7 +104,7 @@ let mapreduce
126
104
(List. map (fun v -> v.v_name) outvs) in
127
105
128
106
(* This is required for now as we do not allow mapreduce with multiple arguments *)
129
- assert (Set. cardinal @@ Set. of_list @@ List. map (fun c -> c.inps) circs = 1 );
107
+ (* assert (Set.cardinal @@ Set.of_list @@ List.map (fun c -> c.inps) circs = 1); *)
130
108
131
109
let c = try
132
110
(circuit_aggregate circs)
@@ -178,9 +156,17 @@ let prog_equiv_prod
178
156
in
179
157
let tm = Unix. gettimeofday () in
180
158
181
- let pstate_l : (symbol, circuit) Map.t = pstate_of_prog hyps meml proc_l invs_l in
159
+ let pstate_l : (symbol, circuit) Map.t = try
160
+ EcCircuits. pstate_of_prog hyps meml proc_l.s_node invs_l
161
+ with CircError err ->
162
+ raise (BDepError err)
163
+ in
182
164
let tm = time tm " Left program generation done" in
183
- let pstate_r : (symbol, circuit) Map.t = pstate_of_prog hyps memr proc_r invs_l in
165
+ let pstate_r : (symbol, circuit) Map.t = try
166
+ EcCircuits. pstate_of_prog hyps memr proc_r.s_node invs_l
167
+ with CircError err ->
168
+ raise (BDepError err)
169
+ in
184
170
let tm = time tm " Right program generation done" in
185
171
186
172
begin
@@ -189,14 +175,8 @@ let prog_equiv_prod
189
175
let circs_r = List. map (fun v -> Option. get (Map. find_opt v pstate_r))
190
176
(List. map (fun v -> v.v_name) outvs_r) in
191
177
192
- (* let () = List.iter2 (fun c v -> Format.eprintf "%s inputs: " v.v_name; *)
193
- (* List.iter (Format.eprintf "%s ") (List.map cinput_to_string c.inps); *)
194
- (* Format.eprintf "@."; ) circs outvs in *)
195
-
196
- (* let () = List.iter (fun c -> Format.eprintf "%s@." (circuit_to_string c)) circs in *)
197
- (* Only one input supported for now *)
198
- assert (Set. cardinal @@ Set. of_list @@ List. map (fun c -> c.inps) circs_l = 1 );
199
- assert (Set. cardinal @@ Set. of_list @@ List. map (fun c -> c.inps) circs_r = 1 );
178
+ (* assert (Set.cardinal @@ Set.of_list @@ List.map (fun c -> c.inps) circs_l = 1); *)
179
+ (* assert (Set.cardinal @@ Set.of_list @@ List.map (fun c -> c.inps) circs_r = 1);*)
200
180
let c_l = try
201
181
(circuit_aggregate circs_l)
202
182
with CircError _err ->
@@ -263,37 +243,6 @@ let prog_equiv_prod
263
243
if both sides are equivalent as circuits
264
244
or false otherwise
265
245
*)
266
- let rec circ_simplify_form_bitstring_equality
267
- ?(mem = mhr)
268
- ?(pstate : (symbol, circuit) Map.t = Map.empty )
269
- ?(pcond : circuit option )
270
- ?(inps : cinput list option )
271
- (hyps : hyps )
272
- (f : form )
273
- : form =
274
- let env = toenv hyps in
275
-
276
- let rec check (f : form ) =
277
- match sform_of_form f with
278
- | SFeq (f1, f2)
279
- when (Option. is_some @@ EcEnv.Circuit. lookup_bitstring env f1.f_ty)
280
- || (Option. is_some @@ EcEnv.Circuit. lookup_array env f1.f_ty)
281
- ->
282
- let c1 = circuit_of_form ~pstate hyps f1 in
283
- let c2 = circuit_of_form ~pstate hyps f2 in
284
- let c1, c2 = match inps with
285
- | Some inps -> {c1 with inps = inps}, {c2 with inps = inps}
286
- | None -> c1, c2
287
- in
288
- Format. eprintf " [W]Testing circuit equivalence for forms:
289
- %a@.%[email protected] circuits: %s | %s@."
290
- (EcPrinting. pp_form (EcPrinting.PPEnv. ofenv env)) f1
291
- (EcPrinting. pp_form (EcPrinting.PPEnv. ofenv env)) f2
292
- (circuit_to_string c1)
293
- (circuit_to_string c2);
294
- f_bool (circ_equiv c1 c2 pcond)
295
- | _ -> f_map (fun ty -> ty) check f
296
- in check f
297
246
298
247
let circ_form_eval_plus_equiv
299
248
?(mem = mhr)
@@ -307,8 +256,8 @@ let circ_form_eval_plus_equiv
307
256
let env = toenv hyps in
308
257
let redmode = circ_red hyps in
309
258
let (@@! ) = EcTypesafeFol. f_app_safe env in
310
- let inps = List. map (EcCircuits. input_of_variable env) invs in
311
- let inpcs, inps = List. split inps in
259
+ (* let inps = List.map (EcCircuits.input_of_variable env) invs in*)
260
+ (* let inpcs, inps = List.split inps in*)
312
261
let size, of_int = match EcEnv.Circuit. lookup_bitstring env v.v_type with
313
262
| Some {size; ofint} -> size, ofint
314
263
| None ->
@@ -322,11 +271,6 @@ let circ_form_eval_plus_equiv
322
271
true
323
272
else
324
273
let cur_val = of_int @@! [f_int cur] in
325
- let pstate : (symbol, circuit) Map.t = Map. empty in
326
- let pstate = List. fold_left2
327
- (fun pstate inp v -> Map. add v inp pstate)
328
- pstate inpcs (invs |> List. map (fun v -> v.v_name))
329
- in
330
274
let insts = List. map (fun i ->
331
275
match i.i_node with
332
276
| Sasgn (lv , e ) ->
@@ -338,12 +282,12 @@ let circ_form_eval_plus_equiv
338
282
| _ -> i
339
283
) proc.s_node
340
284
in
341
- let pstate = try
342
- List. fold_left ( EcCircuits. process_instr hyps mem) pstate insts
343
- with CircError err ->
344
- raise (BDepError ( " Program circuit generation failed with error: \n " ^ err) )
285
+ let pstate = try
286
+ EcCircuits. pstate_of_prog hyps mem insts invs
287
+ with CircError err ->
288
+ raise (BDepError err)
345
289
in
346
- let pstate = Map. map ( fun c -> assert (c.inps = [] ); {c with inps = inps}) pstate in
290
+
347
291
let f = EcPV.PVM. subst1 env (PVloc v.v_name) mem cur_val f in
348
292
let pcond = match Map. find_opt v.v_name pstate with
349
293
| Some circ -> begin try
@@ -353,10 +297,10 @@ let circ_form_eval_plus_equiv
353
297
end
354
298
| None -> None
355
299
in
356
- let () = Format. eprintf " Form before circuit simplify %a@." (EcPrinting. pp_form (EcPrinting.PPEnv. ofenv env)) f in
300
+ (* let () = Format.eprintf "Form before circuit simplify %a@." (EcPrinting.pp_form (EcPrinting.PPEnv.ofenv env)) f in*)
357
301
let f = EcCallbyValue. norm_cbv redmode hyps f in
358
- let () = Format. eprintf " Form after circuit simplify %a@." (EcPrinting. pp_form (EcPrinting.PPEnv. ofenv env)) f in
359
- let f = circ_simplify_form_bitstring_equality ~mem ~pstate ~inps ?pcond hyps f in
302
+ (* let () = Format.eprintf "Form after circuit simplify %a@." (EcPrinting.pp_form (EcPrinting.PPEnv.ofenv env)) f in*)
303
+ let f = EcCircuits. circ_simplify_form_bitstring_equality ~mem ~pstate ?pcond hyps f in
360
304
let f = EcCallbyValue. norm_cbv (EcReduction. full_red) hyps f in
361
305
if f <> f_true then
362
306
(Format. eprintf " Got %a after reduction@." (EcPrinting. pp_form (EcPrinting.PPEnv. ofenv env)) f;
@@ -387,17 +331,19 @@ let mapreduce_eval
387
331
388
332
let tm = time tm " Lane function circuit generation done" in
389
333
390
- let pstate = pstate_of_prog hyps mem proc invs in
334
+ let pstate = try
335
+ EcCircuits. pstate_of_prog hyps mem proc.s_node invs
336
+ with CircError err ->
337
+ raise (BDepError err)
338
+ in
391
339
392
340
let tm = time tm " Program circuit generation done" in
393
341
394
342
begin
395
343
let circs = List. map (fun v -> Option. get (Map. find_opt v pstate)) (List. map (fun v -> v.v_name) outvs) in
396
344
397
- assert (Set. cardinal @@ Set. of_list @@ List. map (fun c -> c.inps) circs = 1 );
398
- let cinp = (List. hd circs).inps in
399
345
let c = try
400
- { (circuit_aggregate circs) with inps = cinp}
346
+ (circuit_aggregate circs)
401
347
with CircError _err ->
402
348
raise (BDepError " Failed to concatenate program outputs" )
403
349
in
@@ -410,8 +356,6 @@ let mapreduce_eval
410
356
411
357
let tm = time tm " circuit dependecy analysis + splitting done" in
412
358
413
- List. iter (fun c -> Format. eprintf " %s@." (circuit_to_string c)) cs;
414
-
415
359
List. iteri (fun i c ->
416
360
if circ_equiv ~strict: true (List. hd cs) c None
417
361
then ()
0 commit comments