Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ rustdoc.all = "warn"
[workspace.lints.clippy]
all = { level = "warn", priority = -1 }
nursery = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
doc_markdown = "allow"
cast_possible_truncation = "allow"
cast_precision_loss = "allow"
Expand All @@ -45,11 +46,9 @@ suboptimal_flops = "allow"
cast_sign_loss = "allow"
redundant_pub_crate = "allow"
too_many_lines = "allow"
to_string_trait_impl = "allow"
transmute_ptr_to_ptr = "allow"
missing_transmute_annotations = "allow"
type_complexity = "allow"
needless_range_loop = "allow"
too_many_arguments = "allow"
result_large_err = "allow"
format_push_string = "allow"
Expand Down
8 changes: 4 additions & 4 deletions crates/air/src/prove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ pub fn prove_many_air_3<
n_tables,
witnesses_1.len() + witnesses_2.len() + witnesses_3.len()
);
for i in 0..tables_1.len() {
for witness in witnesses_1.iter().take(tables_1.len()) {
assert!(
univariate_skips < witnesses_1[i].log_n_rows(),
univariate_skips < witness.log_n_rows(),
"TODO handle the case UNIVARIATE_SKIPS >= log_length"
);
}
Expand Down Expand Up @@ -471,7 +471,7 @@ fn open_structured_columns<EF: ExtensionField<PF<EF>> + ExtensionField<IF>, IF:
);

let mut evaluations_remaining_to_prove = vec![];
for i in 0..n_groups {
for (i, inner_eval) in all_inner_evals.iter().enumerate().take(n_groups) {
let group = &witness.column_groups[i];
let point = MultilinearPoint(
[
Expand All @@ -480,7 +480,7 @@ fn open_structured_columns<EF: ExtensionField<PF<EF>> + ExtensionField<IF>, IF:
]
.concat(),
);
let value = all_inner_evals[i][1];
let value = inner_eval[1];
evaluations_remaining_to_prove.push(Evaluation { point, value });
}
evaluations_remaining_to_prove
Expand Down
81 changes: 39 additions & 42 deletions crates/compiler/src/a_simplify_lang.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use std::collections::{BTreeMap, BTreeSet};
use std::{
collections::{BTreeMap, BTreeSet},
fmt::{self, Display, Formatter},
};

use utils::ToUsize;

Expand Down Expand Up @@ -62,7 +65,7 @@ impl TryInto<VarOrConstMallocAccess> for SimpleExpr {
malloc_label,
offset,
}),
_ => Err(()),
Self::Constant(_) => Err(()),
}
}
}
Expand Down Expand Up @@ -1242,6 +1245,11 @@ fn replace_vars_by_const_in_lines(lines: &mut [Line], map: &BTreeMap<Var, F>) {
}
Line::FunctionCall {
args, return_data, ..
}
| Line::Precompile {
precompile: _,
args,
res: return_data,
} => {
for arg in args {
replace_vars_by_const_in_expr(arg, map);
Expand Down Expand Up @@ -1285,18 +1293,6 @@ fn replace_vars_by_const_in_lines(lines: &mut [Line], map: &BTreeMap<Var, F>) {
replace_vars_by_const_in_expr(ret, map);
}
}
Line::Precompile {
precompile: _,
args,
res: return_data,
} => {
for arg in args {
replace_vars_by_const_in_expr(arg, map);
}
for r in return_data {
assert!(!map.contains_key(r), "Return variable {r} is a constant");
}
}
Line::Print { content, .. } => {
for var in content {
replace_vars_by_const_in_expr(var, map);
Expand All @@ -1315,21 +1311,21 @@ fn replace_vars_by_const_in_lines(lines: &mut [Line], map: &BTreeMap<Var, F>) {
}
}

impl ToString for SimpleLine {
fn to_string(&self) -> String {
self.to_string_with_indent(0)
impl Display for SimpleLine {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.write_str(&self.to_string_with_indent(0))
}
}

impl ToString for VarOrConstMallocAccess {
fn to_string(&self) -> String {
impl Display for VarOrConstMallocAccess {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
Self::Var(var) => var.to_string(),
Self::Var(var) => f.write_str(var),
Self::ConstMallocAccess {
malloc_label,
offset,
} => {
format!("ConstMallocAccess({malloc_label}, {offset})")
write!(f, "ConstMallocAccess({malloc_label}, {offset})")
}
}
}
Expand All @@ -1345,7 +1341,7 @@ impl SimpleLine {
arg0,
arg1,
} => {
format!("{} = {} {} {}", var.to_string(), arg0, operation, arg1)
format!("{var} = {arg0} {operation} {arg1}")
}
Self::DecomposeBits {
var: result,
Expand Down Expand Up @@ -1463,45 +1459,46 @@ impl SimpleLine {
}
}

impl ToString for SimpleFunction {
fn to_string(&self) -> String {
impl Display for SimpleFunction {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
let args_str = self
.arguments
.iter()
.map(std::string::ToString::to_string)
.collect::<Vec<_>>()
.join(", ");

let instructions_str = self
.instructions
.iter()
.map(|line| line.to_string_with_indent(1))
.collect::<Vec<_>>()
.join("\n");

if self.instructions.is_empty() {
format!(
write!(
f,
"fn {}({}) -> {} {{}}",
self.name, args_str, self.n_returned_vars
)
} else {
format!(
"fn {}({}) -> {} {{\n{}\n}}",
self.name, args_str, self.n_returned_vars, instructions_str
)
writeln!(
f,
"fn {}({}) -> {} {{",
self.name, args_str, self.n_returned_vars
)?;
for (i, line) in self.instructions.iter().enumerate() {
if i > 0 {
writeln!(f)?;
}
write!(f, "{}", line.to_string_with_indent(1))?;
}
write!(f, "\n}}")
}
}
}

impl ToString for SimpleProgram {
fn to_string(&self) -> String {
let mut result = String::new();
impl Display for SimpleProgram {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
for (i, function) in self.functions.values().enumerate() {
if i > 0 {
result.push('\n');
writeln!(f)?;
}
result.push_str(&function.to_string());
write!(f, "{function}")?;
}
result
Ok(())
}
}
12 changes: 5 additions & 7 deletions crates/compiler/src/b_compile_intermediate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ fn compile_lines(
let then_instructions = compile_lines(
then_branch,
compiler,
Some(end_label.to_string()),
Some(end_label.clone()),
&mut then_declared_vars,
)?;
let then_stack = compiler.stack_size;
Expand All @@ -303,7 +303,7 @@ fn compile_lines(
let else_instructions = compile_lines(
else_branch,
compiler,
Some(end_label.to_string()),
Some(end_label.clone()),
&mut else_declared_vars,
)?;
let else_stack = compiler.stack_size;
Expand Down Expand Up @@ -397,7 +397,7 @@ fn compile_lines(
args,
res,
} => {
compile_poseidon(&mut instructions, args, res, compiler, declared_vars, true)?;
compile_poseidon(&mut instructions, args, res, compiler, declared_vars, true);
}

SimpleLine::Precompile {
Expand All @@ -409,7 +409,7 @@ fn compile_lines(
args,
res,
} => {
compile_poseidon(&mut instructions, args, res, compiler, declared_vars, false)?;
compile_poseidon(&mut instructions, args, res, compiler, declared_vars, false);
}
SimpleLine::Precompile {
precompile:
Expand Down Expand Up @@ -616,7 +616,7 @@ fn compile_poseidon(
compiler: &Compiler,
declared_vars: &mut BTreeSet<Var>,
over_16: bool, // otherwise over_24
) -> Result<(), String> {
) {
assert_eq!(args.len(), 2);
assert_eq!(res.len(), 1);
let res_var = &res[0];
Expand Down Expand Up @@ -647,8 +647,6 @@ fn compile_poseidon(
res: low_level_res,
});
}

Ok(())
}

fn compile_function_ret(
Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/src/c_compile_final.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ impl IntermediateValue {
offset: eval_const_expression_usize(offset, compiler),
}),
Self::Fp => Ok(MemOrFp::Fp),
_ => Err(format!("Cannot convert {self:?} to MemOrFp")),
Self::Constant(_) => Err(format!("Cannot convert {self:?} to MemOrFp")),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/compiler/src/intermediate_bytecode/operation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub enum HighLevelOperation {

impl HighLevelOperation {
#[must_use]
pub fn eval(&self, a: F, b: F) -> F {
pub fn eval(self, a: F, b: F) -> F {
match self {
Self::Add => a + b,
Self::Mul => a * b,
Expand Down
12 changes: 6 additions & 6 deletions crates/compiler/src/lang/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ impl Line {
} => {
let args_str = args
.iter()
.map(|arg| arg.to_string())
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(", ");
let return_data_str = return_data
.iter()
.map(|var| var.to_string())
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(", ");

Expand All @@ -151,7 +151,7 @@ impl Line {
Self::FunctionRet { return_data } => {
let return_data_str = return_data
.iter()
.map(|arg| arg.to_string())
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(", ");
format!("return {return_data_str}")
Expand All @@ -165,12 +165,12 @@ impl Line {
"{} = {}({})",
return_data
.iter()
.map(|var| var.to_string())
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(", "),
precompile.name,
args.iter()
.map(|arg| arg.to_string())
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(", ")
)
Expand All @@ -181,7 +181,7 @@ impl Line {
} => {
let content_str = content
.iter()
.map(|c| c.to_string())
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(", ");
format!("print({content_str})")
Expand Down
26 changes: 13 additions & 13 deletions crates/pcs/src/ring_switch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,29 +222,29 @@ impl<F: Field, const D: usize> TensorAlgebra<F, D> {
let p1_split = p1.as_basis_coefficients_slice();
let mut data = [[F::ZERO; D]; D];
for i in 0..D {
for j in 0..D {
data[i][j] = p0_split[i] * p1_split[j];
for (j, &p1) in p1_split.iter().enumerate().take(D) {
data[i][j] = p0_split[i] * p1;
}
}
Self(data)
}

fn rows<EF: ExtensionField<F>>(&self) -> [EF; D] {
let mut result = [EF::ZERO; D];
for i in 0..D {
result[i] = EF::from_basis_coefficients_slice(&self.0[i]).unwrap();
for (i, r) in result.iter_mut().enumerate().take(D) {
*r = EF::from_basis_coefficients_slice(&self.0[i]).unwrap();
}
result
}

fn columns<EF: ExtensionField<F>>(&self) -> [EF; D] {
let mut result = [EF::ZERO; D];
for j in 0..D {
for (j, res) in result.iter_mut().enumerate().take(D) {
let mut col = [F::ZERO; D];
for i in 0..D {
col[i] = self.0[i][j];
for (i, c) in col.iter_mut().enumerate().take(D) {
*c = self.0[i][j];
}
result[j] = EF::from_basis_coefficients_slice(&col).unwrap();
*res = EF::from_basis_coefficients_slice(&col).unwrap();
}
result
}
Expand All @@ -259,8 +259,8 @@ impl<F: Field, const D: usize> TensorAlgebra<F, D> {

fn from_columns<EF: ExtensionField<F>>(columns: &[EF; D]) -> Self {
let mut data = [[F::ZERO; D]; D];
for j in 0..D {
let col = columns[j].as_basis_coefficients_slice();
for (j, column) in columns.iter().enumerate().take(D) {
let col = column.as_basis_coefficients_slice();
for i in 0..D {
data[i][j] = col[i];
}
Expand Down Expand Up @@ -309,9 +309,9 @@ impl<F: Field, const D: usize> Add for TensorAlgebra<F, D> {

fn add(self, other: Self) -> Self::Output {
let mut result = [[F::ZERO; D]; D];
for i in 0..D {
for j in 0..D {
result[i][j] = self.0[i][j] + other.0[i][j];
for (i, res) in result.iter_mut().enumerate().take(D) {
for (j, r) in res.iter_mut().enumerate().take(D) {
*r = self.0[i][j] + other.0[i][j];
}
}
Self(result)
Expand Down
1 change: 1 addition & 0 deletions crates/vm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ pcs.workspace = true
p3-poseidon2-air.workspace = true
lookup.workspace = true
sumcheck.workspace = true
thiserror.workspace = true
Loading
Loading