Skip to content

Commit

Permalink
Simplify interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
chriseth committed Jan 22, 2025
1 parent deb1f6e commit 7af2db8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
21 changes: 9 additions & 12 deletions executor/src/witgen/jit/function_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use super::{
block_machine_processor::BlockMachineProcessor,
compiler::{compile_effects, WitgenFunction},
variable::Variable,
witgen_inference::CanProcessCall,
};

#[derive(Debug, Clone, Hash, PartialEq, Eq)]
Expand Down Expand Up @@ -58,42 +59,38 @@ impl<'a, T: FieldElement> FunctionCache<'a, T> {

/// Compiles the JIT function for the given identity and known arguments.
/// Returns true if the function was successfully compiled.
pub fn compile_cached<Q: QueryCallback<T>>(
pub fn compile_cached(
&mut self,
mutable_state: &MutableState<'a, T, Q>,
can_process: impl CanProcessCall<T> + Clone,
identity_id: u64,
known_args: &BitVec,
) -> &Option<WitgenFunction<T>> {
let cache_key = CacheKey {
identity_id,
known_args: known_args.clone(),
};
self.ensure_cache(mutable_state, &cache_key);
self.ensure_cache(can_process, &cache_key);
self.witgen_functions.get(&cache_key).unwrap()
}

fn ensure_cache<Q: QueryCallback<T>>(
&mut self,
mutable_state: &MutableState<'a, T, Q>,
cache_key: &CacheKey,
) {
fn ensure_cache(&mut self, can_process: impl CanProcessCall<T> + Clone, cache_key: &CacheKey) {
if self.witgen_functions.contains_key(cache_key) {
return;
}

let f = match T::known_field() {
// Currently, we only support the Goldilocks fields
Some(KnownField::GoldilocksField) => {
self.compile_witgen_function(mutable_state, cache_key)
self.compile_witgen_function(can_process, cache_key)
}
_ => None,
};
assert!(self.witgen_functions.insert(cache_key.clone(), f).is_none())
}

fn compile_witgen_function<Q: QueryCallback<T>>(
fn compile_witgen_function(
&self,
mutable_state: &MutableState<'a, T, Q>,
can_process: impl CanProcessCall<T> + Clone,
cache_key: &CacheKey,
) -> Option<WitgenFunction<T>> {
log::debug!(
Expand All @@ -104,7 +101,7 @@ impl<'a, T: FieldElement> FunctionCache<'a, T> {
);

self.processor
.generate_code(mutable_state, cache_key.identity_id, &cache_key.known_args)
.generate_code(can_process, cache_key.identity_id, &cache_key.known_args)
.map_err(|e| {
// These errors can be pretty verbose and are quite common currently.
let e = e.to_string().lines().take(5).join("\n");
Expand Down
2 changes: 2 additions & 0 deletions executor/src/witgen/machines/block_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ use crate::witgen::data_structures::finalizable_data::FinalizableData;
use crate::witgen::data_structures::mutable_state::MutableState;
use crate::witgen::jit::function_cache::FunctionCache;
use crate::witgen::processor::{OuterQuery, Processor, SolverState};
use crate::witgen::range_constraints::RangeConstraint;
use crate::witgen::rows::{Row, RowIndex, RowPair};
use crate::witgen::sequence_iterator::{
DefaultSequenceIterator, ProcessingSequenceCache, ProcessingSequenceIterator,
};
use crate::witgen::util::try_to_simple_poly;
use crate::witgen::{machines::Machine, EvalError, EvalValue, IncompleteCause, QueryCallback};
use bit_vec::BitVec;
use powdr_ast::analyzed::{DegreeRange, PolyID, PolynomialType};
use powdr_number::{DegreeType, FieldElement};

Expand Down

0 comments on commit 7af2db8

Please sign in to comment.