Skip to main content

Codegen

Trait Codegen 

Source
pub trait Codegen<'c: 's, 's>: Sized + 's {
    type FuncOutput: Lowering;
    type Output;
    type State: 'c;
    type Error: From<LoweringError> + From<Error>;

    // Required methods
    fn initialize(state: &'s Self::State) -> Self;
    fn define_function(
        &self,
        name: &str,
        inputs: usize,
        outputs: usize,
    ) -> Result<Self::FuncOutput, Self::Error>;
    fn define_main_function(
        &self,
        advice_io: &AdviceIO,
        instance_io: &InstanceIO,
    ) -> Result<Self::FuncOutput, Self::Error>;
    fn generate_output(self) -> Result<Self::Output, Self::Error>
       where Self::Output: 'c;

    // Provided methods
    fn set_prime_field(&self, prime: Prime) -> Result<(), Self::Error> { ... }
    fn define_function_with_body<FN, L, I>(
        &self,
        name: &str,
        inputs: usize,
        outputs: usize,
        f: FN,
    ) -> Result<(), Self::Error>
       where FN: FnOnce(&Self::FuncOutput, &[Slot], &[Slot]) -> Result<I, Self::Error>,
             I: IntoIterator<Item = L>,
             L: LowerableStmt { ... }
    fn define_main_function_with_body<L>(
        &self,
        advice_io: &AdviceIO,
        instance_io: &InstanceIO,
        stmts: impl IntoIterator<Item = L>,
    ) -> Result<(), Self::Error>
       where L: LowerableStmt + Debug { ... }
    fn on_scope_end(&self, _: Self::FuncOutput) -> Result<(), Self::Error> { ... }
}
Expand description

Implemented by code generators that emit some code representation of the circuit.

Required Associated Types§

Source

type FuncOutput: Lowering

Implementation of the lowering behavior.

Source

type Output

Final output of the code generator.

Source

type State: 'c

Internal state of the code generator.

Source

type Error: From<LoweringError> + From<Error>

Error type of the code generator.

Required Methods§

Source

fn initialize(state: &'s Self::State) -> Self

Initializes the code generator.

Source

fn define_function( &self, name: &str, inputs: usize, outputs: usize, ) -> Result<Self::FuncOutput, Self::Error>

Defines an empty function.

Source

fn define_main_function( &self, advice_io: &AdviceIO, instance_io: &InstanceIO, ) -> Result<Self::FuncOutput, Self::Error>

Defines the entrypoint function of the circuit.

Source

fn generate_output(self) -> Result<Self::Output, Self::Error>
where Self::Output: 'c,

Consumes the code generator and returns the final output.

Provided Methods§

Source

fn set_prime_field(&self, prime: Prime) -> Result<(), Self::Error>

Sets the prime field used by the circuit.

By default does nothing.

Source

fn define_function_with_body<FN, L, I>( &self, name: &str, inputs: usize, outputs: usize, f: FN, ) -> Result<(), Self::Error>
where FN: FnOnce(&Self::FuncOutput, &[Slot], &[Slot]) -> Result<I, Self::Error>, I: IntoIterator<Item = L>, L: LowerableStmt,

Defines a function filled with the given body.

Source

fn define_main_function_with_body<L>( &self, advice_io: &AdviceIO, instance_io: &InstanceIO, stmts: impl IntoIterator<Item = L>, ) -> Result<(), Self::Error>
where L: LowerableStmt + Debug,

Defines the entrypoint function of the circuit and fills it with the given body.

Source

fn on_scope_end(&self, _: Self::FuncOutput) -> Result<(), Self::Error>

Callback called when a scope ends.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§