Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove polymorphism from As_prover.t, hoist Typ.t #854

Merged
merged 16 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion src/base/checked_runner.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,41 @@ module Simple_types = struct
end

module Typ = struct
include Types.Typ.T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay.

(** The type [('var, 'value, 'field, 'checked) t] describes a mapping from
OCaml types to the variables and constraints they represent:
- ['value] is the OCaml type
- ['field] is the type of the field elements
- ['var] is some other type that contains some R1CS variables
- ['checked] is the type of checked computation that verifies the stored
contents as R1CS variables.

For convenience and readability, it is usually best to have the ['var]
type mirror the ['value] type in structure, for example:
{[
type t = {b1 : bool; b2 : bool} (* 'value *)

let or (x : t) = x.b1 || x.b2

module Checked = struct
type t = {b1 : Snark.Boolean.var; b2 : Snark.Boolean.var} (* 'var *)

let or (x : t) = Snark.Boolean.(x.b1 || x.b2)
end
]}*)
type ('var, 'value, 'aux, 'field, 'checked) typ' =
{ var_to_fields : 'var -> 'field Cvar.t array * 'aux
; var_of_fields : 'field Cvar.t array * 'aux -> 'var
; value_to_fields : 'value -> 'field array * 'aux
; value_of_fields : 'field array * 'aux -> 'value
; size_in_field_elements : int
; constraint_system_auxiliary : unit -> 'aux
; check : 'var -> 'checked
}

type ('var, 'value, 'field, 'checked) typ =
| Typ :
('var, 'value, 'aux, 'field, 'checked) typ'
-> ('var, 'value, 'field, 'checked) typ

type ('var, 'value, 'f) t = ('var, 'value, 'f, (unit, 'f) Checked.t) typ
end
Expand Down
40 changes: 0 additions & 40 deletions src/base/types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,46 +20,6 @@ module Provider = struct
type ('request, 'compute) t = ('request, 'compute) provider
end

module Typ = struct
module T = struct
(** The type [('var, 'value, 'field, 'checked) t] describes a mapping from
OCaml types to the variables and constraints they represent:
- ['value] is the OCaml type
- ['field] is the type of the field elements
- ['var] is some other type that contains some R1CS variables
- ['checked] is the type of checked computation that verifies the stored
contents as R1CS variables.

For convenience and readability, it is usually best to have the ['var]
type mirror the ['value] type in structure, for example:
{[
type t = {b1 : bool; b2 : bool} (* 'value *)

let or (x : t) = x.b1 || x.b2

module Checked = struct
type t = {b1 : Snark.Boolean.var; b2 : Snark.Boolean.var} (* 'var *)

let or (x : t) = Snark.Boolean.(x.b1 || x.b2)
end
]}*)
type ('var, 'value, 'aux, 'field, 'checked) typ' =
{ var_to_fields : 'var -> 'field Cvar.t array * 'aux
; var_of_fields : 'field Cvar.t array * 'aux -> 'var
; value_to_fields : 'value -> 'field array * 'aux
; value_of_fields : 'field array * 'aux -> 'value
; size_in_field_elements : int
; constraint_system_auxiliary : unit -> 'aux
; check : 'var -> 'checked
}

type ('var, 'value, 'field, 'checked) typ =
| Typ :
('var, 'value, 'aux, 'field, 'checked) typ'
-> ('var, 'value, 'field, 'checked) typ
end
end

module type Types = sig
module Checked : sig
type ('a, 'f) t
Expand Down