automatic clippy fixes
This commit is contained in:
parent
ce1079d890
commit
bfcc13c932
28 changed files with 230 additions and 287 deletions
|
@ -247,9 +247,9 @@ impl<T: Field> TryFrom<serde_json::Value> for Values<T> {
|
|||
match v {
|
||||
serde_json::Value::Array(a) => a
|
||||
.into_iter()
|
||||
.map(|v| Value::try_from(v))
|
||||
.map(Value::try_from)
|
||||
.collect::<Result<_, _>>()
|
||||
.map(|v| Values(v)),
|
||||
.map(Values),
|
||||
v => Err(format!("Expected an array of values, found `{}`", v)),
|
||||
}
|
||||
}
|
||||
|
@ -259,20 +259,22 @@ impl<T: Field> TryFrom<serde_json::Value> for Value<T> {
|
|||
type Error = String;
|
||||
fn try_from(v: serde_json::Value) -> Result<Value<T>, Self::Error> {
|
||||
match v {
|
||||
serde_json::Value::String(s) => T::try_from_dec_str(&s)
|
||||
.map(|v| Value::Field(v))
|
||||
.or_else(|_| match s.len() {
|
||||
4 => u8::from_str_radix(&s[2..], 16)
|
||||
.map(|v| Value::U8(v))
|
||||
.map_err(|_| format!("Expected u8 value, found {}", s)),
|
||||
6 => u16::from_str_radix(&s[2..], 16)
|
||||
.map(|v| Value::U16(v))
|
||||
.map_err(|_| format!("Expected u16 value, found {}", s)),
|
||||
10 => u32::from_str_radix(&s[2..], 16)
|
||||
.map(|v| Value::U32(v))
|
||||
.map_err(|_| format!("Expected u32 value, found {}", s)),
|
||||
_ => Err(format!("Cannot parse {} to any type", s)),
|
||||
}),
|
||||
serde_json::Value::String(s) => {
|
||||
T::try_from_dec_str(&s)
|
||||
.map(Value::Field)
|
||||
.or_else(|_| match s.len() {
|
||||
4 => u8::from_str_radix(&s[2..], 16)
|
||||
.map(Value::U8)
|
||||
.map_err(|_| format!("Expected u8 value, found {}", s)),
|
||||
6 => u16::from_str_radix(&s[2..], 16)
|
||||
.map(Value::U16)
|
||||
.map_err(|_| format!("Expected u16 value, found {}", s)),
|
||||
10 => u32::from_str_radix(&s[2..], 16)
|
||||
.map(Value::U32)
|
||||
.map_err(|_| format!("Expected u32 value, found {}", s)),
|
||||
_ => Err(format!("Cannot parse {} to any type", s)),
|
||||
})
|
||||
}
|
||||
serde_json::Value::Bool(b) => Ok(Value::Boolean(b)),
|
||||
serde_json::Value::Number(n) => Err(format!(
|
||||
"Value `{}` isn't allowed, did you mean `\"{}\"`?",
|
||||
|
@ -280,14 +282,14 @@ impl<T: Field> TryFrom<serde_json::Value> for Value<T> {
|
|||
)),
|
||||
serde_json::Value::Array(a) => a
|
||||
.into_iter()
|
||||
.map(|v| Value::try_from(v))
|
||||
.map(Value::try_from)
|
||||
.collect::<Result<_, _>>()
|
||||
.map(|v| Value::Array(v)),
|
||||
.map(Value::Array),
|
||||
serde_json::Value::Object(o) => o
|
||||
.into_iter()
|
||||
.map(|(k, v)| Value::try_from(v).map(|v| (k, v)))
|
||||
.collect::<Result<Map<_, _>, _>>()
|
||||
.map(|v| Value::Struct(v)),
|
||||
.map(Value::Struct),
|
||||
v => Err(format!("Value `{}` isn't allowed", v)),
|
||||
}
|
||||
}
|
||||
|
@ -320,7 +322,7 @@ impl<T: Field> Into<serde_json::Value> for CheckedValues<T> {
|
|||
fn parse<T: Field>(s: &str) -> Result<Values<T>, Error> {
|
||||
let json_values: serde_json::Value =
|
||||
serde_json::from_str(s).map_err(|e| Error::Json(e.to_string()))?;
|
||||
Values::try_from(json_values).map_err(|e| Error::Conversion(e))
|
||||
Values::try_from(json_values).map_err(Error::Conversion)
|
||||
}
|
||||
|
||||
pub fn parse_strict<T: Field>(s: &str, types: Vec<Type>) -> Result<CheckedValues<T>, Error> {
|
||||
|
@ -338,7 +340,7 @@ pub fn parse_strict<T: Field>(s: &str, types: Vec<Type>) -> Result<CheckedValues
|
|||
.zip(types.into_iter())
|
||||
.map(|(v, ty)| v.check(ty))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(|e| Error::Type(e))?;
|
||||
.map_err(Error::Type)?;
|
||||
Ok(CheckedValues(checked))
|
||||
}
|
||||
|
||||
|
|
|
@ -11,5 +11,5 @@ fn export_stdlib() {
|
|||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let mut options = CopyOptions::new();
|
||||
options.overwrite = true;
|
||||
copy_items(&vec!["tests/contract"], out_dir, &options).unwrap();
|
||||
copy_items(&["tests/contract"], out_dir, &options).unwrap();
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ fn cli_generate_proof<T: Field, S: Scheme<T>, B: Backend<T, S>>(
|
|||
.write(proof.as_bytes())
|
||||
.map_err(|why| format!("Couldn't write to {}: {}", proof_path.display(), why))?;
|
||||
|
||||
println!("Proof:\n{}", format!("{}", proof));
|
||||
println!("Proof:\n{}", proof);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -208,7 +208,7 @@ fn cli_compute<T: Field>(ir_prog: ir::Prog<T>, sub_matches: &ArgMatches) -> Resu
|
|||
.collect::<Result<Vec<_>, _>>()
|
||||
})
|
||||
.unwrap_or(Ok(vec![]))
|
||||
.map(|v| Inputs::Raw(v))
|
||||
.map(Inputs::Raw)
|
||||
}
|
||||
// take stdin arguments
|
||||
true => {
|
||||
|
@ -221,7 +221,7 @@ fn cli_compute<T: Field>(ir_prog: ir::Prog<T>, sub_matches: &ArgMatches) -> Resu
|
|||
use zokrates_abi::parse_strict;
|
||||
|
||||
parse_strict(&input, signature.inputs)
|
||||
.map(|parsed| Inputs::Abi(parsed))
|
||||
.map(Inputs::Abi)
|
||||
.map_err(|why| why.to_string())
|
||||
}
|
||||
Err(_) => Err(String::from("???")),
|
||||
|
@ -232,10 +232,10 @@ fn cli_compute<T: Field>(ir_prog: ir::Prog<T>, sub_matches: &ArgMatches) -> Resu
|
|||
Ok(_) => {
|
||||
input.retain(|x| x != '\n');
|
||||
input
|
||||
.split(" ")
|
||||
.split(' ')
|
||||
.map(|x| T::try_from_dec_str(x).map_err(|_| x.to_string()))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map(|v| Inputs::Raw(v))
|
||||
.map(Inputs::Raw)
|
||||
}
|
||||
Err(_) => Err(String::from("???")),
|
||||
},
|
||||
|
|
|
@ -9,27 +9,21 @@ pub const BACKENDS: &[&str] = if cfg!(feature = "libsnark") {
|
|||
} else {
|
||||
&[LIBSNARK, ARK]
|
||||
}
|
||||
} else if cfg!(feature = "bellman") {
|
||||
&[BELLMAN, LIBSNARK]
|
||||
} else {
|
||||
if cfg!(feature = "bellman") {
|
||||
&[BELLMAN, LIBSNARK]
|
||||
} else {
|
||||
&[LIBSNARK]
|
||||
}
|
||||
&[LIBSNARK]
|
||||
}
|
||||
} else if cfg!(feature = "ark") {
|
||||
if cfg!(feature = "bellman") {
|
||||
&[BELLMAN, ARK]
|
||||
} else {
|
||||
&[ARK]
|
||||
}
|
||||
} else if cfg!(feature = "bellman") {
|
||||
&[BELLMAN]
|
||||
} else {
|
||||
if cfg!(feature = "ark") {
|
||||
if cfg!(feature = "bellman") {
|
||||
&[BELLMAN, ARK]
|
||||
} else {
|
||||
&[ARK]
|
||||
}
|
||||
} else {
|
||||
if cfg!(feature = "bellman") {
|
||||
&[BELLMAN]
|
||||
} else {
|
||||
&[]
|
||||
}
|
||||
}
|
||||
&[]
|
||||
};
|
||||
|
||||
pub const BN128: &str = "bn128";
|
||||
|
|
|
@ -3,7 +3,7 @@ extern crate serde_json;
|
|||
|
||||
#[cfg(test)]
|
||||
mod integration {
|
||||
use assert_cli;
|
||||
|
||||
use serde_json::from_reader;
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
|
@ -147,11 +147,11 @@ mod integration {
|
|||
.map_err(|why| why.to_string())
|
||||
.unwrap();
|
||||
|
||||
let signature = abi.signature().clone();
|
||||
let signature = abi.signature();
|
||||
|
||||
let inputs_abi: zokrates_abi::Inputs<zokrates_field::Bn128Field> =
|
||||
parse_strict(&json_input_str, signature.inputs)
|
||||
.map(|parsed| zokrates_abi::Inputs::Abi(parsed))
|
||||
.map(zokrates_abi::Inputs::Abi)
|
||||
.map_err(|why| why.to_string())
|
||||
.unwrap();
|
||||
let inputs_raw: Vec<_> = inputs_abi
|
||||
|
@ -169,7 +169,7 @@ mod integration {
|
|||
inline_witness_path.to_str().unwrap(),
|
||||
];
|
||||
|
||||
if inputs_raw.len() > 0 {
|
||||
if !inputs_raw.is_empty() {
|
||||
compute_inline.push("-a");
|
||||
|
||||
for arg in &inputs_raw {
|
||||
|
@ -202,7 +202,7 @@ mod integration {
|
|||
|
||||
assert_eq!(inline_witness, witness);
|
||||
|
||||
for line in expected_witness.as_str().split("\n") {
|
||||
for line in expected_witness.as_str().split('\n') {
|
||||
assert!(
|
||||
witness.contains(line),
|
||||
"Witness generation failed for {}\n\nLine \"{}\" not found in witness",
|
||||
|
|
|
@ -10,14 +10,14 @@ impl<'ast> From<pest::File<'ast>> for absy::Module<'ast> {
|
|||
absy::Module::with_symbols(
|
||||
prog.structs
|
||||
.into_iter()
|
||||
.map(|t| absy::SymbolDeclarationNode::from(t))
|
||||
.map(absy::SymbolDeclarationNode::from)
|
||||
.chain(
|
||||
prog.functions
|
||||
.into_iter()
|
||||
.map(|f| absy::SymbolDeclarationNode::from(f)),
|
||||
.map(absy::SymbolDeclarationNode::from),
|
||||
),
|
||||
)
|
||||
.imports(prog.imports.into_iter().map(|i| absy::ImportNode::from(i)))
|
||||
.imports(prog.imports.into_iter().map(absy::ImportNode::from))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ impl<'ast> From<pest::StructDefinition<'ast>> for absy::SymbolDeclarationNode<'a
|
|||
fields: definition
|
||||
.fields
|
||||
.into_iter()
|
||||
.map(|f| absy::StructDefinitionFieldNode::from(f))
|
||||
.map(absy::StructDefinitionFieldNode::from)
|
||||
.collect(),
|
||||
}
|
||||
.span(span.clone());
|
||||
|
@ -105,7 +105,7 @@ impl<'ast> From<pest::Function<'ast>> for absy::SymbolDeclarationNode<'ast> {
|
|||
.returns
|
||||
.clone()
|
||||
.into_iter()
|
||||
.map(|r| absy::UnresolvedTypeNode::from(r))
|
||||
.map(absy::UnresolvedTypeNode::from)
|
||||
.collect(),
|
||||
);
|
||||
|
||||
|
@ -115,12 +115,12 @@ impl<'ast> From<pest::Function<'ast>> for absy::SymbolDeclarationNode<'ast> {
|
|||
arguments: function
|
||||
.parameters
|
||||
.into_iter()
|
||||
.map(|a| absy::ParameterNode::from(a))
|
||||
.map(absy::ParameterNode::from)
|
||||
.collect(),
|
||||
statements: function
|
||||
.statements
|
||||
.into_iter()
|
||||
.flat_map(|s| statements_from_statement(s))
|
||||
.flat_map(statements_from_statement)
|
||||
.collect(),
|
||||
signature,
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ impl<'ast> From<pest::ReturnStatement<'ast>> for absy::StatementNode<'ast> {
|
|||
expressions: statement
|
||||
.expressions
|
||||
.into_iter()
|
||||
.map(|e| absy::ExpressionNode::from(e))
|
||||
.map(absy::ExpressionNode::from)
|
||||
.collect(),
|
||||
}
|
||||
.span(statement.span.clone()),
|
||||
|
@ -275,7 +275,7 @@ impl<'ast> From<pest::IterationStatement<'ast>> for absy::StatementNode<'ast> {
|
|||
let statements: Vec<absy::StatementNode<'ast>> = statement
|
||||
.statements
|
||||
.into_iter()
|
||||
.flat_map(|s| statements_from_statement(s))
|
||||
.flat_map(statements_from_statement)
|
||||
.collect();
|
||||
|
||||
let var = absy::Variable::new(index, ty).span(statement.index.span);
|
||||
|
@ -458,7 +458,7 @@ impl<'ast> From<pest::InlineArrayExpression<'ast>> for absy::ExpressionNode<'ast
|
|||
array
|
||||
.expressions
|
||||
.into_iter()
|
||||
.map(|e| absy::SpreadOrExpression::from(e))
|
||||
.map(absy::SpreadOrExpression::from)
|
||||
.collect(),
|
||||
)
|
||||
.span(array.span)
|
||||
|
@ -529,7 +529,7 @@ impl<'ast> From<pest::PostfixExpression<'ast>> for absy::ExpressionNode<'ast> {
|
|||
&id_str,
|
||||
a.expressions
|
||||
.into_iter()
|
||||
.map(|e| absy::ExpressionNode::from(e))
|
||||
.map(absy::ExpressionNode::from)
|
||||
.collect(),
|
||||
),
|
||||
e => unimplemented!("only identifiers are callable, found \"{}\"", e),
|
||||
|
@ -891,15 +891,14 @@ mod tests {
|
|||
// we basically accept `()?[]*` : an optional call at first, then only array accesses
|
||||
|
||||
let vectors = vec![
|
||||
("a", absy::Expression::Identifier("a").into()),
|
||||
("a", absy::Expression::Identifier("a")),
|
||||
(
|
||||
"a[3]",
|
||||
absy::Expression::Select(
|
||||
box absy::Expression::Identifier("a").into(),
|
||||
box absy::RangeOrExpression::Expression(
|
||||
absy::Expression::FieldConstant(BigUint::from(3u32)).into(),
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
),
|
||||
),
|
||||
(
|
||||
|
@ -909,14 +908,12 @@ mod tests {
|
|||
box absy::Expression::Identifier("a").into(),
|
||||
box absy::RangeOrExpression::Expression(
|
||||
absy::Expression::FieldConstant(BigUint::from(3u32)).into(),
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
box absy::RangeOrExpression::Expression(
|
||||
absy::Expression::FieldConstant(BigUint::from(4u32)).into(),
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
),
|
||||
),
|
||||
(
|
||||
|
@ -929,8 +926,7 @@ mod tests {
|
|||
.into(),
|
||||
box absy::RangeOrExpression::Expression(
|
||||
absy::Expression::FieldConstant(BigUint::from(4u32)).into(),
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
),
|
||||
),
|
||||
(
|
||||
|
@ -944,14 +940,12 @@ mod tests {
|
|||
.into(),
|
||||
box absy::RangeOrExpression::Expression(
|
||||
absy::Expression::FieldConstant(BigUint::from(4u32)).into(),
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
)
|
||||
.into(),
|
||||
box absy::RangeOrExpression::Expression(
|
||||
absy::Expression::FieldConstant(BigUint::from(5u32)).into(),
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
),
|
||||
),
|
||||
];
|
||||
|
|
|
@ -189,12 +189,11 @@ fn check_with_arena<'ast, T: Field, E: Into<imports::Error>>(
|
|||
arena: &'ast Arena<String>,
|
||||
) -> Result<(ZirProgram<'ast, T>, Abi), CompileErrors> {
|
||||
let source = arena.alloc(source);
|
||||
let compiled = compile_program::<T, E>(source, location.clone(), resolver, &arena)?;
|
||||
let compiled = compile_program::<T, E>(source, location, resolver, &arena)?;
|
||||
|
||||
// check semantics
|
||||
let typed_ast = Checker::check(compiled).map_err(|errors| {
|
||||
CompileErrors(errors.into_iter().map(|e| CompileError::from(e)).collect())
|
||||
})?;
|
||||
let typed_ast = Checker::check(compiled)
|
||||
.map_err(|errors| CompileErrors(errors.into_iter().map(CompileError::from).collect()))?;
|
||||
|
||||
let abi = typed_ast.abi();
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ impl FlatParameter {
|
|||
substitution: &HashMap<FlatVariable, FlatVariable>,
|
||||
) -> FlatParameter {
|
||||
FlatParameter {
|
||||
id: substitution.get(&self.id).unwrap().clone(),
|
||||
id: *substitution.get(&self.id).unwrap(),
|
||||
private: self.private,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ impl FlatVariable {
|
|||
Ok(FlatVariable::public(v))
|
||||
}
|
||||
None => {
|
||||
let mut private = s.split("_");
|
||||
let mut private = s.split('_');
|
||||
match private.nth(1) {
|
||||
Some(v) => {
|
||||
let v = v.parse().map_err(|_| s)?;
|
||||
|
|
|
@ -113,7 +113,7 @@ impl<T> LinComb<T> {
|
|||
}
|
||||
|
||||
pub fn is_zero(&self) -> bool {
|
||||
self.0.len() == 0
|
||||
self.0.is_empty()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,7 +141,7 @@ impl<T: Field> LinComb<T> {
|
|||
// collect to a Result to short circuit when we hit an error
|
||||
.collect::<Result<_, _>>()
|
||||
// we didn't hit an error, do final processing. It's fine to clone here.
|
||||
.map(|v: Vec<_>| (first.clone(), v.iter().fold(T::zero(), |acc, e| acc + *e)))
|
||||
.map(|v: Vec<_>| (*first, v.iter().fold(T::zero(), |acc, e| acc + *e)))
|
||||
.ok()
|
||||
}
|
||||
}
|
||||
|
@ -287,7 +287,7 @@ mod tests {
|
|||
fn add() {
|
||||
let a: LinComb<Bn128Field> = FlatVariable::new(42).into();
|
||||
let b: LinComb<Bn128Field> = FlatVariable::new(42).into();
|
||||
let c = a + b.clone();
|
||||
let c = a + b;
|
||||
|
||||
let expected_vec = vec![
|
||||
(FlatVariable::new(42), Bn128Field::from(1)),
|
||||
|
@ -300,7 +300,7 @@ mod tests {
|
|||
fn sub() {
|
||||
let a: LinComb<Bn128Field> = FlatVariable::new(42).into();
|
||||
let b: LinComb<Bn128Field> = FlatVariable::new(42).into();
|
||||
let c = a - b.clone();
|
||||
let c = a - b;
|
||||
|
||||
let expected_vec = vec![
|
||||
(FlatVariable::new(42), Bn128Field::from(1)),
|
||||
|
|
|
@ -125,7 +125,7 @@ impl<T: Field> From<FlatDirective<T>> for Directive<T> {
|
|||
inputs: ds
|
||||
.inputs
|
||||
.into_iter()
|
||||
.map(|i| QuadComb::from_flat_expression(i))
|
||||
.map(QuadComb::from_flat_expression)
|
||||
.collect(),
|
||||
solver: ds.solver,
|
||||
outputs: ds.outputs,
|
||||
|
|
|
@ -40,7 +40,7 @@ impl Interpreter {
|
|||
let mut witness = BTreeMap::new();
|
||||
witness.insert(FlatVariable::one(), T::one());
|
||||
for (arg, value) in main.arguments.iter().zip(inputs.iter()) {
|
||||
witness.insert(arg.clone(), value.clone().into());
|
||||
witness.insert(*arg, value.clone());
|
||||
}
|
||||
|
||||
for statement in main.statements.iter() {
|
||||
|
@ -48,7 +48,7 @@ impl Interpreter {
|
|||
Statement::Constraint(quad, lin) => match lin.is_assignee(&witness) {
|
||||
true => {
|
||||
let val = quad.evaluate(&witness).unwrap();
|
||||
witness.insert(lin.0.iter().next().unwrap().0.clone(), val);
|
||||
witness.insert(lin.0.get(0).unwrap().0, val);
|
||||
}
|
||||
false => {
|
||||
let lhs_value = quad.evaluate(&witness).unwrap();
|
||||
|
@ -79,7 +79,7 @@ impl Interpreter {
|
|||
match self.execute_solver(&d.solver, &inputs) {
|
||||
Ok(res) => {
|
||||
for (i, o) in d.outputs.iter().enumerate() {
|
||||
witness.insert(o.clone(), res[i].clone());
|
||||
witness.insert(*o, res[i].clone());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
@ -107,12 +107,12 @@ impl Interpreter {
|
|||
value.to_biguint()
|
||||
};
|
||||
|
||||
let mut num = input.clone();
|
||||
let mut num = input;
|
||||
let mut res = vec![];
|
||||
let bits = T::get_required_bits();
|
||||
for i in (0..bits).rev() {
|
||||
if T::from(2).to_biguint().pow(i as usize) <= num {
|
||||
num = num - T::from(2).to_biguint().pow(i as usize);
|
||||
num -= T::from(2).to_biguint().pow(i as usize);
|
||||
res.push(T::one());
|
||||
} else {
|
||||
res.push(T::zero());
|
||||
|
@ -120,7 +120,7 @@ impl Interpreter {
|
|||
}
|
||||
assert_eq!(num, T::zero().to_biguint());
|
||||
for (i, o) in d.outputs.iter().enumerate() {
|
||||
witness.insert(o.clone(), res[i].clone());
|
||||
witness.insert(*o, res[i].clone());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,8 +224,8 @@ impl<T: Field> LinComb<T> {
|
|||
|
||||
fn is_assignee<U>(&self, witness: &BTreeMap<FlatVariable, U>) -> bool {
|
||||
self.0.iter().count() == 1
|
||||
&& self.0.iter().next().unwrap().1 == T::from(1)
|
||||
&& !witness.contains_key(&self.0.iter().next().unwrap().0)
|
||||
&& self.0.get(0).unwrap().1 == T::from(1)
|
||||
&& !witness.contains_key(&self.0.get(0).unwrap().0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ mod tests {
|
|||
main: Function {
|
||||
id: "main".to_string(),
|
||||
statements: vec![
|
||||
constraint.clone(),
|
||||
constraint,
|
||||
Statement::Constraint(
|
||||
QuadComb::from_linear_combinations(
|
||||
LinComb::summand(3, FlatVariable::new(42)),
|
||||
|
|
|
@ -236,7 +236,7 @@ mod tests {
|
|||
id: "foo".to_string(),
|
||||
arguments: vec![x],
|
||||
statements: vec![Statement::definition(y, x), Statement::definition(z, y)],
|
||||
returns: vec![z.into()],
|
||||
returns: vec![z],
|
||||
};
|
||||
|
||||
let optimized: Function<Bn128Field> = Function {
|
||||
|
@ -263,7 +263,7 @@ mod tests {
|
|||
id: "foo".to_string(),
|
||||
arguments: vec![x],
|
||||
statements: vec![Statement::definition(one, x)],
|
||||
returns: vec![x.into()],
|
||||
returns: vec![x],
|
||||
};
|
||||
|
||||
let optimized = f.clone();
|
||||
|
@ -298,14 +298,14 @@ mod tests {
|
|||
Statement::definition(z, y),
|
||||
Statement::constraint(z, y),
|
||||
],
|
||||
returns: vec![z.into()],
|
||||
returns: vec![z],
|
||||
};
|
||||
|
||||
let optimized: Function<Bn128Field> = Function {
|
||||
id: "foo".to_string(),
|
||||
arguments: vec![x],
|
||||
statements: vec![Statement::definition(z, x), Statement::constraint(z, x)],
|
||||
returns: vec![z.into()],
|
||||
returns: vec![z],
|
||||
};
|
||||
|
||||
let mut optimizer = RedefinitionOptimizer::new();
|
||||
|
@ -475,7 +475,7 @@ mod tests {
|
|||
Statement::constraint(x, Bn128Field::from(1)),
|
||||
Statement::constraint(x, Bn128Field::from(2)),
|
||||
],
|
||||
returns: vec![x.into()],
|
||||
returns: vec![x],
|
||||
};
|
||||
|
||||
let optimized = f.clone();
|
||||
|
|
|
@ -78,7 +78,7 @@ impl<T: Field + ArkFieldExtensions + NotBw6_761Field> Backend<T, GM17> for Ark {
|
|||
query: vk
|
||||
.query
|
||||
.into_iter()
|
||||
.map(|g1| serialization::to_g1::<T>(g1))
|
||||
.map(serialization::to_g1::<T>)
|
||||
.collect(),
|
||||
};
|
||||
|
||||
|
@ -172,7 +172,7 @@ impl Backend<Bw6_761Field, GM17> for Ark {
|
|||
query: vk
|
||||
.query
|
||||
.into_iter()
|
||||
.map(|g1| serialization::to_g1::<Bw6_761Field>(g1))
|
||||
.map(serialization::to_g1::<Bw6_761Field>)
|
||||
.collect(),
|
||||
};
|
||||
|
||||
|
|
|
@ -58,28 +58,25 @@ fn ark_combination<T: Field + ArkFieldExtensions>(
|
|||
.map(|(k, v)| {
|
||||
(
|
||||
v.into_ark(),
|
||||
symbols
|
||||
.entry(k)
|
||||
.or_insert_with(|| {
|
||||
match k.is_output() {
|
||||
true => cs.new_input_variable(|| {
|
||||
Ok(witness
|
||||
.0
|
||||
.remove(&k)
|
||||
.ok_or(SynthesisError::AssignmentMissing)?
|
||||
.into_ark())
|
||||
}),
|
||||
false => cs.new_witness_variable(|| {
|
||||
Ok(witness
|
||||
.0
|
||||
.remove(&k)
|
||||
.ok_or(SynthesisError::AssignmentMissing)?
|
||||
.into_ark())
|
||||
}),
|
||||
}
|
||||
.unwrap()
|
||||
})
|
||||
.clone(),
|
||||
*symbols.entry(k).or_insert_with(|| {
|
||||
match k.is_output() {
|
||||
true => cs.new_input_variable(|| {
|
||||
Ok(witness
|
||||
.0
|
||||
.remove(&k)
|
||||
.ok_or(SynthesisError::AssignmentMissing)?
|
||||
.into_ark())
|
||||
}),
|
||||
false => cs.new_witness_variable(|| {
|
||||
Ok(witness
|
||||
.0
|
||||
.remove(&k)
|
||||
.ok_or(SynthesisError::AssignmentMissing)?
|
||||
.into_ark())
|
||||
}),
|
||||
}
|
||||
.unwrap()
|
||||
}),
|
||||
)
|
||||
})
|
||||
.fold(LinearCombination::zero(), |acc, e| acc + e);
|
||||
|
@ -127,7 +124,7 @@ impl<T: Field + ArkFieldExtensions> Prog<T> {
|
|||
}),
|
||||
}
|
||||
.unwrap();
|
||||
(var.clone(), wire)
|
||||
(*var, wire)
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ impl<T: Field + BellmanFieldExtensions> Backend<T, G16> for Bellman {
|
|||
ic: vk
|
||||
.gamma_abc
|
||||
.into_iter()
|
||||
.map(|g1| serialization::to_g1::<T>(g1))
|
||||
.map(serialization::to_g1::<T>)
|
||||
.collect(),
|
||||
};
|
||||
|
||||
|
|
|
@ -51,34 +51,31 @@ fn bellman_combination<T: BellmanFieldExtensions, CS: ConstraintSystem<T::Bellma
|
|||
.map(|(k, v)| {
|
||||
(
|
||||
v.into_bellman(),
|
||||
symbols
|
||||
.entry(k)
|
||||
.or_insert_with(|| {
|
||||
match k.is_output() {
|
||||
true => cs.alloc_input(
|
||||
|| format!("{}", k),
|
||||
|| {
|
||||
Ok(witness
|
||||
.0
|
||||
.remove(&k)
|
||||
.ok_or(SynthesisError::AssignmentMissing)?
|
||||
.into_bellman())
|
||||
},
|
||||
),
|
||||
false => cs.alloc(
|
||||
|| format!("{}", k),
|
||||
|| {
|
||||
Ok(witness
|
||||
.0
|
||||
.remove(&k)
|
||||
.ok_or(SynthesisError::AssignmentMissing)?
|
||||
.into_bellman())
|
||||
},
|
||||
),
|
||||
}
|
||||
.unwrap()
|
||||
})
|
||||
.clone(),
|
||||
*symbols.entry(k).or_insert_with(|| {
|
||||
match k.is_output() {
|
||||
true => cs.alloc_input(
|
||||
|| format!("{}", k),
|
||||
|| {
|
||||
Ok(witness
|
||||
.0
|
||||
.remove(&k)
|
||||
.ok_or(SynthesisError::AssignmentMissing)?
|
||||
.into_bellman())
|
||||
},
|
||||
),
|
||||
false => cs.alloc(
|
||||
|| format!("{}", k),
|
||||
|| {
|
||||
Ok(witness
|
||||
.0
|
||||
.remove(&k)
|
||||
.ok_or(SynthesisError::AssignmentMissing)?
|
||||
.into_bellman())
|
||||
},
|
||||
),
|
||||
}
|
||||
.unwrap()
|
||||
}),
|
||||
)
|
||||
})
|
||||
.fold(LinearCombination::zero(), |acc, e| acc + e)
|
||||
|
@ -127,7 +124,7 @@ impl<T: BellmanFieldExtensions + Field> Prog<T> {
|
|||
),
|
||||
}
|
||||
.unwrap();
|
||||
(var.clone(), wire)
|
||||
(*var, wire)
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
|
@ -2379,9 +2379,7 @@ mod tests {
|
|||
let types = HashMap::new();
|
||||
let module_id = "".into();
|
||||
|
||||
let expr =
|
||||
Expression::FieldConstant(BigUint::from(Bn128Field::max_value().to_biguint()))
|
||||
.mock();
|
||||
let expr = Expression::FieldConstant(Bn128Field::max_value().to_biguint()).mock();
|
||||
assert!(Checker::new()
|
||||
.check_expression::<Bn128Field>(expr, &module_id, &types)
|
||||
.is_ok());
|
||||
|
@ -2393,7 +2391,7 @@ mod tests {
|
|||
let module_id = "".into();
|
||||
|
||||
let value = Bn128Field::max_value().to_biguint().add(1u32);
|
||||
let expr = Expression::FieldConstant(BigUint::from(value)).mock();
|
||||
let expr = Expression::FieldConstant(value).mock();
|
||||
|
||||
assert!(Checker::new()
|
||||
.check_expression::<Bn128Field>(expr, &module_id, &types)
|
||||
|
@ -2515,7 +2513,7 @@ mod tests {
|
|||
fn struct1() -> StructDefinitionNode<'static> {
|
||||
StructDefinition {
|
||||
fields: vec![StructDefinitionField {
|
||||
id: "foo".into(),
|
||||
id: "foo",
|
||||
ty: UnresolvedType::FieldElement.mock(),
|
||||
}
|
||||
.mock()],
|
||||
|
@ -2620,7 +2618,7 @@ mod tests {
|
|||
};
|
||||
|
||||
let mut state = State::<Bn128Field>::new(
|
||||
vec![(PathBuf::from(MODULE_ID).into(), module)]
|
||||
vec![(PathBuf::from(MODULE_ID), module)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
);
|
||||
|
@ -2628,7 +2626,7 @@ mod tests {
|
|||
let mut checker = Checker::new();
|
||||
assert_eq!(
|
||||
checker
|
||||
.check_module(&PathBuf::from(MODULE_ID).into(), &mut state)
|
||||
.check_module(&PathBuf::from(MODULE_ID), &mut state)
|
||||
.unwrap_err()[0]
|
||||
.inner
|
||||
.message,
|
||||
|
@ -3638,7 +3636,7 @@ mod tests {
|
|||
)
|
||||
.mock(),
|
||||
Statement::Definition(
|
||||
Assignee::Identifier("a".into()).mock(),
|
||||
Assignee::Identifier("a").mock(),
|
||||
Expression::InlineArray(vec![absy::SpreadOrExpression::Expression(
|
||||
Expression::FieldConstant(BigUint::from(0u32)).mock(),
|
||||
)])
|
||||
|
@ -4445,7 +4443,7 @@ mod tests {
|
|||
assert_eq!(
|
||||
checker.check_type(
|
||||
UnresolvedType::User("Foo".into()).mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types
|
||||
),
|
||||
Ok(Type::Struct(StructType::new(
|
||||
|
@ -4459,7 +4457,7 @@ mod tests {
|
|||
checker
|
||||
.check_type(
|
||||
UnresolvedType::User("Bar".into()).mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types
|
||||
)
|
||||
.unwrap_err()
|
||||
|
@ -4491,7 +4489,7 @@ mod tests {
|
|||
private: true,
|
||||
}
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types,
|
||||
),
|
||||
Ok(Parameter {
|
||||
|
@ -4519,7 +4517,7 @@ mod tests {
|
|||
private: true,
|
||||
}
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types,
|
||||
)
|
||||
.unwrap_err()[0]
|
||||
|
@ -4549,7 +4547,7 @@ mod tests {
|
|||
.mock()
|
||||
)
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types,
|
||||
),
|
||||
Ok(TypedStatement::Declaration(Variable::with_id_and_type(
|
||||
|
@ -4574,7 +4572,7 @@ mod tests {
|
|||
private: true,
|
||||
}
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types,
|
||||
)
|
||||
.unwrap_err()[0]
|
||||
|
@ -4617,7 +4615,7 @@ mod tests {
|
|||
"foo".into()
|
||||
)
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types
|
||||
),
|
||||
Ok(FieldElementExpression::Member(
|
||||
|
@ -4666,7 +4664,7 @@ mod tests {
|
|||
"bar".into()
|
||||
)
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types
|
||||
)
|
||||
.unwrap_err()
|
||||
|
@ -4703,7 +4701,7 @@ mod tests {
|
|||
)]
|
||||
)
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types
|
||||
)
|
||||
.unwrap_err()
|
||||
|
@ -4747,7 +4745,7 @@ mod tests {
|
|||
]
|
||||
)
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types
|
||||
),
|
||||
Ok(StructExpressionInner::Value(vec![
|
||||
|
@ -4801,7 +4799,7 @@ mod tests {
|
|||
]
|
||||
)
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types
|
||||
),
|
||||
Ok(StructExpressionInner::Value(vec![
|
||||
|
@ -4853,7 +4851,7 @@ mod tests {
|
|||
)]
|
||||
)
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types
|
||||
)
|
||||
.unwrap_err()
|
||||
|
@ -4900,7 +4898,7 @@ mod tests {
|
|||
)]
|
||||
)
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types
|
||||
).unwrap_err()
|
||||
.message,
|
||||
|
@ -4924,7 +4922,7 @@ mod tests {
|
|||
]
|
||||
)
|
||||
.mock(),
|
||||
&PathBuf::from(MODULE_ID).into(),
|
||||
&PathBuf::from(MODULE_ID),
|
||||
&state.types
|
||||
)
|
||||
.unwrap_err()
|
||||
|
@ -5001,7 +4999,7 @@ mod tests {
|
|||
checker.check_assignee::<Bn128Field>(a, &module_id, &types),
|
||||
Ok(TypedAssignee::Select(
|
||||
box TypedAssignee::Identifier(typed_absy::Variable::field_array("a", 33)),
|
||||
box FieldElementExpression::Number(Bn128Field::from(2u32)).into()
|
||||
box FieldElementExpression::Number(Bn128Field::from(2u32))
|
||||
))
|
||||
);
|
||||
}
|
||||
|
@ -5056,9 +5054,9 @@ mod tests {
|
|||
Type::array(Type::FieldElement, 33),
|
||||
42
|
||||
)),
|
||||
box FieldElementExpression::Number(Bn128Field::from(1u32)).into()
|
||||
box FieldElementExpression::Number(Bn128Field::from(1u32))
|
||||
),
|
||||
box FieldElementExpression::Number(Bn128Field::from(2u32)).into()
|
||||
box FieldElementExpression::Number(Bn128Field::from(2u32))
|
||||
))
|
||||
);
|
||||
}
|
||||
|
|
|
@ -240,7 +240,7 @@ impl<'ast, T: Field> Inliner<'ast, T> {
|
|||
res.map(|exprs| {
|
||||
self.call_cache_mut()
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| HashMap::new())
|
||||
.or_insert_with(HashMap::new)
|
||||
.insert(expressions, exprs.clone());
|
||||
exprs
|
||||
})
|
||||
|
@ -269,7 +269,7 @@ impl<'ast, T: Field> Inliner<'ast, T> {
|
|||
> {
|
||||
self.call_cache
|
||||
.entry(self.location.clone())
|
||||
.or_insert_with(|| HashMap::new())
|
||||
.or_insert_with(HashMap::new)
|
||||
}
|
||||
|
||||
fn call_cache_mut(
|
||||
|
@ -366,7 +366,7 @@ impl<'ast, T: Field> Folder<'ast, T> for Inliner<'ast, T> {
|
|||
|
||||
self.call_cache_mut()
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| HashMap::new())
|
||||
.or_insert_with(HashMap::new)
|
||||
.insert(
|
||||
expressions,
|
||||
vec![FieldElementExpression::Identifier(id.clone()).into()],
|
||||
|
@ -420,7 +420,7 @@ impl<'ast, T: Field> Folder<'ast, T> for Inliner<'ast, T> {
|
|||
|
||||
self.call_cache_mut()
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| HashMap::new())
|
||||
.or_insert_with(HashMap::new)
|
||||
.insert(
|
||||
expressions,
|
||||
vec![BooleanExpression::Identifier(id.clone()).into()],
|
||||
|
@ -478,7 +478,7 @@ impl<'ast, T: Field> Folder<'ast, T> for Inliner<'ast, T> {
|
|||
|
||||
self.call_cache_mut()
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| HashMap::new())
|
||||
.or_insert_with(HashMap::new)
|
||||
.insert(
|
||||
expressions,
|
||||
vec![out.clone().annotate(ty.clone(), size).into()],
|
||||
|
@ -535,7 +535,7 @@ impl<'ast, T: Field> Folder<'ast, T> for Inliner<'ast, T> {
|
|||
|
||||
self.call_cache_mut()
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| HashMap::new())
|
||||
.or_insert_with(HashMap::new)
|
||||
.insert(expressions, vec![out.clone().annotate(ty.clone()).into()]);
|
||||
|
||||
out
|
||||
|
@ -589,7 +589,7 @@ impl<'ast, T: Field> Folder<'ast, T> for Inliner<'ast, T> {
|
|||
|
||||
self.call_cache_mut()
|
||||
.entry(key.clone())
|
||||
.or_insert_with(|| HashMap::new())
|
||||
.or_insert_with(HashMap::new)
|
||||
.insert(expressions, vec![out.clone().annotate(size).into()]);
|
||||
|
||||
out
|
||||
|
@ -850,7 +850,7 @@ mod tests {
|
|||
Identifier::from("a").stack(stack.clone())
|
||||
),
|
||||
box FieldElementExpression::Identifier(
|
||||
Identifier::from("a").stack(stack.clone())
|
||||
Identifier::from("a").stack(stack)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -1007,7 +1007,7 @@ mod tests {
|
|||
FieldElementExpression::Identifier("b".into()).into(),
|
||||
])
|
||||
],
|
||||
signature: signature.clone(),
|
||||
signature: signature,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -1229,7 +1229,7 @@ mod tests {
|
|||
FieldElementExpression::Identifier("b".into()).into(),
|
||||
])
|
||||
],
|
||||
signature: signature.clone(),
|
||||
signature: signature,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
@ -1591,13 +1591,11 @@ mod tests {
|
|||
TypedAssignee::Identifier(Variable::field_element(
|
||||
Identifier::from("a").stack(stack1.clone())
|
||||
)),
|
||||
FieldElementExpression::Identifier(
|
||||
Identifier::from("a").stack(stack0.clone())
|
||||
)
|
||||
.into()
|
||||
FieldElementExpression::Identifier(Identifier::from("a").stack(stack0))
|
||||
.into()
|
||||
),
|
||||
TypedStatement::Return(vec![FieldElementExpression::Identifier(
|
||||
Identifier::from("a").stack(stack1.clone())
|
||||
Identifier::from("a").stack(stack1)
|
||||
)
|
||||
.into(),])
|
||||
],
|
||||
|
|
|
@ -84,13 +84,10 @@ impl<'ast> Unroller<'ast> {
|
|||
|
||||
match head {
|
||||
Access::Select(head) => {
|
||||
statements.insert(TypedStatement::Assertion(
|
||||
BooleanExpression::Lt(
|
||||
box head.clone(),
|
||||
box FieldElementExpression::Number(T::from(size)),
|
||||
)
|
||||
.into(),
|
||||
));
|
||||
statements.insert(TypedStatement::Assertion(BooleanExpression::Lt(
|
||||
box head.clone(),
|
||||
box FieldElementExpression::Number(T::from(size)),
|
||||
)));
|
||||
|
||||
ArrayExpressionInner::Value(
|
||||
(0..size)
|
||||
|
@ -241,7 +238,7 @@ impl<'ast> Unroller<'ast> {
|
|||
}
|
||||
TypedExpression::Struct(base) => {
|
||||
let members = match base.get_type() {
|
||||
Type::Struct(members) => members.clone(),
|
||||
Type::Struct(members) => members,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
@ -267,11 +264,8 @@ impl<'ast> Unroller<'ast> {
|
|||
statements,
|
||||
)
|
||||
} else {
|
||||
FieldElementExpression::member(
|
||||
base.clone(),
|
||||
member.id.clone(),
|
||||
)
|
||||
.into()
|
||||
FieldElementExpression::member(base.clone(), member.id)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
Type::Uint(..) => {
|
||||
|
@ -284,8 +278,7 @@ impl<'ast> Unroller<'ast> {
|
|||
statements,
|
||||
)
|
||||
} else {
|
||||
UExpression::member(base.clone(), member.id.clone())
|
||||
.into()
|
||||
UExpression::member(base.clone(), member.id).into()
|
||||
}
|
||||
}
|
||||
Type::Boolean => {
|
||||
|
@ -301,11 +294,8 @@ impl<'ast> Unroller<'ast> {
|
|||
statements,
|
||||
)
|
||||
} else {
|
||||
BooleanExpression::member(
|
||||
base.clone(),
|
||||
member.id.clone(),
|
||||
)
|
||||
.into()
|
||||
BooleanExpression::member(base.clone(), member.id)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
Type::Array(..) => {
|
||||
|
@ -318,8 +308,7 @@ impl<'ast> Unroller<'ast> {
|
|||
statements,
|
||||
)
|
||||
} else {
|
||||
ArrayExpression::member(base.clone(), member.id.clone())
|
||||
.into()
|
||||
ArrayExpression::member(base.clone(), member.id).into()
|
||||
}
|
||||
}
|
||||
Type::Struct(..) => {
|
||||
|
@ -335,11 +324,7 @@ impl<'ast> Unroller<'ast> {
|
|||
statements,
|
||||
)
|
||||
} else {
|
||||
StructExpression::member(
|
||||
base.clone(),
|
||||
member.id.clone(),
|
||||
)
|
||||
.into()
|
||||
StructExpression::member(base.clone(), member.id).into()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -391,26 +376,20 @@ impl<'ast, T: Field> Folder<'ast, T> for Unroller<'ast> {
|
|||
|
||||
let base = match variable.get_type() {
|
||||
Type::FieldElement => {
|
||||
FieldElementExpression::Identifier(variable.id.clone().into()).into()
|
||||
}
|
||||
Type::Boolean => {
|
||||
BooleanExpression::Identifier(variable.id.clone().into()).into()
|
||||
}
|
||||
Type::Uint(bitwidth) => {
|
||||
UExpressionInner::Identifier(variable.id.clone().into())
|
||||
.annotate(bitwidth)
|
||||
.into()
|
||||
FieldElementExpression::Identifier(variable.id.clone()).into()
|
||||
}
|
||||
Type::Boolean => BooleanExpression::Identifier(variable.id.clone()).into(),
|
||||
Type::Uint(bitwidth) => UExpressionInner::Identifier(variable.id.clone())
|
||||
.annotate(bitwidth)
|
||||
.into(),
|
||||
Type::Array(array_type) => {
|
||||
ArrayExpressionInner::Identifier(variable.id.clone().into())
|
||||
ArrayExpressionInner::Identifier(variable.id.clone())
|
||||
.annotate(*array_type.ty, array_type.size)
|
||||
.into()
|
||||
}
|
||||
Type::Struct(members) => {
|
||||
StructExpressionInner::Identifier(variable.id.clone().into())
|
||||
.annotate(members)
|
||||
.into()
|
||||
}
|
||||
Type::Struct(members) => StructExpressionInner::Identifier(variable.id.clone())
|
||||
.annotate(members)
|
||||
.into(),
|
||||
};
|
||||
|
||||
let base = self.fold_expression(base);
|
||||
|
@ -470,9 +449,9 @@ impl<'ast, T: Field> Folder<'ast, T> for Unroller<'ast> {
|
|||
stats.clone(),
|
||||
]
|
||||
.into_iter()
|
||||
.flat_map(|x| x)
|
||||
.flatten()
|
||||
})
|
||||
.flat_map(|x| x)
|
||||
.flatten()
|
||||
.flat_map(|x| self.fold_statement(x))
|
||||
.collect();
|
||||
|
||||
|
@ -499,7 +478,7 @@ impl<'ast, T: Field> Folder<'ast, T> for Unroller<'ast> {
|
|||
|
||||
fn fold_name(&mut self, n: Identifier<'ast>) -> Identifier<'ast> {
|
||||
Identifier {
|
||||
version: self.substitution.get(&n.id).unwrap_or(&0).clone(),
|
||||
version: *self.substitution.get(&n.id).unwrap_or(&0),
|
||||
..n
|
||||
}
|
||||
}
|
||||
|
@ -1088,13 +1067,10 @@ mod tests {
|
|||
assert_eq!(
|
||||
u.fold_statement(s),
|
||||
vec![
|
||||
TypedStatement::Assertion(
|
||||
BooleanExpression::Lt(
|
||||
box FieldElementExpression::Number(Bn128Field::from(1)),
|
||||
box FieldElementExpression::Number(Bn128Field::from(2))
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
TypedStatement::Assertion(BooleanExpression::Lt(
|
||||
box FieldElementExpression::Number(Bn128Field::from(1)),
|
||||
box FieldElementExpression::Number(Bn128Field::from(2))
|
||||
),),
|
||||
TypedStatement::Definition(
|
||||
TypedAssignee::Identifier(Variable::field_array(
|
||||
Identifier::from("a").version(1),
|
||||
|
@ -1225,17 +1201,14 @@ mod tests {
|
|||
assert_eq!(
|
||||
u.fold_statement(s),
|
||||
vec![
|
||||
TypedStatement::Assertion(
|
||||
BooleanExpression::Lt(
|
||||
box FieldElementExpression::Number(Bn128Field::from(1)),
|
||||
box FieldElementExpression::Number(Bn128Field::from(2))
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
TypedStatement::Assertion(BooleanExpression::Lt(
|
||||
box FieldElementExpression::Number(Bn128Field::from(1)),
|
||||
box FieldElementExpression::Number(Bn128Field::from(2))
|
||||
),),
|
||||
TypedStatement::Definition(
|
||||
TypedAssignee::Identifier(Variable::with_id_and_type(
|
||||
Identifier::from("a").version(1),
|
||||
array_of_array_ty.clone()
|
||||
array_of_array_ty
|
||||
)),
|
||||
ArrayExpressionInner::Value(vec![
|
||||
ArrayExpressionInner::IfElse(
|
||||
|
@ -1247,8 +1220,7 @@ mod tests {
|
|||
FieldElementExpression::Number(Bn128Field::from(4)).into(),
|
||||
FieldElementExpression::Number(Bn128Field::from(5)).into(),
|
||||
])
|
||||
.annotate(Type::FieldElement, 2)
|
||||
.into(),
|
||||
.annotate(Type::FieldElement, 2),
|
||||
box ArrayExpressionInner::Select(
|
||||
box ArrayExpressionInner::Identifier(
|
||||
Identifier::from("a").version(0)
|
||||
|
@ -1269,8 +1241,7 @@ mod tests {
|
|||
FieldElementExpression::Number(Bn128Field::from(4)).into(),
|
||||
FieldElementExpression::Number(Bn128Field::from(5)).into(),
|
||||
])
|
||||
.annotate(Type::FieldElement, 2)
|
||||
.into(),
|
||||
.annotate(Type::FieldElement, 2),
|
||||
box ArrayExpressionInner::Select(
|
||||
box ArrayExpressionInner::Identifier(
|
||||
Identifier::from("a").version(0)
|
||||
|
|
|
@ -34,7 +34,7 @@ impl<'ast, T: Field> VariableAccessRemover<'ast, T> {
|
|||
match i {
|
||||
FieldElementExpression::Number(i) => U::select(a, FieldElementExpression::Number(i)),
|
||||
i => {
|
||||
let size = match a.get_type().clone() {
|
||||
let size = match a.get_type() {
|
||||
Type::Array(array_ty) => array_ty.size,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
@ -44,15 +44,14 @@ impl<'ast, T: Field> VariableAccessRemover<'ast, T> {
|
|||
.map(|index| {
|
||||
BooleanExpression::FieldEq(
|
||||
box i.clone(),
|
||||
box FieldElementExpression::Number(index.into()).into(),
|
||||
box FieldElementExpression::Number(index.into()),
|
||||
)
|
||||
})
|
||||
.fold(None, |acc, e| match acc {
|
||||
Some(acc) => Some(BooleanExpression::Or(box acc, box e)),
|
||||
None => Some(e),
|
||||
})
|
||||
.unwrap()
|
||||
.into(),
|
||||
.unwrap(),
|
||||
));
|
||||
|
||||
(0..size)
|
||||
|
@ -169,19 +168,16 @@ mod tests {
|
|||
assert_eq!(
|
||||
VariableAccessRemover::new().fold_statement(access),
|
||||
vec![
|
||||
TypedStatement::Assertion(
|
||||
BooleanExpression::Or(
|
||||
box BooleanExpression::FieldEq(
|
||||
box FieldElementExpression::Identifier("i".into()),
|
||||
box FieldElementExpression::Number(0.into())
|
||||
),
|
||||
box BooleanExpression::FieldEq(
|
||||
box FieldElementExpression::Identifier("i".into()),
|
||||
box FieldElementExpression::Number(1.into())
|
||||
)
|
||||
TypedStatement::Assertion(BooleanExpression::Or(
|
||||
box BooleanExpression::FieldEq(
|
||||
box FieldElementExpression::Identifier("i".into()),
|
||||
box FieldElementExpression::Number(0.into())
|
||||
),
|
||||
box BooleanExpression::FieldEq(
|
||||
box FieldElementExpression::Identifier("i".into()),
|
||||
box FieldElementExpression::Number(1.into())
|
||||
)
|
||||
.into(),
|
||||
),
|
||||
),),
|
||||
TypedStatement::Definition(
|
||||
TypedAssignee::Identifier(Variable::field_element("b")),
|
||||
FieldElementExpression::if_else(
|
||||
|
|
|
@ -32,7 +32,7 @@ pub struct Identifier<'ast> {
|
|||
|
||||
impl<'ast> fmt::Display for Identifier<'ast> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
if self.stack.len() == 0 && self.version == 0 {
|
||||
if self.stack.is_empty() && self.version == 0 {
|
||||
write!(f, "{}", self.id)
|
||||
} else {
|
||||
write!(
|
||||
|
|
|
@ -12,8 +12,8 @@ impl<'ast> From<typed_absy::types::FunctionKey<'ast>> for zir::types::FunctionKe
|
|||
impl From<typed_absy::types::Signature> for zir::types::Signature {
|
||||
fn from(s: typed_absy::types::Signature) -> zir::types::Signature {
|
||||
zir::types::Signature {
|
||||
inputs: s.inputs.into_iter().flat_map(|t| from_type(t)).collect(),
|
||||
outputs: s.outputs.into_iter().flat_map(|t| from_type(t)).collect(),
|
||||
inputs: s.inputs.into_iter().flat_map(from_type).collect(),
|
||||
outputs: s.outputs.into_iter().flat_map(from_type).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,8 +88,7 @@ impl<'ast, T> ZirFunctionSymbol<'ast, T> {
|
|||
.functions
|
||||
.get(key)
|
||||
.unwrap()
|
||||
.signature(&modules)
|
||||
.clone(),
|
||||
.signature(&modules),
|
||||
ZirFunctionSymbol::Flat(flat_fun) => flat_fun.signature().into(),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,14 +37,12 @@ impl<'a> Resolver<io::Error> for FileSystemResolver<'a> {
|
|||
// other paths `abc/def` are interpreted relative to the standard library root path
|
||||
let base = match source.components().next() {
|
||||
Some(Component::CurDir) | Some(Component::ParentDir) => {
|
||||
PathBuf::from(current_location).parent().unwrap().into()
|
||||
current_location.parent().unwrap().into()
|
||||
}
|
||||
_ => PathBuf::from(self.stdlib_root_path.unwrap_or("")),
|
||||
};
|
||||
|
||||
let path_owned = base
|
||||
.join(PathBuf::from(import_location.clone()))
|
||||
.with_extension("zok");
|
||||
let path_owned = base.join(import_location.clone()).with_extension("zok");
|
||||
|
||||
if !path_owned.is_file() {
|
||||
return Err(io::Error::new(
|
||||
|
@ -96,7 +94,7 @@ mod tests {
|
|||
// create a source folder with a zok file
|
||||
let folder = tempfile::tempdir().unwrap();
|
||||
let dir_path = folder.path().join("dir");
|
||||
std::fs::create_dir(dir_path.clone()).unwrap();
|
||||
std::fs::create_dir(dir_path).unwrap();
|
||||
|
||||
let fs_resolver = FileSystemResolver::default();
|
||||
let res = fs_resolver.resolve(".".into(), "./dir/".into());
|
||||
|
@ -155,7 +153,7 @@ mod tests {
|
|||
|
||||
let stdlib_root_path = temp_dir.path().to_owned();
|
||||
let fs_resolver = FileSystemResolver::with_stdlib_root(stdlib_root_path.to_str().unwrap());
|
||||
let result = fs_resolver.resolve(file_path.clone(), "bar.zok".into());
|
||||
let result = fs_resolver.resolve(file_path, "bar.zok".into());
|
||||
assert!(result.is_ok());
|
||||
// the imported file should be the user's
|
||||
assert_eq!(result.unwrap().0, String::from("<stdlib code>\n"));
|
||||
|
|
|
@ -15,5 +15,5 @@ fn export_stdlib() {
|
|||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let mut options = CopyOptions::new();
|
||||
options.overwrite = true;
|
||||
copy_items(&vec!["stdlib"], out_dir, &options).unwrap();
|
||||
copy_items(&["stdlib"], out_dir, &options).unwrap();
|
||||
}
|
||||
|
|
|
@ -144,7 +144,7 @@ fn compile_and_run<T: Field>(t: Tests) {
|
|||
s,
|
||||
input
|
||||
.iter()
|
||||
.map(|i| format!("{}", i))
|
||||
.map(|i| i.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
);
|
||||
|
|
Loading…
Reference in a new issue