mirror of https://github.com/zcash/halo2.git
dev: Introduce Cell helper struct to CircuitLayout internals
This commit is contained in:
parent
2633567840
commit
42ea7116a7
|
@ -54,6 +54,12 @@ pub struct CircuitCost<G: PrimeGroup, ConcreteCircuit: Circuit<G::Scalar>> {
|
||||||
_marker: PhantomData<(G, ConcreteCircuit)>,
|
_marker: PhantomData<(G, ConcreteCircuit)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub(crate) struct Cell {
|
||||||
|
pub(crate) column: RegionColumn,
|
||||||
|
pub(crate) row: usize,
|
||||||
|
}
|
||||||
|
|
||||||
/// Region implementation used by Layout
|
/// Region implementation used by Layout
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -66,8 +72,9 @@ pub(crate) struct LayoutRegion {
|
||||||
pub(crate) offset: Option<usize>,
|
pub(crate) offset: Option<usize>,
|
||||||
/// The number of rows that this region takes up.
|
/// The number of rows that this region takes up.
|
||||||
pub(crate) rows: usize,
|
pub(crate) rows: usize,
|
||||||
/// The cells assigned in this region.
|
/// The cells assigned in this region. We store this as a `Vec` to track multiple
|
||||||
pub(crate) cells: Vec<(RegionColumn, usize)>,
|
/// assignments to a cell.
|
||||||
|
pub(crate) cells: Vec<Cell>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cost and graphing layouter
|
/// Cost and graphing layouter
|
||||||
|
@ -84,10 +91,11 @@ pub(crate) struct Layout {
|
||||||
pub(crate) total_advice_rows: usize,
|
pub(crate) total_advice_rows: usize,
|
||||||
/// Total fixed rows
|
/// Total fixed rows
|
||||||
pub(crate) total_fixed_rows: usize,
|
pub(crate) total_fixed_rows: usize,
|
||||||
/// Any cells assigned outside of a region.
|
/// Any cells assigned outside of a region. We store this as a `Vec` to track multiple
|
||||||
pub(crate) loose_cells: Vec<(RegionColumn, usize)>,
|
/// assignments to a cell.
|
||||||
|
pub(crate) loose_cells: Vec<Cell>,
|
||||||
/// Pairs of cells between which we have equality constraints.
|
/// Pairs of cells between which we have equality constraints.
|
||||||
pub(crate) equality: Vec<(Column<Any>, usize, Column<Any>, usize)>,
|
pub(crate) equality: Vec<(Cell, Cell)>,
|
||||||
/// Selector assignments used for optimization pass
|
/// Selector assignments used for optimization pass
|
||||||
pub(crate) selectors: Vec<Vec<bool>>,
|
pub(crate) selectors: Vec<Vec<bool>>,
|
||||||
}
|
}
|
||||||
|
@ -139,9 +147,9 @@ impl Layout {
|
||||||
region.rows = cmp::max(region.rows, row - offset + 1);
|
region.rows = cmp::max(region.rows, row - offset + 1);
|
||||||
region.offset = Some(offset);
|
region.offset = Some(offset);
|
||||||
|
|
||||||
region.cells.push((column, row));
|
region.cells.push(Cell { column, row });
|
||||||
} else {
|
} else {
|
||||||
self.loose_cells.push((column, row));
|
self.loose_cells.push(Cell { column, row });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,7 +236,16 @@ impl<F: Field> Assignment<F> for Layout {
|
||||||
r_col: Column<Any>,
|
r_col: Column<Any>,
|
||||||
r_row: usize,
|
r_row: usize,
|
||||||
) -> Result<(), crate::plonk::Error> {
|
) -> Result<(), crate::plonk::Error> {
|
||||||
self.equality.push((l_col, l_row, r_col, r_row));
|
self.equality.push((
|
||||||
|
Cell {
|
||||||
|
column: l_col.into(),
|
||||||
|
row: l_row,
|
||||||
|
},
|
||||||
|
Cell {
|
||||||
|
column: r_col.into(),
|
||||||
|
row: r_row,
|
||||||
|
},
|
||||||
|
));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ use std::ops::Range;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
circuit::layouter::RegionColumn,
|
circuit::layouter::RegionColumn,
|
||||||
dev::cost::Layout,
|
dev::cost::{Cell, Layout},
|
||||||
plonk::{Any, Circuit, Column, ConstraintSystem, FloorPlanner},
|
plonk::{Any, Circuit, Column, ConstraintSystem, FloorPlanner},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -242,26 +242,26 @@ impl CircuitLayout {
|
||||||
|
|
||||||
// Darken the cells of the region that have been assigned to.
|
// Darken the cells of the region that have been assigned to.
|
||||||
for region in layout.regions {
|
for region in layout.regions {
|
||||||
for (column, row) in region.cells {
|
for Cell { column, row } in region.cells {
|
||||||
draw_cell(&root, column_index(&cs, column), row)?;
|
draw_cell(&root, column_index(&cs, column), row)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Darken any loose cells that have been assigned to.
|
// Darken any loose cells that have been assigned to.
|
||||||
for (column, row) in layout.loose_cells {
|
for Cell { column, row } in layout.loose_cells {
|
||||||
draw_cell(&root, column_index(&cs, column), row)?;
|
draw_cell(&root, column_index(&cs, column), row)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark equality-constrained cells.
|
// Mark equality-constrained cells.
|
||||||
if self.mark_equality_cells {
|
if self.mark_equality_cells {
|
||||||
let mut cells = HashSet::new();
|
let mut cells = HashSet::new();
|
||||||
for (l_col, l_row, r_col, r_row) in &layout.equality {
|
for (l, r) in &layout.equality {
|
||||||
let l_col = column_index(&cs, (*l_col).into());
|
let l_col = column_index(&cs, l.column);
|
||||||
let r_col = column_index(&cs, (*r_col).into());
|
let r_col = column_index(&cs, r.column);
|
||||||
|
|
||||||
// Deduplicate cells.
|
// Deduplicate cells.
|
||||||
cells.insert((l_col, *l_row));
|
cells.insert((l_col, l.row));
|
||||||
cells.insert((r_col, *r_row));
|
cells.insert((r_col, r.row));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (col, row) in cells {
|
for (col, row) in cells {
|
||||||
|
@ -274,11 +274,11 @@ impl CircuitLayout {
|
||||||
|
|
||||||
// Draw lines between equality-constrained cells.
|
// Draw lines between equality-constrained cells.
|
||||||
if self.show_equality_constraints {
|
if self.show_equality_constraints {
|
||||||
for (l_col, l_row, r_col, r_row) in &layout.equality {
|
for (l, r) in &layout.equality {
|
||||||
let l_col = column_index(&cs, (*l_col).into());
|
let l_col = column_index(&cs, l.column);
|
||||||
let r_col = column_index(&cs, (*r_col).into());
|
let r_col = column_index(&cs, r.column);
|
||||||
root.draw(&PathElement::new(
|
root.draw(&PathElement::new(
|
||||||
[(l_col, *l_row), (r_col, *r_row)],
|
[(l_col, l.row), (r_col, r.row)],
|
||||||
ShapeStyle::from(&RED),
|
ShapeStyle::from(&RED),
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue