Skip to content

Commit

Permalink
Remove lifetimes.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Nov 23, 2024
1 parent b3272db commit 1146653
Show file tree
Hide file tree
Showing 13 changed files with 52 additions and 61 deletions.
15 changes: 7 additions & 8 deletions executor/src/witgen/block_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,18 @@ use super::{
/// for a given list of identities.
/// The lifetimes mean the following:
/// - `'a`: The duration of the entire witness generation (e.g. references to identities)
/// - `'b`: The duration of this machine's call (e.g. the mutable references of the other machines)
/// - `'c`: The duration of this Processor's lifetime (e.g. the reference to the identity processor)
pub struct BlockProcessor<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> {
processor: Processor<'a, 'b, 'c, T, Q>,
pub struct BlockProcessor<'a, 'c, T: FieldElement, Q: QueryCallback<T>> {
processor: Processor<'a, 'c, T, Q>,
/// The list of identities
identities: &'c [&'a Identity<T>],
}

impl<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> BlockProcessor<'a, 'b, 'c, T, Q> {
impl<'a, 'c, T: FieldElement, Q: QueryCallback<T>> BlockProcessor<'a, 'c, T, Q> {
pub fn new(
row_offset: RowIndex,
mutable_data: SolverState<'a, T>,
mutable_state: &'c MutableState<'a, 'b, T, Q>,
mutable_state: &'c MutableState<'a, T, Q>,
fixed_data: &'a FixedData<'a, T>,
parts: &'c MachineParts<'a, T>,
size: DegreeType,
Expand All @@ -48,7 +47,7 @@ impl<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> BlockProcessor<'a, 'b, 'c
}

pub fn from_processor(
processor: Processor<'a, 'b, 'c, T, Q>,
processor: Processor<'a, 'c, T, Q>,
identities: &'c [&'a Identity<T>],
) -> Self {
Self {
Expand All @@ -59,8 +58,8 @@ impl<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> BlockProcessor<'a, 'b, 'c

pub fn with_outer_query(
self,
outer_query: OuterQuery<'a, 'b, T>,
) -> BlockProcessor<'a, 'b, 'c, T, Q> {
outer_query: OuterQuery<'a, 'c, T>,
) -> BlockProcessor<'a, 'c, T, Q> {
let processor = self.processor.with_outer_query(outer_query);
Self { processor, ..self }
}
Expand Down
8 changes: 4 additions & 4 deletions executor/src/witgen/data_structures/mutable_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ use crate::witgen::{
/// The container and access method for machines and the query callback.
/// The machines contain the actual data tables.
/// This struct uses interior mutability for accessing the machines.
pub struct MutableState<'a, 'b, T: FieldElement, Q: QueryCallback<T>> {
pub struct MutableState<'a, T: FieldElement, Q: QueryCallback<T>> {
machines: Vec<RefCell<KnownMachine<'a, T>>>,
identity_to_machine_index: BTreeMap<u64, usize>,
query_callback: &'b Q,
query_callback: &'a Q,
}

impl<'a, 'b, T: FieldElement, Q: QueryCallback<T>> MutableState<'a, 'b, T, Q> {
pub fn new(machines: impl Iterator<Item = KnownMachine<'a, T>>, query_callback: &'b Q) -> Self {
impl<'a, T: FieldElement, Q: QueryCallback<T>> MutableState<'a, T, Q> {
pub fn new(machines: impl Iterator<Item = KnownMachine<'a, T>>, query_callback: &'a Q) -> Self {
let machines: Vec<_> = machines.map(RefCell::new).collect();
let identity_to_machine_index = machines
.iter()
Expand Down
15 changes: 6 additions & 9 deletions executor/src/witgen/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for Generator<'a, T> {

fn process_plookup<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &MutableState<'a, 'b, T, Q>,
mutable_state: &MutableState<'a, T, Q>,
identity_id: u64,
caller_rows: &'b RowPair<'b, 'a, T>,
) -> EvalResult<'a, T> {
Expand Down Expand Up @@ -91,7 +91,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for Generator<'a, T> {

fn take_witness_col_values<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &'b MutableState<'a, 'b, T, Q>,
mutable_state: &'b MutableState<'a, T, Q>,
) -> HashMap<String, Vec<T>> {
log::debug!("Finalizing VM: {}", self.name());

Expand Down Expand Up @@ -133,7 +133,7 @@ impl<'a, T: FieldElement> Generator<'a, T> {
}

/// Runs the machine without any arguments from the first row.
pub fn run<'b, Q: QueryCallback<T>>(&mut self, mutable_state: &MutableState<'a, 'b, T, Q>) {
pub fn run<'b, Q: QueryCallback<T>>(&mut self, mutable_state: &MutableState<'a, T, Q>) {
record_start(self.name());
assert!(self.data.is_empty());
let first_row = self.compute_partial_first_row(mutable_state);
Expand All @@ -144,10 +144,7 @@ impl<'a, T: FieldElement> Generator<'a, T> {
record_end(self.name());
}

fn fill_remaining_rows<Q: QueryCallback<T>>(
&mut self,
mutable_state: &MutableState<'a, '_, T, Q>,
) {
fn fill_remaining_rows<Q: QueryCallback<T>>(&mut self, mutable_state: &MutableState<'a, T, Q>) {
if self.data.len() < self.degree as usize + 1 {
assert!(self.latch.is_some());

Expand All @@ -173,7 +170,7 @@ impl<'a, T: FieldElement> Generator<'a, T> {
/// row from identities like `pc' = (1 - first_step') * <...>`.
fn compute_partial_first_row<Q: QueryCallback<T>>(
&self,
mutable_state: &MutableState<'a, '_, T, Q>,
mutable_state: &MutableState<'a, T, Q>,
) -> Row<T> {
// Use `BlockProcessor` + `DefaultSequenceIterator` using a "block size" of 0. Because `BlockProcessor`
// expects `data` to include the row before and after the block, this means we'll run the
Expand Down Expand Up @@ -219,7 +216,7 @@ impl<'a, T: FieldElement> Generator<'a, T> {
&mut self,
first_row: Row<T>,
row_offset: DegreeType,
mutable_state: &MutableState<'a, 'b, T, Q>,
mutable_state: &MutableState<'a, T, Q>,
outer_query: Option<OuterQuery<'a, 'c, T>>,
is_main_run: bool,
) -> ProcessResult<'a, T> {
Expand Down
9 changes: 4 additions & 5 deletions executor/src/witgen/identity_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@ use super::{
/// Computes (value or range constraint) updates given a [RowPair] and [Identity].
/// The lifetimes mean the following:
/// - `'a`: The duration of the entire witness generation (e.g. references to identities)
/// - `'b`: The duration of this machine's call (e.g. the mutable references of the other machines)
/// - `'c`: The duration of this IdentityProcessor's lifetime (e.g. the reference to the mutable state)
pub struct IdentityProcessor<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> {
mutable_state: &'c MutableState<'a, 'b, T, Q>,
pub struct IdentityProcessor<'a, 'c, T: FieldElement, Q: QueryCallback<T>> {
mutable_state: &'c MutableState<'a, T, Q>,
}

impl<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> IdentityProcessor<'a, 'b, 'c, T, Q> {
pub fn new(mutable_state: &'c MutableState<'a, 'b, T, Q>) -> Self {
impl<'a, 'c, T: FieldElement, Q: QueryCallback<T>> IdentityProcessor<'a, 'c, T, Q> {
pub fn new(mutable_state: &'c MutableState<'a, T, Q>) -> Self {
Self { mutable_state }
}

Expand Down
8 changes: 4 additions & 4 deletions executor/src/witgen/machines/block_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for BlockMachine<'a, T> {

fn process_plookup<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &'b MutableState<'a, 'b, T, Q>,
mutable_state: &'b MutableState<'a, T, Q>,
identity_id: u64,
caller_rows: &'b RowPair<'b, 'a, T>,
) -> EvalResult<'a, T> {
Expand All @@ -162,7 +162,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for BlockMachine<'a, T> {

fn take_witness_col_values<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &'b MutableState<'a, 'b, T, Q>,
mutable_state: &'b MutableState<'a, T, Q>,
) -> HashMap<String, Vec<T>> {
if self.data.len() < 2 * self.block_size {
if self.fixed_data.is_monolithic() {
Expand Down Expand Up @@ -351,7 +351,7 @@ impl<'a, T: FieldElement> BlockMachine<'a, T> {

fn process_plookup_internal<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &MutableState<'a, 'b, T, Q>,
mutable_state: &MutableState<'a, T, Q>,
identity_id: u64,
caller_rows: &'b RowPair<'b, 'a, T>,
) -> EvalResult<'a, T> {
Expand Down Expand Up @@ -420,7 +420,7 @@ impl<'a, T: FieldElement> BlockMachine<'a, T> {

fn process<'b, Q: QueryCallback<T>>(
&self,
mutable_state: &MutableState<'a, 'b, T, Q>,
mutable_state: &MutableState<'a, T, Q>,
sequence_iterator: &mut ProcessingSequenceIterator,
outer_query: OuterQuery<'a, 'b, T>,
) -> Result<ProcessResult<'a, T>, EvalError<T>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for DoubleSortedWitnesses16<'a, T> {

fn process_plookup<Q: QueryCallback<T>>(
&mut self,
_mutable_state: &MutableState<'a, '_, T, Q>,
_mutable_state: &MutableState<'a, T, Q>,
identity_id: u64,
caller_rows: &RowPair<'_, 'a, T>,
) -> EvalResult<'a, T> {
Expand All @@ -229,7 +229,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for DoubleSortedWitnesses16<'a, T> {

fn take_witness_col_values<'b, Q: QueryCallback<T>>(
&mut self,
_mutable_state: &'b MutableState<'a, 'b, T, Q>,
_mutable_state: &'b MutableState<'a, T, Q>,
) -> HashMap<String, Vec<T>> {
let mut addr: Vec<Word32<T>> = vec![];
let mut step: Vec<Word32<T>> = vec![];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for DoubleSortedWitnesses32<'a, T> {

fn process_plookup<Q: QueryCallback<T>>(
&mut self,
_mutable_state: &MutableState<'a, '_, T, Q>,
_mutable_state: &MutableState<'a, T, Q>,
identity_id: u64,
caller_rows: &RowPair<'_, 'a, T>,
) -> EvalResult<'a, T> {
Expand All @@ -199,7 +199,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for DoubleSortedWitnesses32<'a, T> {

fn take_witness_col_values<'b, Q: QueryCallback<T>>(
&mut self,
_mutable_state: &'b MutableState<'a, 'b, T, Q>,
_mutable_state: &'b MutableState<'a, T, Q>,
) -> HashMap<String, Vec<T>> {
let mut addr = vec![];
let mut step = vec![];
Expand Down
8 changes: 4 additions & 4 deletions executor/src/witgen/machines/fixed_lookup_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ impl<'a, T: FieldElement> FixedLookup<'a, T> {

fn process_plookup_internal<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &'b MutableState<'a, 'b, T, Q>,
mutable_state: &'b MutableState<'a, T, Q>,
identity_id: u64,
rows: &RowPair<'_, 'a, T>,
left: &[AffineExpression<AlgebraicVariable<'a>, T>],
Expand Down Expand Up @@ -329,7 +329,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for FixedLookup<'a, T> {

fn process_plookup<'b, Q: crate::witgen::QueryCallback<T>>(
&mut self,
mutable_state: &'b MutableState<'a, 'b, T, Q>,
mutable_state: &'b MutableState<'a, T, Q>,
identity_id: u64,
caller_rows: &'b RowPair<'b, 'a, T>,
) -> EvalResult<'a, T> {
Expand All @@ -355,7 +355,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for FixedLookup<'a, T> {

fn process_lookup_direct<'b, 'c, Q: QueryCallback<T>>(
&mut self,
_mutable_state: &'b MutableState<'a, 'b, T, Q>,
_mutable_state: &'b MutableState<'a, T, Q>,
identity_id: u64,
values: Vec<LookupCell<'c, T>>,
) -> Result<bool, EvalError<T>> {
Expand Down Expand Up @@ -421,7 +421,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for FixedLookup<'a, T> {

fn take_witness_col_values<'b, Q: QueryCallback<T>>(
&mut self,
_mutable_state: &'b MutableState<'a, 'b, T, Q>,
_mutable_state: &'b MutableState<'a, T, Q>,
) -> HashMap<String, Vec<T>> {
self.multiplicity_counter
.generate_columns_different_sizes()
Expand Down
12 changes: 6 additions & 6 deletions executor/src/witgen/machines/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub trait Machine<'a, T: FieldElement>: Send + Sync {
/// Like `process_plookup`, but also records the time spent in this machine.
fn process_plookup_timed<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &'b MutableState<'a, 'b, T, Q>,
mutable_state: &'b MutableState<'a, T, Q>,
identity_id: u64,
caller_rows: &'b RowPair<'b, 'a, T>,
) -> EvalResult<'a, T> {
Expand All @@ -56,7 +56,7 @@ pub trait Machine<'a, T: FieldElement>: Send + Sync {
/// Otherwise, it computes any updates to the caller row pair and returns them.
fn process_plookup<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &'b MutableState<'a, 'b, T, Q>,
mutable_state: &'b MutableState<'a, T, Q>,
identity_id: u64,
caller_rows: &'b RowPair<'b, 'a, T>,
) -> EvalResult<'a, T>;
Expand All @@ -73,7 +73,7 @@ pub trait Machine<'a, T: FieldElement>: Send + Sync {
/// An error is always unrecoverable.
fn process_lookup_direct<'b, 'c, Q: QueryCallback<T>>(
&mut self,
_mutable_state: &'b MutableState<'a, 'b, T, Q>,
_mutable_state: &'b MutableState<'a, T, Q>,
_identity_id: u64,
_values: Vec<LookupCell<'c, T>>,
) -> Result<bool, EvalError<T>> {
Expand All @@ -83,7 +83,7 @@ pub trait Machine<'a, T: FieldElement>: Send + Sync {
/// Returns the final values of the witness columns.
fn take_witness_col_values<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &'b MutableState<'a, 'b, T, Q>,
mutable_state: &'b MutableState<'a, T, Q>,
) -> HashMap<String, Vec<T>>;

/// Returns the identity IDs of the connecting identities that this machine is responsible for.
Expand Down Expand Up @@ -113,7 +113,7 @@ pub enum KnownMachine<'a, T: FieldElement> {
impl<'a, T: FieldElement> Machine<'a, T> for KnownMachine<'a, T> {
fn process_plookup<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &'b MutableState<'a, 'b, T, Q>,
mutable_state: &'b MutableState<'a, T, Q>,
identity_id: u64,
caller_rows: &'b RowPair<'b, 'a, T>,
) -> EvalResult<'a, T> {
Expand Down Expand Up @@ -154,7 +154,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for KnownMachine<'a, T> {

fn take_witness_col_values<'b, Q: QueryCallback<T>>(
&mut self,
mutable_state: &'b MutableState<'a, 'b, T, Q>,
mutable_state: &'b MutableState<'a, T, Q>,
) -> HashMap<String, Vec<T>> {
match self {
KnownMachine::SortedWitnesses(m) => m.take_witness_col_values(mutable_state),
Expand Down
4 changes: 2 additions & 2 deletions executor/src/witgen/machines/sorted_witness_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for SortedWitnesses<'a, T> {

fn process_plookup<Q: QueryCallback<T>>(
&mut self,
_mutable_state: &MutableState<'a, '_, T, Q>,
_mutable_state: &MutableState<'a, T, Q>,
identity_id: u64,
caller_rows: &RowPair<'_, 'a, T>,
) -> EvalResult<'a, T> {
Expand All @@ -212,7 +212,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for SortedWitnesses<'a, T> {

fn take_witness_col_values<'b, Q: QueryCallback<T>>(
&mut self,
_mutable_state: &'b MutableState<'a, 'b, T, Q>,
_mutable_state: &'b MutableState<'a, T, Q>,
) -> HashMap<String, Vec<T>> {
let mut result = HashMap::new();

Expand Down
4 changes: 2 additions & 2 deletions executor/src/witgen/machines/write_once_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for WriteOnceMemory<'a, T> {

fn process_plookup<'b, Q: QueryCallback<T>>(
&mut self,
_mutable_state: &'b MutableState<'a, 'b, T, Q>,
_mutable_state: &'b MutableState<'a, T, Q>,
identity_id: u64,
caller_rows: &RowPair<'_, 'a, T>,
) -> EvalResult<'a, T> {
Expand All @@ -246,7 +246,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for WriteOnceMemory<'a, T> {

fn take_witness_col_values<'b, Q: QueryCallback<T>>(
&mut self,
_mutable_state: &'b MutableState<'a, 'b, T, Q>,
_mutable_state: &'b MutableState<'a, T, Q>,
) -> HashMap<String, Vec<T>> {
self.value_polys
.iter()
Expand Down
14 changes: 5 additions & 9 deletions executor/src/witgen/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,16 @@ pub struct IdentityResult {
/// on any given row.
/// The lifetimes mean the following:
/// - `'a`: The duration of the entire witness generation (e.g. references to identities)
/// - `'b`: The duration of this machine's call (e.g. the mutable references of the other machines)
/// - `'c`: The duration of this Processor's lifetime (e.g. the reference to the identity processor)
pub struct Processor<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> {
pub struct Processor<'a, 'c, T: FieldElement, Q: QueryCallback<T>> {
/// The global index of the first row of [Processor::data].
row_offset: RowIndex,
/// The rows that are being processed.
data: FinalizableData<T>,
/// The values of the publics
publics: BTreeMap<&'a str, T>,
/// The mutable state
mutable_state: &'c MutableState<'a, 'b, T, Q>,
mutable_state: &'c MutableState<'a, T, Q>,
/// The fixed data (containing information about all columns)
fixed_data: &'a FixedData<'a, T>,
/// The machine parts (witness columns, identities, fixed data)
Expand All @@ -118,11 +117,11 @@ pub struct Processor<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> {
size: DegreeType,
}

impl<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> Processor<'a, 'b, 'c, T, Q> {
impl<'a, 'c, T: FieldElement, Q: QueryCallback<T>> Processor<'a, 'c, T, Q> {
pub fn new(
row_offset: RowIndex,
mutable_data: SolverState<'a, T>,
mutable_state: &'c MutableState<'a, 'b, T, Q>,
mutable_state: &'c MutableState<'a, T, Q>,
fixed_data: &'a FixedData<'a, T>,
parts: &'c MachineParts<'a, T>,
size: DegreeType,
Expand Down Expand Up @@ -159,10 +158,7 @@ impl<'a, 'b, 'c, T: FieldElement, Q: QueryCallback<T>> Processor<'a, 'b, 'c, T,
}
}

pub fn with_outer_query(
self,
outer_query: OuterQuery<'a, 'c, T>,
) -> Processor<'a, 'b, 'c, T, Q> {
pub fn with_outer_query(self, outer_query: OuterQuery<'a, 'c, T>) -> Processor<'a, 'c, T, Q> {
log::trace!(" Extracting inputs:");
let mut inputs = vec![];
for (l, r) in outer_query
Expand Down
Loading

0 comments on commit 1146653

Please sign in to comment.