PR feedback

This commit is contained in:
wborgeaud 2022-02-16 09:26:16 +01:00
parent 08e255a2bb
commit f8dfc3986b
2 changed files with 15 additions and 21 deletions

View File

@ -124,6 +124,8 @@ pub trait Gate<F: RichField + Extendable<D>, const D: usize>: 'static + Send + S
}
}
/// The generators used to populate the witness.
/// Note: This should return exactly 1 generator per operation in the gate.
fn generators(
&self,
gate_index: usize,
@ -179,7 +181,9 @@ impl<F: RichField + Extendable<D>, const D: usize> Debug for GateRef<F, D> {
}
/// Map between gate parameters and available slots.
#[derive(Clone, Debug)]
/// An available slot is of the form `(gate_index, op)`, meaning the current available slot
/// is at gate index `gate_index` in the `op`-th operation.
#[derive(Clone, Debug, Default)]
pub struct CurrentSlot<F: RichField + Extendable<D>, const D: usize> {
pub current_slot: HashMap<Vec<F>, (usize, usize)>,
}

View File

@ -391,7 +391,9 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
})
}
/// Find an available slot, of the form `(gate_index, op)` for gate `G`.
/// Find an available slot, of the form `(gate_index, op)` for gate `G` using parameters `params`
/// and constants `constants`. Parameters are any data used to differentiate which gate should be
/// used for the given operation.
pub fn find_slot<G: Gate<F, D> + Clone>(
&mut self,
gate: G,
@ -401,36 +403,24 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
let num_gates = self.num_gates();
let num_ops = gate.num_ops();
let gate_ref = GateRef::new(gate.clone());
let gate_slot = self
.current_slots
.entry(gate_ref.clone())
.or_insert(CurrentSlot {
current_slot: HashMap::new(),
});
let gate_slot = self.current_slots.entry(gate_ref.clone()).or_default();
let slot = gate_slot.current_slot.get(params);
let res = if let Some(&s) = slot {
let (gate_idx, slot_idx) = if let Some(&s) = slot {
s
} else {
self.add_gate(gate, constants.to_vec());
(num_gates, 0)
};
if res.1 == num_ops - 1 {
let current_slot = &mut self.current_slots.get_mut(&gate_ref).unwrap().current_slot;
if slot_idx == num_ops - 1 {
// We've filled up the slots at this index.
self.current_slots
.get_mut(&gate_ref)
.unwrap()
.current_slot
.remove(params);
current_slot.remove(params);
} else {
// Increment the slot operation index.
self.current_slots
.get_mut(&gate_ref)
.unwrap()
.current_slot
.insert(params.to_vec(), (res.0, res.1 + 1));
current_slot.insert(params.to_vec(), (gate_idx, slot_idx + 1));
}
res
(gate_idx, slot_idx)
}
fn fri_params(&self, degree_bits: usize) -> FriParams {