From 78ea483f650879d9a520237746faec26377794a3 Mon Sep 17 00:00:00 2001 From: therealyingtong Date: Wed, 22 Feb 2023 01:00:52 +0800 Subject: [PATCH] circuit::layouter::RegionColumn: Introduce TableTag variant Co-authored-by: Avi Dessauer --- halo2_proofs/src/circuit/layouter.rs | 22 ++++++++++++++++++++-- halo2_proofs/src/dev/graph/layout.rs | 2 ++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/halo2_proofs/src/circuit/layouter.rs b/halo2_proofs/src/circuit/layouter.rs index 81fa00be..3e3e87b0 100644 --- a/halo2_proofs/src/circuit/layouter.rs +++ b/halo2_proofs/src/circuit/layouter.rs @@ -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, CS: Assignment + 'a> Layouter for MyLayouter<'a, C, CS> { +/// impl<'a, F: Field, C: Chip, CS: Assignment + 'a> Layouter 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), /// 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> for RegionColumn { @@ -141,13 +146,26 @@ impl From for RegionColumn { } } +#[cfg(feature = "unstable-dynamic-lookups")] +impl From 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, } } } diff --git a/halo2_proofs/src/dev/graph/layout.rs b/halo2_proofs/src/dev/graph/layout.rs index 965e0683..90979aa4 100644 --- a/halo2_proofs/src/dev/graph/layout.rs +++ b/halo2_proofs/src/dev/graph/layout.rs @@ -113,6 +113,8 @@ impl CircuitLayout { let column: Column = 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() {