Skip to content

Commit

Permalink
chore: clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
delehef committed Nov 14, 2023
1 parent 123afd0 commit 65e2008
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 49 deletions.
4 changes: 2 additions & 2 deletions src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
35 changes: 17 additions & 18 deletions src/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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("."),
}
Expand Down Expand Up @@ -899,7 +895,7 @@ impl ColumnSet {
self.column(c).unwrap().handle.module.clone()
}

pub(crate) fn module_for<'a, I: std::borrow::Borrow<ColumnRef>, C: IntoIterator<Item = I>>(
pub(crate) fn module_for<I: std::borrow::Borrow<ColumnRef>, C: IntoIterator<Item = I>>(
&self,
cols: C,
) -> Option<String> {
Expand Down Expand Up @@ -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!()
}
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/codetyper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 1 addition & 4 deletions src/compiler/compiletime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)?;
}
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, .. } => {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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) => {
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
22 changes: 13 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ impl ConstraintSetBuilder {
}
}

fn to_constraint_set(self) -> Result<ConstraintSet> {
fn into_constraint_set(self) -> Result<ConstraintSet> {
let mut cs = match self.source {
Either::Left(ref sources) => compiler::make(
&self.prepare_sources(sources),
Expand Down Expand Up @@ -629,15 +629,19 @@ 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 {
package,
output_file_path: output_path,
} => {
exporters::besu::render(
&builder.to_constraint_set()?,
&builder.into_constraint_set()?,
&package,
output_path.as_ref(),
)?;
Expand All @@ -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)?;
}
Expand All @@ -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))?;
Expand Down Expand Up @@ -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))?;
Expand Down Expand Up @@ -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))?;
Expand All @@ -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);
}
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion src/pretty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub trait Pretty {
fn pretty_with_base(&self, base: Base) -> String;
}

fn to_bytes<'a>(f: &'a Fr) -> Vec<u8> {
fn to_bytes(f: &Fr) -> Vec<u8> {
// TODO: smallvec
f.into_bigint()
.0
Expand Down
2 changes: 1 addition & 1 deletion src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 4 additions & 7 deletions src/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,27 +62,24 @@ 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<u8> for ExpansionLevel {
fn from(x: u8) -> Self {
match x {
0 => ExpansionLevel::None,
1 => ExpansionLevel::ExpandsIfs,
2 => ExpansionLevel::Splatter,
3 => ExpansionLevel::ColumnizeExpressions,
4 | _ => ExpansionLevel::ExpandInvs,
4 => ExpansionLevel::ExpandInvs,
_ => ExpansionLevel::ExpandInvs,
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/transformer/inverses.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 65e2008

Please sign in to comment.