Skip to content

Commit 934d05d

Browse files
committed
[#14206,#14205] Cosmetics for of_int, of_nat
1 parent ad7c810 commit 934d05d

File tree

6 files changed

+16
-12
lines changed

6 files changed

+16
-12
lines changed

src/lib/pickles/common.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ let actual_wrap_domain_size ~log_2_domain_size =
4242
| _ ->
4343
assert false
4444
in
45-
Pickles_base.Proofs_verified.of_int d
45+
Pickles_base.Proofs_verified.of_int_exn d
4646

4747
let hash_messages_for_next_step_proof ~app_state
4848
(t : _ Types.Step.Proof_state.Messages_for_next_step_proof.t) =

src/lib/pickles/compile.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,8 @@ module Side_loaded = struct
849849
{ wrap_vk = Some (Lazy.force d.wrap_vk)
850850
; wrap_index = Lazy.force d.wrap_key
851851
; max_proofs_verified =
852-
Pickles_base.Proofs_verified.of_nat (Nat.Add.n d.max_proofs_verified)
852+
Pickles_base.Proofs_verified.of_nat_exn
853+
(Nat.Add.n d.max_proofs_verified)
853854
; actual_wrap_domain_size
854855
}
855856

src/lib/pickles/pickles.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ module Make_str (_ : Wire_types.Concrete) = struct
226226
{ wrap_vk = Some (Lazy.force d.wrap_vk)
227227
; wrap_index = Lazy.force d.wrap_key
228228
; max_proofs_verified =
229-
Pickles_base.Proofs_verified.of_nat
229+
Pickles_base.Proofs_verified.of_nat_exn
230230
(Nat.Add.n d.max_proofs_verified)
231231
; actual_wrap_domain_size
232232
}

src/lib/pickles/step.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@ struct
752752
~f:(fun j acc (Pow_2_roots_of_unity domain) ->
753753
if Int.equal domain domain_size then j else acc )
754754
in
755-
Pickles_base.Proofs_verified.of_int domain_index )
755+
Pickles_base.Proofs_verified.of_int_exn domain_index )
756756
in
757757
k wrap_domain_indices
758758
| _ -> (

src/lib/pickles_base/proofs_verified.ml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ let to_int : t -> int = function N0 -> 0 | N1 -> 1 | N2 -> 2
4040

4141
type proofs_verified = t
4242

43-
let of_nat (type n) (n : n Pickles_types.Nat.t) : t =
43+
let of_nat_exn (type n) (n : n Pickles_types.Nat.t) : t =
4444
let open Pickles_types.Nat in
4545
match n with
4646
| Z ->
@@ -50,9 +50,11 @@ let of_nat (type n) (n : n Pickles_types.Nat.t) : t =
5050
| S (S Z) ->
5151
N2
5252
| S _ ->
53-
failwithf "Proofs_verified.of_nat: got %d" (to_int n) ()
53+
raise
54+
(Invalid_argument
55+
(Printf.sprintf "Proofs_verified.of_nat: got %d" (to_int n)) )
5456

55-
let of_int (n : int) : t =
57+
let of_int_exn (n : int) : t =
5658
match n with
5759
| 0 ->
5860
N0
@@ -61,7 +63,8 @@ let of_int (n : int) : t =
6163
| 2 ->
6264
N2
6365
| _ ->
64-
failwithf "Proofs_verified.of_int: got %d" n ()
66+
raise
67+
(Invalid_argument (Printf.sprintf "Proofs_verified.of_int: got %d" n))
6568

6669
type 'f boolean = 'f Snarky_backendless.Cvar.t Snarky_backendless.Boolean.t
6770

src/lib/pickles_base/proofs_verified.mli

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ end
1313
type t = Stable.V1.t = N0 | N1 | N2
1414
[@@deriving sexp, compare, yojson, hash, equal]
1515

16-
(** [of_nat t_n] converts the type level natural [t_n] to the data type natural.
16+
(** [of_nat_exn t_n] converts the type level natural [t_n] to the data type natural.
1717
Raise an exception if [t_n] represents a value above or equal to 3 *)
18-
val of_nat : 'n Pickles_types.Nat.t -> t
18+
val of_nat_exn : 'n Pickles_types.Nat.t -> t
1919

20-
(** [of_int n] converts the runtime natural [n] to the data type natural. Raise
20+
(** [of_int_exn n] converts the runtime natural [n] to the data type natural. Raise
2121
an exception if the value [n] is above or equal to 3 *)
22-
val of_int : int -> t
22+
val of_int_exn : int -> t
2323

2424
(** [to_int v] converts the value [v] to the corresponding integer, i.e [N0 ->
2525
0], [N1 -> 1] and [N2 -> 2] *)

0 commit comments

Comments
 (0)