157157
158158(* -------------------------------------------------------------------- *)
159159type width = int
160- exception CircError of string Lazy .t
161160exception MissingTyBinding of ty
162161exception AbstractTyBinding of ty
163162exception InvalidArgument
@@ -168,8 +167,9 @@ exception DestrError of string (* FIXME: change this one *)
168167exception MissingOpBody (* FIXME: rename? *)
169168exception BadFormForArg (* FIXME: rename *)
170169exception CantConvertToConstant
170+ exception CantReadWriteGlobs
171171exception CantConvertToCirc of
172- [`Int
172+ [ `Int
173173 | `OpK of EcFol .op_kind
174174 | `Op of path
175175 | `Quantif of quantif
@@ -302,17 +302,17 @@ module BitstringOps = struct
302302 in
303303 (* assert false => should be guarded by a previous call to op_is_bsop *)
304304 match bnd with
305- | bs , `From -> assert false (* doesn't translate to circuit *)
305+ | _bs , `From -> assert false (* doesn't translate to circuit *)
306306 | {size = (_ , Some size )} , `OfInt -> begin match args with
307307 | [ `Constant i ] ->
308308 circuit_of_zint ~size i
309- | args -> raise InvalidArgument
309+ | _args -> raise InvalidArgument
310310 end
311311 | {size = (_ , None); type_ =ty } , `OfInt ->
312312 raise (AbstractTyBinding (ty_of_path ty)) (* FIXME: check this, might want to add generic path -> ty conversion *)
313- | bs , `To -> assert false (* doesn't translate to circuit *)
314- | bs , `ToSInt -> assert false (* doesn't translate to circuit *)
315- | bs , `ToUInt -> assert false (* doesn't translate to circuit *)
313+ | _bs , `To -> assert false (* doesn't translate to circuit *)
314+ | _bs , `ToSInt -> assert false (* doesn't translate to circuit *)
315+ | _bs , `ToUInt -> assert false (* doesn't translate to circuit *)
316316end
317317open BitstringOps
318318
@@ -337,23 +337,23 @@ module ArrayOps = struct
337337 in
338338 (* assert false => should be guarded by a call to op_is_arrayop *)
339339 match op with
340- | (arr , `ToList) -> assert false (* We do not translate this to circuit *)
341- | (arr , `Get) -> begin match args with
342- | [ `Circuit (({type_ = CArray _}, inps ) as arr); `Constant i] ->
340+ | (_arr , `ToList) -> assert false (* We do not translate this to circuit *)
341+ | (_arr , `Get) -> begin match args with
342+ | [ `Circuit (({type_ = CArray _}, _inps ) as arr); `Constant i] ->
343343 array_get arr (BI. to_int i)
344- | args -> raise InvalidArgument
344+ | _args -> raise InvalidArgument
345345 end
346346 | ({size = (_ , Some size )} , `OfList) -> begin match args with
347347 | [ `Circuit dfl; `List cs ] -> array_oflist cs dfl size
348- | args -> raise InvalidArgument
348+ | _args -> raise InvalidArgument
349349 end
350350 | ({size = (_ , None); type_ =ty } , `OfList) -> raise (AbstractTyBinding (ty_of_path ty))
351351 | (_arr , `Set) -> begin match args with
352352 | [ `Circuit (({type_ = CArray _}, _) as arr);
353353 `Constant i;
354354 `Circuit (({type_ = CBitstring _}, _) as bs) ] ->
355355 array_set arr (BI. to_int i) bs
356- | args -> raise InvalidArgument
356+ | _args -> raise InvalidArgument
357357 end
358358end
359359open ArrayOps
@@ -428,7 +428,7 @@ let circuit_of_op (env: env) (p: path) : circuit =
428428 raise (MissingOpBinding p)
429429 in
430430 match op with
431- | `Bitstring (bs , op ) -> assert false (* Should be guarded by a call to op_is_base *)
431+ | `Bitstring (_bs , _op ) -> assert false (* Should be guarded by a call to op_is_base *)
432432 | `Array _ -> assert false (* Should be guarded by a call to op_is_parametric_base *)
433433 | `BvOperator bvbnd -> circuit_of_bvop env (`BvBind bvbnd)
434434 | `Circuit c -> circuit_from_spec env (`Bind c)
@@ -443,7 +443,7 @@ let circuit_of_op_with_args (env: env) (p: path) (args: arg list) : circuit =
443443 | `Bitstring bsbnd -> circuit_of_bsop env (`BSBinding bsbnd) args
444444 | `Array abnd -> circuit_of_arrayop env (`ABinding abnd) args
445445 | `BvOperator bvbnd -> circuit_of_parametric_bvop env (`BvBind bvbnd) args
446- | `Circuit c -> assert false (* FIXME PR: Do we want to have parametric operators coming from the spec? *)
446+ | `Circuit _c -> assert false (* FIXME PR: Do we want to have parametric operators coming from the spec? *)
447447
448448
449449let type_has_bindings (env : env ) (t : ty ) : bool =
@@ -506,12 +506,12 @@ let expand_iter_form (hyps: hyps) (f: form) : form =
506506 | Fapp ({f_node = Fop (p , _ )} , [rep ; fn ; base ]) when p = EcCoreLib.CI_Int. p_iter ->
507507 let rep = int_of_form hyps rep in
508508 let is = List. init (BI. to_int rep) BI. of_int in
509- let f = List. fold_left (fun f i -> fn @!! [f]) base is in
509+ let f = List. fold_left (fun f _i -> fn @!! [f]) base is in
510510 f
511511 | Fapp ({f_node = Fop (p , _ )} , [fn ; base ; rep ]) when p = EcCoreLib.CI_Int. p_fold ->
512512 let rep = int_of_form hyps rep in
513513 let is = List. init (BI. to_int rep) BI. of_int in
514- let f = List. fold_left (fun f i -> fn @!! [f]) base is in
514+ let f = List. fold_left (fun f _i -> fn @!! [f]) base is in
515515 f
516516 | _ -> raise (DestrError " iter" )
517517 in
@@ -581,7 +581,7 @@ let circuit_of_form
581581 and doit (st : state ) (f_ : form ) : circuit =
582582 try begin
583583 match f_.f_node with
584- | Fint z -> raise (CantConvertToCirc `Int )
584+ | Fint _z -> raise (CantConvertToCirc `Int )
585585
586586 | Fif (c_f , t_f , f_f ) ->
587587 let t = doit st t_f in
@@ -641,7 +641,7 @@ let circuit_of_form
641641 | {f_node = Fop _ } when form_is_iter f_ ->
642642 trans_iter st hyps f fs
643643
644- | {f_node = Fop (p , _ )} when not (List. for_all (fun f -> f.f_ty.ty_node <> EcTypes. tint.ty_node) fs) ->
644+ | {f_node = Fop (_p , _ )} when not (List. for_all (fun f -> f.f_ty.ty_node <> EcTypes. tint.ty_node) fs) ->
645645 doit st (propagate_integer_arguments f fs)
646646
647647 | {f_node = Fop _ } ->
@@ -711,17 +711,17 @@ let circuit_of_form
711711 let ftp = doit st f in
712712 (circuit_tuple_proj ftp i :> circuit )
713713
714- | Fmatch (f , fs , ty ) -> raise (CantConvertToCirc `Match )
714+ | Fmatch (_f , _fs , _ty ) -> raise (CantConvertToCirc `Match )
715715
716- | Flet (LSymbol (id , t ), v , f ) ->
716+ | Flet (LSymbol (id , _t ), v , f ) ->
717717 let vc = doit st v in
718718 let st = update_state st id vc in
719719 doit st f
720720
721721 | Flet (LTuple vs , v , f ) ->
722722 let vc = doit st v in
723723 let comps = circuits_of_circuit_tuple vc in
724- let st = List. fold_left2 (fun st (id , t ) vc ->
724+ let st = List. fold_left2 (fun st (id , _t ) vc ->
725725 update_state st id vc)
726726 st
727727 vs
@@ -744,7 +744,7 @@ let circuit_of_form
744744 in
745745 v
746746
747- | Fglob (id , mem ) -> raise (CantConvertToCirc `Glob )
747+ | Fglob (_id , _mem ) -> raise (CantConvertToCirc `Glob )
748748
749749 | Ftuple comps ->
750750 let comps =
@@ -769,6 +769,11 @@ let circuit_of_form
769769 EcPrinting. (pp_form ppe) f_
770770 (Printexc. to_string e);
771771 assert false
772+ | (MissingTyBinding ty ) ->
773+ Format. eprintf " Failed on form %a because of missing type binding for type %a@."
774+ EcPrinting. (pp_form ppe) f_
775+ EcPrinting. (pp_type ppe) ty;
776+ assert false
772777 | e ->
773778 Format. eprintf " Failed on %a with exception %s@."
774779 EcPrinting. (pp_form ppe) f_
@@ -905,12 +910,11 @@ let process_instr ?me (hyps: hyps) (mem: memory) ~(st: state) (inst: instr) : st
905910 with
906911 | e ->
907912 (* FIXME: Bad handling, use new exceptions *)
908- let err = lazy (
909- Format. asprintf " BDep failed on instr: %a@.Exception thrown: %s@.BACKTRACE: %s@.@."
913+ Format. eprintf " BDep failed on instr: %a@.Exception thrown: %s@.BACKTRACE: %s@.@."
910914 (EcPrinting. pp_instr (EcPrinting.PPEnv. ofenv env)) inst
911915 (Printexc. to_string e)
912- (Printexc. get_backtrace () )) in
913- raise ( CircError err)
916+ (Printexc. get_backtrace () );
917+ raise e
914918
915919(* FIXME: check if memory is the right one in calls to state *)
916920let instrs_equiv
@@ -927,10 +931,10 @@ let instrs_equiv
927931 let wr, wglobs = EcPV.PV. elements (EcPV. is_write env (s1 @ s2)) in
928932
929933 if not (List. is_empty rglobs && List. is_empty wglobs) then
930- raise ( CircError ( lazy " the statements should not read/write globs " )) ;
934+ raise CantReadWriteGlobs ;
931935
932936 if not (List. for_all (EcTypes. is_loc |- fst) (rd @ wr)) then
933- raise ( CircError ( lazy " the statements should not read/write global variables " )) ;
937+ raise CantReadWriteGlobs ;
934938
935939 let inputs = List. map (fun (pv , ty ) -> { v_name = EcTypes. get_loc pv; v_type = ty; }) (rd @ wr) in
936940 let inputs = List. map (fun {v_name; v_type} -> (create v_name, ctype_of_ty env v_type)) inputs in
@@ -1064,10 +1068,12 @@ let circuit_state_of_hyps ?(strict = false) ?(use_mem = false) ?(st = empty_stat
10641068 if debug then Format. eprintf " Assigning %a to %a@." EcPrinting. (pp_form ppe) f EcIdent. pp_ident id;
10651069 begin try
10661070 update_state st id (circuit_of_form ~st hyps f)
1067- with CircError _ ->
1071+ (* FIXME PR: Should only catch circuit translation errors, hack *)
1072+ with e ->
10681073 try
10691074 open_circ_lambda st [(id, ctype_of_ty env t)]
1070- with (CircError _ ) as e ->
1075+ (* FIXME PR: Should only catch circuit translation errors, hack *)
1076+ with e ->
10711077 if strict then raise e else st
10721078 end
10731079
@@ -1076,7 +1082,8 @@ let circuit_state_of_hyps ?(strict = false) ?(use_mem = false) ?(st = empty_stat
10761082 | EcBaseLogic. LD_var (t , None) ->
10771083 begin try
10781084 open_circ_lambda st [(id, ctype_of_ty env t)]
1079- with (CircError _ ) as e ->
1085+ (* FIXME PR: Should only catch circuit translation errors, hack *)
1086+ with e ->
10801087 if strict then raise e else st end
10811088
10821089 (* For things of the form a_ = a{&hr}, we assume the local variable takes precedence *)
@@ -1090,7 +1097,8 @@ let circuit_state_of_hyps ?(strict = false) ?(use_mem = false) ?(st = empty_stat
10901097 | {f_node =Fapp ({f_node = Fop (p , _ ); _} , [fv ; {f_node = Fpvar (PVloc pv , m ); _} ])} when EcFol. op_kind p = Some `Eq ->
10911098 begin try
10921099 update_state_pv st m pv (circuit_of_form ~st hyps fv)
1093- with CircError _ ->
1100+ (* FIXME PR: Should only catch circuit translation errors, hack *)
1101+ with e ->
10941102 st
10951103 end
10961104 | _ -> st
0 commit comments