forked from zcash/halo2
-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow halo2 constraint names to have non static names #156
Merged
han0110
merged 6 commits into
privacy-scaling-explorations:main
from
CeciliaZ030:65-allow-halo2-constraint-names-to-have-non-static-names
Apr 20, 2023
Merged
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b67f1a
static ref to String type in Gates, Constraints, VirtualCell, Argument
CeciliaZ030 094725f
'lookup'.to_string()
CeciliaZ030 1029488
return &str for gate name and constriant_name, also run fmt
CeciliaZ030 bbbb844
Update halo2_gadgets/Cargo.toml
CPerezz 90dc357
upgrade rust-toochain
CeciliaZ030 dcc8d74
merged with fcdd5b91
CeciliaZ030 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1213,25 +1213,25 @@ impl<Col: Into<Column<Any>>> From<(Col, Rotation)> for VirtualCell { | |||||||||
/// These are returned by the closures passed to `ConstraintSystem::create_gate`. | ||||||||||
#[derive(Debug)] | ||||||||||
pub struct Constraint<F: Field> { | ||||||||||
name: &'static str, | ||||||||||
name: String, | ||||||||||
poly: Expression<F>, | ||||||||||
} | ||||||||||
|
||||||||||
impl<F: Field> From<Expression<F>> for Constraint<F> { | ||||||||||
fn from(poly: Expression<F>) -> Self { | ||||||||||
Constraint { name: "", poly } | ||||||||||
Constraint { name: "".to_string(), poly } | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
impl<F: Field> From<(&'static str, Expression<F>)> for Constraint<F> { | ||||||||||
fn from((name, poly): (&'static str, Expression<F>)) -> Self { | ||||||||||
Constraint { name, poly } | ||||||||||
impl<F: Field, S: AsRef<str>> From<(S, Expression<F>)> for Constraint<F> { | ||||||||||
fn from((name, poly): (S, Expression<F>)) -> Self { | ||||||||||
Constraint { name: name.as_ref().to_string(), poly } | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
impl<F: Field> From<Expression<F>> for Vec<Constraint<F>> { | ||||||||||
fn from(poly: Expression<F>) -> Self { | ||||||||||
vec![Constraint { name: "", poly }] | ||||||||||
vec![Constraint { name: "".to_string(), poly }] | ||||||||||
} | ||||||||||
} | ||||||||||
|
||||||||||
|
@@ -1321,8 +1321,8 @@ impl<F: Field, C: Into<Constraint<F>>, Iter: IntoIterator<Item = C>> IntoIterato | |||||||||
/// Gate | ||||||||||
#[derive(Clone, Debug)] | ||||||||||
pub struct Gate<F: Field> { | ||||||||||
name: &'static str, | ||||||||||
constraint_names: Vec<&'static str>, | ||||||||||
name: String, | ||||||||||
constraint_names: Vec<String>, | ||||||||||
polys: Vec<Expression<F>>, | ||||||||||
/// We track queried selectors separately from other cells, so that we can use them to | ||||||||||
/// trigger debug checks on gates. | ||||||||||
|
@@ -1331,12 +1331,12 @@ pub struct Gate<F: Field> { | |||||||||
} | ||||||||||
|
||||||||||
impl<F: Field> Gate<F> { | ||||||||||
pub(crate) fn name(&self) -> &'static str { | ||||||||||
self.name | ||||||||||
pub(crate) fn name(&self) -> String { | ||||||||||
self.name.clone() | ||||||||||
} | ||||||||||
|
||||||||||
pub(crate) fn constraint_name(&self, constraint_index: usize) -> &'static str { | ||||||||||
self.constraint_names[constraint_index] | ||||||||||
pub(crate) fn constraint_name(&self, constraint_index: usize) -> String { | ||||||||||
self.constraint_names[constraint_index].clone() | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
} | ||||||||||
|
||||||||||
/// Returns constraints of this gate | ||||||||||
|
@@ -1529,9 +1529,9 @@ impl<F: Field> ConstraintSystem<F> { | |||||||||
/// | ||||||||||
/// `table_map` returns a map between input expressions and the table columns | ||||||||||
/// they need to match. | ||||||||||
pub fn lookup( | ||||||||||
pub fn lookup<S: AsRef<str>>( | ||||||||||
&mut self, | ||||||||||
name: &'static str, | ||||||||||
name: S, | ||||||||||
table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression<F>, TableColumn)>, | ||||||||||
) -> usize { | ||||||||||
let mut cells = VirtualCells::new(self); | ||||||||||
|
@@ -1550,7 +1550,7 @@ impl<F: Field> ConstraintSystem<F> { | |||||||||
|
||||||||||
let index = self.lookups.len(); | ||||||||||
|
||||||||||
self.lookups.push(lookup::Argument::new(name, table_map)); | ||||||||||
self.lookups.push(lookup::Argument::new(name.as_ref(), table_map)); | ||||||||||
|
||||||||||
index | ||||||||||
} | ||||||||||
|
@@ -1559,17 +1559,17 @@ impl<F: Field> ConstraintSystem<F> { | |||||||||
/// | ||||||||||
/// `table_map` returns a map between input expressions and the table expressions | ||||||||||
/// they need to match. | ||||||||||
pub fn lookup_any( | ||||||||||
pub fn lookup_any<S: AsRef<str>>( | ||||||||||
&mut self, | ||||||||||
name: &'static str, | ||||||||||
name: S, | ||||||||||
table_map: impl FnOnce(&mut VirtualCells<'_, F>) -> Vec<(Expression<F>, Expression<F>)>, | ||||||||||
) -> usize { | ||||||||||
let mut cells = VirtualCells::new(self); | ||||||||||
let table_map = table_map(&mut cells); | ||||||||||
|
||||||||||
let index = self.lookups.len(); | ||||||||||
|
||||||||||
self.lookups.push(lookup::Argument::new(name, table_map)); | ||||||||||
self.lookups.push(lookup::Argument::new(name.as_ref(), table_map)); | ||||||||||
|
||||||||||
index | ||||||||||
} | ||||||||||
|
@@ -1689,9 +1689,9 @@ impl<F: Field> ConstraintSystem<F> { | |||||||||
/// | ||||||||||
/// A gate is required to contain polynomial constraints. This method will panic if | ||||||||||
/// `constraints` returns an empty iterator. | ||||||||||
pub fn create_gate<C: Into<Constraint<F>>, Iter: IntoIterator<Item = C>>( | ||||||||||
pub fn create_gate<C: Into<Constraint<F>>, Iter: IntoIterator<Item = C>, S: AsRef<str>>( | ||||||||||
&mut self, | ||||||||||
name: &'static str, | ||||||||||
name: S, | ||||||||||
constraints: impl FnOnce(&mut VirtualCells<'_, F>) -> Iter, | ||||||||||
) { | ||||||||||
let mut cells = VirtualCells::new(self); | ||||||||||
|
@@ -1711,7 +1711,7 @@ impl<F: Field> ConstraintSystem<F> { | |||||||||
); | ||||||||||
|
||||||||||
self.gates.push(Gate { | ||||||||||
name, | ||||||||||
name: name.as_ref().to_string(), | ||||||||||
constraint_names, | ||||||||||
polys, | ||||||||||
queried_selectors, | ||||||||||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the name will be cloned twice when calling
(gate_index, gate.name()).into()
tometadata::Gate
, not sure if it'd be optimized out, but I think it'd be nice to have the code look no extra clone (and more consistent since other APIs returns also reference).