Skip to content

Commit 635066a

Browse files
committed
(Hopefully) better error messages
1 parent 85f35ce commit 635066a

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

src/ecCircuits.ml

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ let ctype_of_ty (env: env) (ty: ty) : ctype =
5656
| _ ->
5757
Format.eprintf "Missing binding for type %a@."
5858
EcPrinting.(pp_type (PPEnv.ofenv env)) ty;
59-
assert false
59+
raise (CircError "Failed to convert EC type to Circuit type")
6060
end
6161
end
6262

@@ -291,7 +291,7 @@ let circuit_of_op (env: env) (p: path) : circuit =
291291
let op = try
292292
EcEnv.Circuit.reverse_operator env p |> List.hd
293293
with Failure _ ->
294-
assert false
294+
raise (CircError "Failed reverse operator")
295295
in
296296
match op with
297297
| `Bitstring (bs, op) -> assert false
@@ -303,7 +303,7 @@ let circuit_of_op_with_args (env: env) (p: path) (args: arg list) : circuit =
303303
let op = try
304304
EcEnv.Circuit.reverse_operator env p |> List.hd
305305
with Failure _ ->
306-
assert false
306+
raise (CircError "Failed reverse operator")
307307
in
308308
match op with
309309
| `Bitstring bsbnd -> circuit_of_bsop env (`BSBinding bsbnd) args
@@ -430,7 +430,7 @@ let circuit_of_form
430430
| _ ->
431431
if debug then Format.eprintf "Failed to get body for op: %a\n"
432432
(EcPrinting.pp_form (EcPrinting.PPEnv.ofenv (LDecl.toenv hyps))) op;
433-
assert false
433+
raise (CircError "Failed to get body for op in propagate integer arg")
434434
in
435435
(*
436436
if debug then Format.eprintf "Propagating arguments for op: %a@\n"
@@ -478,7 +478,8 @@ let circuit_of_form
478478
doit cache hyps f) hyps (form_list_of_form ~ppenv:(EcPrinting.PPEnv.ofenv (LDecl.toenv hyps)) f)
479479
in
480480
hyps, arg_of_circuits cs
481-
| _ -> assert false
481+
| _ -> Format.eprintf "Failed to convert form to arg: %a@." EcPrinting.(pp_form (PPEnv.ofenv env)) f;
482+
raise (CircError "Failed to convert arg to form")
482483
in
483484

484485
match f_.f_node with
@@ -506,7 +507,11 @@ let circuit_of_form
506507
hyps, op
507508
| None ->
508509
if op_is_base env pth then
509-
let circ = circuit_of_op env pth in
510+
let circ = try
511+
circuit_of_op env pth
512+
with
513+
| CircError e -> Format.eprintf "(%s ->)" (EcPath.tostring pth); raise (CircError e)
514+
in
510515
let hyps = EcEnv.Circuit.add_circuit_cache_hyps hyps pth circ in
511516
hyps, circ
512517
else
@@ -529,7 +534,7 @@ let circuit_of_form
529534
let hyps = EcEnv.Circuit.add_circuit_cache_hyps hyps pth circ in
530535
hyps, circ
531536
end
532-
| Fapp (f, fs) ->
537+
| Fapp (f, fs) -> begin try
533538
(* TODO: find a way to properly propagate int arguments. Done? *)
534539
begin match f with
535540
| {f_node = Fop (pth, _)} when op_is_parametric_base env pth ->
@@ -600,6 +605,10 @@ let circuit_of_form
600605
in
601606
hyps, circuit_compose f_c fcs
602607
end
608+
with CircError e ->
609+
Format.eprintf "Call %a ->" EcPrinting.(pp_form (PPEnv.ofenv env)) f;
610+
raise (CircError e)
611+
end
603612

604613
| Fquant (qnt, binds, f) ->
605614
let binds = List.map (fun (idn, t) -> (idn, gty_as_ty t |> ctype_of_ty env)) binds in
@@ -672,8 +681,8 @@ let circuit_of_form
672681
let hyps, fn = doit cache hyps fn in
673682
hyps, circuit_compose fn [f]
674683
) (doit cache hyps base) fs
675-
| ({f_node = Fop (p, _)}, [rep; fn; base]) when p = EcCoreLib.CI_Int.p_iter -> assert false
676-
| ({f_node = Fop (p, _)}, [rep; fn; base]) when p = EcCoreLib.CI_Int.p_fold -> assert false
684+
| ({f_node = Fop (p, _)}, [rep; fn; base]) when p = EcCoreLib.CI_Int.p_iter -> assert false
685+
| ({f_node = Fop (p, _)}, [rep; fn; base]) when p = EcCoreLib.CI_Int.p_fold -> assert false
677686
| _ -> assert false
678687
in
679688
(*

0 commit comments

Comments
 (0)