1
0
Fork 0
mirror of synced 2025-09-23 04:08:33 +00:00
This commit is contained in:
dark64 2021-12-10 15:08:15 +01:00
parent 71c74e5962
commit 95a931c579
10 changed files with 29 additions and 38 deletions

View file

@ -74,7 +74,7 @@ fn cli_check<T: Field>(sub_matches: &ArgMatches) -> Result<(), String> {
format!( format!(
"{}:{}", "{}:{}",
file.strip_prefix(std::env::current_dir().unwrap()) file.strip_prefix(std::env::current_dir().unwrap())
.unwrap_or_else(|_| file.as_path()) .unwrap_or(file.as_path())
.display(), .display(),
e.value() e.value()
) )

View file

@ -90,7 +90,7 @@ fn cli_compile<T: Field>(sub_matches: &ArgMatches) -> Result<(), String> {
format!( format!(
"{}:{}", "{}:{}",
file.strip_prefix(std::env::current_dir().unwrap()) file.strip_prefix(std::env::current_dir().unwrap())
.unwrap_or_else(|_| file.as_path()) .unwrap_or(file.as_path())
.display(), .display(),
e.value() e.value()
) )

View file

@ -137,6 +137,7 @@ pub enum SymbolDefinition<'ast> {
Function(FunctionNode<'ast>), Function(FunctionNode<'ast>),
} }
#[allow(clippy::large_enum_variant)]
#[derive(Debug, PartialEq, Clone)] #[derive(Debug, PartialEq, Clone)]
pub enum Symbol<'ast> { pub enum Symbol<'ast> {
Here(SymbolDefinition<'ast>), Here(SymbolDefinition<'ast>),

View file

@ -257,8 +257,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Reducer<'ast, 'a, T> {
} }
Err(InlineError::Generic(decl, conc)) => Err(Error::Incompatible(format!( Err(InlineError::Generic(decl, conc)) => Err(Error::Incompatible(format!(
"Call site `{}` incompatible with declaration `{}`", "Call site `{}` incompatible with declaration `{}`",
conc.to_string(), conc, decl
decl.to_string()
))), ))),
Err(InlineError::NonConstant(key, generics, arguments, _)) => { Err(InlineError::NonConstant(key, generics, arguments, _)) => {
self.complete = false; self.complete = false;
@ -388,8 +387,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Reducer<'ast, 'a, T> {
} }
Err(InlineError::Generic(decl, conc)) => Err(Error::Incompatible(format!( Err(InlineError::Generic(decl, conc)) => Err(Error::Incompatible(format!(
"Call site `{}` incompatible with declaration `{}`", "Call site `{}` incompatible with declaration `{}`",
conc.to_string(), conc, decl
decl.to_string()
))), ))),
Err(InlineError::NonConstant(key, generics, arguments, output_types)) => { Err(InlineError::NonConstant(key, generics, arguments, output_types)) => {
self.complete = false; self.complete = false;
@ -442,8 +440,7 @@ impl<'ast, 'a, T: Field> ResultFolder<'ast, T> for Reducer<'ast, 'a, T> {
UExpression::from(index as u32).into(), UExpression::from(index as u32).into(),
)) ))
.chain(statements.clone().into_iter()) .chain(statements.clone().into_iter())
.map(|s| transformer.fold_statement(s)) .flat_map(|s| transformer.fold_statement(s))
.flatten()
.collect(); .collect();
out_statements.extend(statements); out_statements.extend(statements);

View file

@ -147,7 +147,7 @@ impl<'ast, T: Field> ResultFolder<'ast, T> for ZirPropagator<'ast, T> {
UExpressionInner::Value(v) => e UExpressionInner::Value(v) => e
.get(v as usize) .get(v as usize)
.cloned() .cloned()
.ok_or_else(|| Error::OutOfBounds(v, e.len() as u128)), .ok_or(Error::OutOfBounds(v, e.len() as u128)),
i => Ok(FieldElementExpression::Select( i => Ok(FieldElementExpression::Select(
e, e,
box i.annotate(UBitwidth::B32), box i.annotate(UBitwidth::B32),
@ -279,7 +279,7 @@ impl<'ast, T: Field> ResultFolder<'ast, T> for ZirPropagator<'ast, T> {
UExpressionInner::Value(v) => e UExpressionInner::Value(v) => e
.get(*v as usize) .get(*v as usize)
.cloned() .cloned()
.ok_or_else(|| Error::OutOfBounds(*v, e.len() as u128)), .ok_or(Error::OutOfBounds(*v, e.len() as u128)),
_ => Ok(BooleanExpression::Select(e, box index)), _ => Ok(BooleanExpression::Select(e, box index)),
} }
} }
@ -498,7 +498,7 @@ impl<'ast, T: Field> ResultFolder<'ast, T> for ZirPropagator<'ast, T> {
UExpressionInner::Value(v) => e UExpressionInner::Value(v) => e
.get(v as usize) .get(v as usize)
.cloned() .cloned()
.ok_or_else(|| Error::OutOfBounds(v, e.len() as u128)) .ok_or(Error::OutOfBounds(v, e.len() as u128))
.map(|e| e.into_inner()), .map(|e| e.into_inner()),
i => Ok(UExpressionInner::Select(e, box i.annotate(UBitwidth::B32))), i => Ok(UExpressionInner::Select(e, box i.annotate(UBitwidth::B32))),
} }

View file

@ -190,6 +190,7 @@ impl<'ast, T> TypedConstantSymbolDeclaration<'ast, T> {
} }
} }
#[allow(clippy::large_enum_variant)]
#[derive(PartialEq, Debug, Clone)] #[derive(PartialEq, Debug, Clone)]
pub enum TypedSymbolDeclaration<'ast, T> { pub enum TypedSymbolDeclaration<'ast, T> {
Function(TypedFunctionSymbolDeclaration<'ast, T>), Function(TypedFunctionSymbolDeclaration<'ast, T>),
@ -424,6 +425,7 @@ impl<'ast, T: Field> Typed<'ast, T> for TypedConstant<'ast, T> {
} }
/// Something we can assign to. /// Something we can assign to.
#[allow(clippy::large_enum_variant)]
#[derive(Clone, PartialEq, Debug, Hash, Eq, PartialOrd, Ord)] #[derive(Clone, PartialEq, Debug, Hash, Eq, PartialOrd, Ord)]
pub enum TypedAssignee<'ast, T> { pub enum TypedAssignee<'ast, T> {
Identifier(Variable<'ast, T>), Identifier(Variable<'ast, T>),
@ -1243,8 +1245,7 @@ impl<'ast, T: Clone> ArrayValue<'ast, T> {
) -> Option<U> { ) -> Option<U> {
self.0 self.0
.iter() .iter()
.map(|v| Self::expression_at_aux(v.clone())) .flat_map(|v| Self::expression_at_aux(v.clone()))
.flatten()
.take_while(|e| e.is_some()) .take_while(|e| e.is_some())
.map(|e| e.unwrap()) .map(|e| e.unwrap())
.nth(index) .nth(index)

View file

@ -344,17 +344,14 @@ impl<'ast, T> Iterator for ConjunctionIterator<BooleanExpression<'ast, T>> {
type Item = BooleanExpression<'ast, T>; type Item = BooleanExpression<'ast, T>;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.current self.current.pop().and_then(|n| match n {
.pop() BooleanExpression::And(box left, box right) => {
.map(|n| match n { self.current.push(left);
BooleanExpression::And(box left, box right) => { self.current.push(right);
self.current.push(left); self.next()
self.current.push(right); }
self.next() n => Some(n),
} })
n => Some(n),
})
.flatten()
} }
} }

View file

@ -144,17 +144,12 @@ pub fn generate_verify_constraints(
var_to_index(&vk.h_gamma_g2.y.c1, num_instance_variables), var_to_index(&vk.h_gamma_g2.y.c1, num_instance_variables),
]; ];
vk_indices.extend( vk_indices.extend(vk.query.iter().flat_map(|q| {
vk.query vec![
.iter() var_to_index(&q.x, num_instance_variables),
.map(|q| { var_to_index(&q.y, num_instance_variables),
vec![ ]
var_to_index(&q.x, num_instance_variables), }));
var_to_index(&q.y, num_instance_variables),
]
})
.flatten(),
);
let out_index = match &res { let out_index = match &res {
Boolean::Is(x) => x Boolean::Is(x) => x

View file

@ -705,7 +705,7 @@ mod ast {
#[derive(Debug, FromPest, PartialEq, Clone)] #[derive(Debug, FromPest, PartialEq, Clone)]
#[pest_ast(rule(Rule::assignee_access))] #[pest_ast(rule(Rule::assignee_access))]
pub enum AssigneeAccess<'ast> { pub enum AssigneeAccess<'ast> {
Select(ArrayAccess<'ast>), Select(Box<ArrayAccess<'ast>>),
Member(MemberAccess<'ast>), Member(MemberAccess<'ast>),
} }

View file

@ -28,9 +28,9 @@ fn write_test<W: Write>(test_file: &mut W, test_path: &Path, base_path: &Path) {
.unwrap() .unwrap()
.display() .display()
.to_string() .to_string()
.replace("/", "_") .replace('/', "_")
.replace(".json", "") .replace(".json", "")
.replace(".", "") .replace('.', "")
); );
write!( write!(