circuit::layouter::RegionColumn: Introduce TableTag variant

Co-authored-by: Avi Dessauer <avi.dessauer@platonic.systems>
This commit is contained in:
therealyingtong 2023-02-22 01:00:52 +08:00
parent 77b18df089
commit 78ea483f65
2 changed files with 22 additions and 2 deletions

View File

@ -8,6 +8,8 @@ use ff::Field;
pub use super::table_layouter::TableLayouter;
use super::{Cell, RegionIndex, Value};
#[cfg(feature = "unstable-dynamic-lookups")]
use crate::plonk::TableTag;
use crate::plonk::{Advice, Any, Assigned, Column, Error, Fixed, Instance, Selector};
/// Helper trait for implementing a custom [`Layouter`].
@ -15,7 +17,7 @@ use crate::plonk::{Advice, Any, Assigned, Column, Error, Fixed, Instance, Select
/// This trait is used for implementing region assignments:
///
/// ```ignore
/// impl<'a, F: FieldExt, C: Chip<F>, CS: Assignment<F> + 'a> Layouter<C> for MyLayouter<'a, C, CS> {
/// impl<'a, F: Field, C: Chip<F>, CS: Assignment<F> + 'a> Layouter<C> for MyLayouter<'a, C, CS> {
/// fn assign_region(
/// &mut self,
/// assignment: impl FnOnce(Region<'_, F, C>) -> Result<(), Error>,
@ -127,6 +129,9 @@ pub enum RegionColumn {
Column(Column<Any>),
/// Virtual column representing a (boolean) selector
Selector(Selector),
/// Virtual column used for storing dynamic table tags
#[cfg(feature = "unstable-dynamic-lookups")]
TableTag(TableTag),
}
impl From<Column<Any>> for RegionColumn {
@ -141,13 +146,26 @@ impl From<Selector> for RegionColumn {
}
}
#[cfg(feature = "unstable-dynamic-lookups")]
impl From<TableTag> for RegionColumn {
fn from(table_tag: TableTag) -> RegionColumn {
RegionColumn::TableTag(table_tag)
}
}
impl Ord for RegionColumn {
fn cmp(&self, other: &Self) -> cmp::Ordering {
match (self, other) {
(Self::Column(ref a), Self::Column(ref b)) => a.cmp(b),
(Self::Selector(ref a), Self::Selector(ref b)) => a.0.cmp(&b.0),
(Self::Column(_), Self::Selector(_)) => cmp::Ordering::Less,
#[cfg(feature = "unstable-dynamic-lookups")]
(Self::TableTag(ref a), Self::TableTag(ref b)) => a.0.cmp(&b.0),
(Self::Column(_), _) => cmp::Ordering::Less,
(Self::Selector(_), Self::Column(_)) => cmp::Ordering::Greater,
#[cfg(feature = "unstable-dynamic-lookups")]
(Self::TableTag(_), _) => cmp::Ordering::Greater,
#[cfg(feature = "unstable-dynamic-lookups")]
(_, Self::TableTag(_)) => cmp::Ordering::Less,
}
}
}

View File

@ -113,6 +113,8 @@ impl CircuitLayout {
let column: Column<Any> = match column {
RegionColumn::Column(col) => col,
RegionColumn::Selector(selector) => cs.selector_map[selector.0].into(),
#[cfg(feature = "unstable-dynamic-lookups")]
RegionColumn::TableTag(tag_col) => cs.dynamic_table_tag_map[tag_col.0].into(),
};
column.index()
+ match column.column_type() {