mirror of
https://github.com/powdr-labs/powdr.git
synced 2026-01-09 14:48:16 -05:00
Implement process_lookup_direct for KnownMachine & change interface slightly (#2206)
Extracted out of #2071
This commit is contained in:
@@ -220,7 +220,7 @@ impl<'a, T: FieldElement> FixedLookup<'a, T> {
|
||||
|
||||
// Split the left-hand-side into known input values and unknown output expressions.
|
||||
let mut data = vec![T::zero(); left.len()];
|
||||
let values = left
|
||||
let mut values = left
|
||||
.iter()
|
||||
.zip(&mut data)
|
||||
.map(|(l, d)| {
|
||||
@@ -233,7 +233,7 @@ impl<'a, T: FieldElement> FixedLookup<'a, T> {
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if !self.process_lookup_direct(mutable_state, identity_id, values)? {
|
||||
if !self.process_lookup_direct(mutable_state, identity_id, &mut values)? {
|
||||
// multiple matches, we stop and learnt nothing
|
||||
return Ok(EvalValue::incomplete(
|
||||
IncompleteCause::MultipleLookupMatches,
|
||||
@@ -357,7 +357,7 @@ impl<'a, T: FieldElement> Machine<'a, T> for FixedLookup<'a, T> {
|
||||
&mut self,
|
||||
_mutable_state: &'b MutableState<'a, T, Q>,
|
||||
identity_id: u64,
|
||||
values: Vec<LookupCell<'c, T>>,
|
||||
values: &mut [LookupCell<'c, T>],
|
||||
) -> Result<bool, EvalError<T>> {
|
||||
let mut input_values = vec![];
|
||||
|
||||
@@ -407,14 +407,14 @@ impl<'a, T: FieldElement> Machine<'a, T> for FixedLookup<'a, T> {
|
||||
self.multiplicity_counter.increment_at_row(identity_id, row);
|
||||
|
||||
values
|
||||
.into_iter()
|
||||
.iter_mut()
|
||||
.filter_map(|v| match v {
|
||||
LookupCell::Output(e) => Some(e),
|
||||
_ => None,
|
||||
})
|
||||
.zip(output)
|
||||
.for_each(|(e, v)| {
|
||||
*e = *v;
|
||||
**e = *v;
|
||||
});
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
@@ -93,9 +93,9 @@ pub trait Machine<'a, T: FieldElement>: Send + Sync {
|
||||
&mut self,
|
||||
_mutable_state: &'b MutableState<'a, T, Q>,
|
||||
_identity_id: u64,
|
||||
_values: Vec<LookupCell<'c, T>>,
|
||||
_values: &mut [LookupCell<'c, T>],
|
||||
) -> Result<bool, EvalError<T>> {
|
||||
unimplemented!("Direct lookup is not supported for this machine.");
|
||||
unimplemented!("Direct lookup not supported machine {}.", self.name())
|
||||
}
|
||||
|
||||
/// Returns the final values of the witness columns.
|
||||
@@ -177,6 +177,40 @@ impl<'a, T: FieldElement> Machine<'a, T> for KnownMachine<'a, T> {
|
||||
}
|
||||
}
|
||||
|
||||
fn process_lookup_direct<'b, 'c, Q: QueryCallback<T>>(
|
||||
&mut self,
|
||||
mutable_state: &'b MutableState<'a, T, Q>,
|
||||
identity_id: u64,
|
||||
values: &mut [LookupCell<'c, T>],
|
||||
) -> Result<bool, EvalError<T>> {
|
||||
match self {
|
||||
KnownMachine::SecondStageMachine(m) => {
|
||||
m.process_lookup_direct(mutable_state, identity_id, values)
|
||||
}
|
||||
KnownMachine::SortedWitnesses(m) => {
|
||||
m.process_lookup_direct(mutable_state, identity_id, values)
|
||||
}
|
||||
KnownMachine::DoubleSortedWitnesses16(m) => {
|
||||
m.process_lookup_direct(mutable_state, identity_id, values)
|
||||
}
|
||||
KnownMachine::DoubleSortedWitnesses32(m) => {
|
||||
m.process_lookup_direct(mutable_state, identity_id, values)
|
||||
}
|
||||
KnownMachine::WriteOnceMemory(m) => {
|
||||
m.process_lookup_direct(mutable_state, identity_id, values)
|
||||
}
|
||||
KnownMachine::BlockMachine(m) => {
|
||||
m.process_lookup_direct(mutable_state, identity_id, values)
|
||||
}
|
||||
KnownMachine::DynamicMachine(m) => {
|
||||
m.process_lookup_direct(mutable_state, identity_id, values)
|
||||
}
|
||||
KnownMachine::FixedLookup(m) => {
|
||||
m.process_lookup_direct(mutable_state, identity_id, values)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn name(&self) -> &str {
|
||||
match self {
|
||||
KnownMachine::SecondStageMachine(m) => m.name(),
|
||||
|
||||
Reference in New Issue
Block a user