diff --git a/src/check.rs b/src/check.rs index 36df947..2b8857e 100644 --- a/src/check.rs +++ b/src/check.rs @@ -10,7 +10,7 @@ use anyhow::*; use log::*; use crate::{ - column::{ColumnSet, Value, ValueBacking}, + column::{ColumnSet, Value}, compiler::{Constraint, ConstraintSet, Domain, EvalSettings, Expression, Node}, pretty::*, structs::Handle, @@ -431,7 +431,7 @@ fn check_lookup(cs: &ConstraintSet, parents: &[Node], children: &[Node]) -> Resu .collect(); for i in 0..child_len { - if !parent_hashes.contains(&pseudo_rlc(&children, i, &cs.columns)) { + if !parent_hashes.contains(&pseudo_rlc(children, i, &cs.columns)) { bail!( "@{}: {{\n{}\n}} not found in {{{}}}", i, diff --git a/src/column.rs b/src/column.rs index 457e939..3c2630a 100644 --- a/src/column.rs +++ b/src/column.rs @@ -439,23 +439,19 @@ impl Pretty for Value { fn pretty_with_base(&self, base: Base) -> String { match self { - Value::BigInt(i) => { - format!( - "{}", - match base { - Base::Dec => i.to_str_radix(10), - Base::Hex => format!("0x{}", i.to_str_radix(16)), - Base::Bin | Base::Bool | Base::Loob => i.to_str_radix(2), - Base::Bytes => i - .to_bytes_le() - .1 - .iter() - .map(|b| format!("{b:0>2x}")) - .join(" "), - Base::OpCode => opcodes::to_str(i.to_usize().unwrap().try_into().unwrap()), - } - ) + Value::BigInt(i) => match base { + Base::Dec => i.to_str_radix(10), + Base::Hex => format!("0x{}", i.to_str_radix(16)), + Base::Bin | Base::Bool | Base::Loob => i.to_str_radix(2), + Base::Bytes => i + .to_bytes_le() + .1 + .iter() + .map(|b| format!("{b:0>2x}")) + .join(" "), + Base::OpCode => opcodes::to_str(i.to_usize().unwrap().try_into().unwrap()), } + .to_string(), Value::Native(f) => f.pretty_with_base(base), Value::ExoNative(fs) => fs.iter().map(|f| f.pretty_with_base(base)).join("."), } @@ -899,7 +895,7 @@ impl ColumnSet { self.column(c).unwrap().handle.module.clone() } - pub(crate) fn module_for<'a, I: std::borrow::Borrow, C: IntoIterator>( + pub(crate) fn module_for, C: IntoIterator>( &self, cols: C, ) -> Option { @@ -1037,7 +1033,10 @@ impl ColumnSet { if h.is_id() { h.as_id() } else if h.is_handle() { - *self.cols.get(h.as_handle()).expect(&h.to_string()) + *self + .cols + .get(h.as_handle()) + .unwrap_or_else(|| panic!("{}", h.to_string())) } else { unreachable!() } diff --git a/src/compiler/codetyper.rs b/src/compiler/codetyper.rs index 249e5a5..a4477e2 100644 --- a/src/compiler/codetyper.rs +++ b/src/compiler/codetyper.rs @@ -142,7 +142,7 @@ impl Tty { fn make_indent(&self, l: &Line) -> String { if self.with_guides { - if self.depths[l.indentation].len() > 0 {" "} else {""}.to_string() // Account for the first skipped '|' + if !self.depths[l.indentation].is_empty() {" "} else {""}.to_string() // Account for the first skipped '|' + &self .depths[l.indentation] .iter() diff --git a/src/compiler/compiletime.rs b/src/compiler/compiletime.rs index ced1d0d..aa9172e 100755 --- a/src/compiler/compiletime.rs +++ b/src/compiler/compiletime.rs @@ -26,10 +26,7 @@ fn compile_time_constants(e: &AstNode, ctx: &mut Scope, settings: &CompileSettin }; ctx.insert_constant( name, - value - .pure_eval() - .with_context(|| make_ast_error(exp))? - .into(), + value.pure_eval().with_context(|| make_ast_error(exp))?, true, )?; } diff --git a/src/compiler/generator.rs b/src/compiler/generator.rs index 69cd891..91a8999 100644 --- a/src/compiler/generator.rs +++ b/src/compiler/generator.rs @@ -662,7 +662,7 @@ impl ConstraintSet { } Constraint::Permutation { from, to, .. } => { for c in from.iter().chain(to.iter()) { - self.columns.mark_used(&c).unwrap(); + self.columns.mark_used(c).unwrap(); } } Constraint::InRange { exp, .. } => { @@ -890,7 +890,7 @@ impl ConstraintSet { let handle = &column.handle; let module_size = self.effective_len_for(&handle.module).unwrap(); trace!("Writing {}", handle); - let backing = self.columns.backing(&r).unwrap_or_else(|| &empty_backing); + let backing = self.columns.backing(&r).unwrap_or(&empty_backing); let padding: Value = if let Some(v) = column.padding_value.as_ref() { v.clone() } else { @@ -1699,7 +1699,7 @@ fn reduce_toplevel( Ok(Some(Constraint::InRange { handle, exp: reduce(e, ctx, settings)?.unwrap(), - max: Fr::from(*range as u64).into(), + max: Fr::from(*range).into(), })) } Token::DefColumns(columns) => { diff --git a/src/lib.rs b/src/lib.rs index 83d9b49..1497d57 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -143,7 +143,7 @@ impl Trace { } else { backing.get(0, false, &c.columns).unwrap_or_else(|| { c.computations - .computation_for(&cref) + .computation_for(cref) .map(|c| match c { Computation::Composite { exp, .. } => exp .eval( diff --git a/src/main.rs b/src/main.rs index d6ca88f..a13c171 100755 --- a/src/main.rs +++ b/src/main.rs @@ -542,7 +542,7 @@ impl ConstraintSetBuilder { } } - fn to_constraint_set(self) -> Result { + fn into_constraint_set(self) -> Result { let mut cs = match self.source { Either::Left(ref sources) => compiler::make( &self.prepare_sources(sources), @@ -629,7 +629,11 @@ fn main() -> Result<()> { match args.command { #[cfg(feature = "exporters")] Commands::Go { package, filename } => { - exporters::zkgeth::render(&builder.to_constraint_set()?, &package, filename.as_ref())?; + exporters::zkgeth::render( + &builder.into_constraint_set()?, + &package, + filename.as_ref(), + )?; } #[cfg(feature = "exporters")] Commands::Besu { @@ -637,7 +641,7 @@ fn main() -> Result<()> { output_file_path: output_path, } => { exporters::besu::render( - &builder.to_constraint_set()?, + &builder.into_constraint_set()?, &package, output_path.as_ref(), )?; @@ -650,7 +654,7 @@ fn main() -> Result<()> { Commands::WizardIOP { out_filename } => { builder.expand_to(ExpansionLevel::top()); builder.auto_constraints(AutoConstraint::all()); - let cs = builder.to_constraint_set()?; + let cs = builder.into_constraint_set()?; exporters::wizardiop::render(&cs, &out_filename)?; } @@ -675,7 +679,7 @@ fn main() -> Result<()> { } => { builder.expand_to(ExpansionLevel::top()); builder.auto_constraints(AutoConstraint::all()); - let mut cs = builder.to_constraint_set()?; + let mut cs = builder.into_constraint_set()?; compute::compute_trace(&tracefile, &mut cs, fail_on_missing) .with_context(|| format!("while computing from `{}`", tracefile))?; @@ -789,7 +793,7 @@ fn main() -> Result<()> { return Ok(()); } - let mut cs = builder.to_constraint_set()?; + let mut cs = builder.into_constraint_set()?; compute::compute_trace(&tracefile, &mut cs, false) .with_context(|| format!("while expanding `{}`", tracefile))?; @@ -826,7 +830,7 @@ fn main() -> Result<()> { warn!("`{}` is empty, exiting", tracefile); return Ok(()); } - let mut cs = builder.to_constraint_set()?; + let mut cs = builder.into_constraint_set()?; compute::compute_trace(&tracefile, &mut cs, false) .with_context(|| format!("while expanding `{}`", tracefile))?; @@ -851,7 +855,7 @@ fn main() -> Result<()> { only, skip, } => { - let mut cs = builder.to_constraint_set()?; + let mut cs = builder.into_constraint_set()?; if native_arithmetic { transformer::concretize(&mut cs); } @@ -885,7 +889,7 @@ fn main() -> Result<()> { } } Commands::Compile { outfile, pretty } => { - let constraints = builder.to_constraint_set()?; + let constraints = builder.into_constraint_set()?; std::fs::File::create(&outfile) .with_context(|| format!("while creating `{}`", &outfile))? .write_all( diff --git a/src/pretty/mod.rs b/src/pretty/mod.rs index ccb0119..51f87ae 100644 --- a/src/pretty/mod.rs +++ b/src/pretty/mod.rs @@ -67,7 +67,7 @@ pub trait Pretty { fn pretty_with_base(&self, base: Base) -> String; } -fn to_bytes<'a>(f: &'a Fr) -> Vec { +fn to_bytes(f: &Fr) -> Vec { // TODO: smallvec f.into_bigint() .0 diff --git a/src/tests.rs b/src/tests.rs index 6158b43..aa9fe80 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -10,7 +10,7 @@ fn make(name: &str, source: &str) -> Result<()> { r.add_source(source)?; r.expand_to(ExpansionLevel::top()); - r.to_constraint_set().map(|_| ()) + r.into_constraint_set().map(|_| ()) } fn must_run(name: &str, source: &str) { diff --git a/src/transformer.rs b/src/transformer.rs index 42a1283..2bf7b9c 100644 --- a/src/transformer.rs +++ b/src/transformer.rs @@ -62,19 +62,15 @@ impl From<&str> for AutoConstraint { } } -#[derive(Eq, PartialEq, PartialOrd, Ord, Debug, Copy, Clone)] +#[derive(Eq, PartialEq, PartialOrd, Ord, Debug, Copy, Clone, Default)] pub(crate) enum ExpansionLevel { + #[default] None = 0, ExpandsIfs = 1, Splatter = 2, ColumnizeExpressions = 4, ExpandInvs = 8, } -impl Default for ExpansionLevel { - fn default() -> Self { - ExpansionLevel::None - } -} impl From for ExpansionLevel { fn from(x: u8) -> Self { match x { @@ -82,7 +78,8 @@ impl From for ExpansionLevel { 1 => ExpansionLevel::ExpandsIfs, 2 => ExpansionLevel::Splatter, 3 => ExpansionLevel::ColumnizeExpressions, - 4 | _ => ExpansionLevel::ExpandInvs, + 4 => ExpansionLevel::ExpandInvs, + _ => ExpansionLevel::ExpandInvs, } } } diff --git a/src/transformer/inverses.rs b/src/transformer/inverses.rs index 1c2f13a..021bab7 100644 --- a/src/transformer/inverses.rs +++ b/src/transformer/inverses.rs @@ -50,8 +50,7 @@ impl Node { .t(self.t().m().invert()) .build(), ]) - .unwrap() - .into(); + .unwrap(); } else { todo!("exo-value case"); // let module = get_module(&args[0].dependencies());