Add name field to Layouter::assign_region
This commit is contained in:
parent
4c3adf59d5
commit
60061f64fd
|
@ -146,12 +146,13 @@ pub trait Layouter<C: Chip> {
|
||||||
/// closure, the `Layouter` is allowed to optimise as it sees fit.
|
/// closure, the `Layouter` is allowed to optimise as it sees fit.
|
||||||
///
|
///
|
||||||
/// ```ignore
|
/// ```ignore
|
||||||
/// fn assign_region(&mut self, |region| {
|
/// fn assign_region(&mut self, || "region name", |region| {
|
||||||
/// region.assign_advice(self.config.a, offset, || { Some(value)});
|
/// region.assign_advice(self.config.a, offset, || { Some(value)});
|
||||||
/// });
|
/// });
|
||||||
/// ```
|
/// ```
|
||||||
fn assign_region(
|
fn assign_region<A, N, NR>(&mut self, name: N, assignment: A) -> Result<(), Error>
|
||||||
&mut self,
|
where
|
||||||
assignment: impl FnMut(Region<'_, C>) -> Result<(), Error>,
|
A: FnMut(Region<'_, C>) -> Result<(), Error>,
|
||||||
) -> Result<(), Error>;
|
N: Fn() -> NR,
|
||||||
|
NR: Into<String>;
|
||||||
}
|
}
|
||||||
|
|
|
@ -104,10 +104,12 @@ impl<'a, C: Chip, CS: Assignment<C::Field> + 'a> Layouter<C> for SingleChip<'a,
|
||||||
&self.config
|
&self.config
|
||||||
}
|
}
|
||||||
|
|
||||||
fn assign_region(
|
fn assign_region<A, N, NR>(&mut self, name: N, mut assignment: A) -> Result<(), Error>
|
||||||
&mut self,
|
where
|
||||||
mut assignment: impl FnMut(Region<'_, C>) -> Result<(), Error>,
|
A: FnMut(Region<'_, C>) -> Result<(), Error>,
|
||||||
) -> Result<(), Error> {
|
N: Fn() -> NR,
|
||||||
|
NR: Into<String>,
|
||||||
|
{
|
||||||
let region_index = self.regions.len();
|
let region_index = self.regions.len();
|
||||||
|
|
||||||
// Get shape of the region.
|
// Get shape of the region.
|
||||||
|
@ -130,11 +132,13 @@ impl<'a, C: Chip, CS: Assignment<C::Field> + 'a> Layouter<C> for SingleChip<'a,
|
||||||
self.columns.insert(column, region_start + shape.row_count);
|
self.columns.insert(column, region_start + shape.row_count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.cs.enter_region(name);
|
||||||
let mut region = SingleChipRegion::new(self, region_index);
|
let mut region = SingleChipRegion::new(self, region_index);
|
||||||
{
|
{
|
||||||
let region: &mut dyn RegionLayouter<C> = &mut region;
|
let region: &mut dyn RegionLayouter<C> = &mut region;
|
||||||
assignment(region.into())?;
|
assignment(region.into())?;
|
||||||
}
|
}
|
||||||
|
self.cs.exit_region();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,15 @@ pub struct MockProver<F: Group> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: Field + Group> Assignment<F> for MockProver<F> {
|
impl<F: Field + Group> Assignment<F> for MockProver<F> {
|
||||||
|
fn enter_region<NR, N>(&mut self, _: N)
|
||||||
|
where
|
||||||
|
NR: Into<String>,
|
||||||
|
N: FnOnce() -> NR,
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exit_region(&mut self) {}
|
||||||
|
|
||||||
fn assign_advice<V, A, AR>(
|
fn assign_advice<V, A, AR>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: A,
|
_: A,
|
||||||
|
|
|
@ -126,6 +126,27 @@ impl TryFrom<Column<Any>> for Column<Aux> {
|
||||||
/// This trait allows a [`Circuit`] to direct some backend to assign a witness
|
/// This trait allows a [`Circuit`] to direct some backend to assign a witness
|
||||||
/// for a constraint system.
|
/// for a constraint system.
|
||||||
pub trait Assignment<F: Field> {
|
pub trait Assignment<F: Field> {
|
||||||
|
/// Creates a new region and enters into it.
|
||||||
|
///
|
||||||
|
/// Panics if we are currently in a region (if `exit_region` was not called).
|
||||||
|
///
|
||||||
|
/// Not intended for downstream consumption; use [`Layouter::assign_region`] instead.
|
||||||
|
///
|
||||||
|
/// [`Layouter::assign_region`]: crate::circuit::Layouter#method.assign_region
|
||||||
|
fn enter_region<NR, N>(&mut self, name_fn: N)
|
||||||
|
where
|
||||||
|
NR: Into<String>,
|
||||||
|
N: FnOnce() -> NR;
|
||||||
|
|
||||||
|
/// Exits the current region.
|
||||||
|
///
|
||||||
|
/// Panics if we are not currently in a region (if `enter_region` was not called).
|
||||||
|
///
|
||||||
|
/// Not intended for downstream consumption; use [`Layouter::assign_region`] instead.
|
||||||
|
///
|
||||||
|
/// [`Layouter::assign_region`]: crate::circuit::Layouter#method.assign_region
|
||||||
|
fn exit_region(&mut self);
|
||||||
|
|
||||||
/// Assign an advice column value (witness)
|
/// Assign an advice column value (witness)
|
||||||
fn assign_advice<V, A, AR>(
|
fn assign_advice<V, A, AR>(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|
|
@ -64,6 +64,18 @@ struct Assembly<F: Field> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: Field> Assignment<F> for Assembly<F> {
|
impl<F: Field> Assignment<F> for Assembly<F> {
|
||||||
|
fn enter_region<NR, N>(&mut self, _: N)
|
||||||
|
where
|
||||||
|
NR: Into<String>,
|
||||||
|
N: FnOnce() -> NR,
|
||||||
|
{
|
||||||
|
// Do nothing; we don't care about regions in this context.
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exit_region(&mut self) {
|
||||||
|
// Do nothing; we don't care about regions in this context.
|
||||||
|
}
|
||||||
|
|
||||||
fn assign_advice<V, A, AR>(
|
fn assign_advice<V, A, AR>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: A,
|
_: A,
|
||||||
|
|
|
@ -100,6 +100,18 @@ pub fn create_proof<C: CurveAffine, T: TranscriptWrite<C>, ConcreteCircuit: Circ
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<F: Field> Assignment<F> for WitnessCollection<F> {
|
impl<F: Field> Assignment<F> for WitnessCollection<F> {
|
||||||
|
fn enter_region<NR, N>(&mut self, _: N)
|
||||||
|
where
|
||||||
|
NR: Into<String>,
|
||||||
|
N: FnOnce() -> NR,
|
||||||
|
{
|
||||||
|
// Do nothing; we don't care about regions in this context.
|
||||||
|
}
|
||||||
|
|
||||||
|
fn exit_region(&mut self) {
|
||||||
|
// Do nothing; we don't care about regions in this context.
|
||||||
|
}
|
||||||
|
|
||||||
fn assign_advice<V, A, AR>(
|
fn assign_advice<V, A, AR>(
|
||||||
&mut self,
|
&mut self,
|
||||||
_: A,
|
_: A,
|
||||||
|
|
Loading…
Reference in New Issue