Skip to content

Commit

Permalink
chore: fix clippy errors (#4684)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Resolves <!-- Link to GitHub Issue -->

## Summary\*

This PR fixes a bunch of clippy errors some new, some old.

## Additional Context



## Documentation\*

Check one:
- [ ] No documentation needed.
- [ ] Documentation included in this PR.
- [ ] **[For Experimental Features]** Documentation to be submitted in a
separate PR.

# PR Checklist\*

- [ ] I have tested the changes locally.
- [ ] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
TomAFrench authored Apr 2, 2024
1 parent 0d3d5fd commit 6ee645a
Show file tree
Hide file tree
Showing 25 changed files with 43 additions and 129 deletions.
2 changes: 1 addition & 1 deletion acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub(crate) struct BackendError(#[from] Error);

impl From<FeatureError> for BackendError {
fn from(value: FeatureError) -> Self {
value.into()
BackendError(Error::FromFeature(value))
}
}

Expand Down
5 changes: 3 additions & 2 deletions acvm-repo/brillig_vm/src/black_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@ fn black_box_function_from_op(op: &BlackBoxOp) -> BlackBoxFunc {
#[cfg(test)]
mod test {
use acir::brillig::{BlackBoxOp, MemoryAddress};
use acvm_blackbox_solver::StubbedBlackBoxSolver;

use crate::{
black_box::{evaluate_black_box, to_u8_vec, to_value_vec},
DummyBlackBoxSolver, HeapArray, HeapVector, Memory,
HeapArray, HeapVector, Memory,
};

#[test]
Expand All @@ -280,7 +281,7 @@ mod test {
output: HeapArray { pointer: 2.into(), size: 32 },
};

evaluate_black_box(&op, &DummyBlackBoxSolver, &mut memory).unwrap();
evaluate_black_box(&op, &StubbedBlackBoxSolver, &mut memory).unwrap();

let result = memory.read_slice(MemoryAddress(result_pointer), 32);

Expand Down
75 changes: 13 additions & 62 deletions acvm-repo/brillig_vm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use acir::brillig::{
HeapVector, MemoryAddress, Opcode, ValueOrArray,
};
use acir::FieldElement;
use acvm_blackbox_solver::{BlackBoxFunctionSolver, BlackBoxResolutionError};
use acvm_blackbox_solver::BlackBoxFunctionSolver;
use arithmetic::{evaluate_binary_field_op, evaluate_binary_int_op, BrilligArithmeticError};
use black_box::evaluate_black_box;
use num_bigint::BigUint;
Expand Down Expand Up @@ -593,59 +593,10 @@ impl<'a, B: BlackBoxFunctionSolver> VM<'a, B> {
}
}

pub(crate) struct DummyBlackBoxSolver;

impl BlackBoxFunctionSolver for DummyBlackBoxSolver {
fn schnorr_verify(
&self,
_public_key_x: &FieldElement,
_public_key_y: &FieldElement,
_signature: &[u8],
_message: &[u8],
) -> Result<bool, BlackBoxResolutionError> {
Ok(true)
}
fn pedersen_commitment(
&self,
_inputs: &[FieldElement],
_domain_separator: u32,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
Ok((2_u128.into(), 3_u128.into()))
}
fn pedersen_hash(
&self,
_inputs: &[FieldElement],
_domain_separator: u32,
) -> Result<FieldElement, BlackBoxResolutionError> {
Ok(6_u128.into())
}
fn fixed_base_scalar_mul(
&self,
_low: &FieldElement,
_high: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
Ok((4_u128.into(), 5_u128.into()))
}
fn ec_add(
&self,
_input1_x: &FieldElement,
_input1_y: &FieldElement,
_input2_x: &FieldElement,
_input2_y: &FieldElement,
) -> Result<(FieldElement, FieldElement), BlackBoxResolutionError> {
Ok((5_u128.into(), 6_u128.into()))
}
fn poseidon2_permutation(
&self,
_input: &[FieldElement],
len: u32,
) -> Result<Vec<FieldElement>, BlackBoxResolutionError> {
Ok(vec![0_u128.into(); len as usize])
}
}

#[cfg(test)]
mod tests {
use acvm_blackbox_solver::StubbedBlackBoxSolver;

use super::*;

#[test]
Expand All @@ -662,7 +613,7 @@ mod tests {

// Start VM
let opcodes = [calldata_copy];
let mut vm = VM::new(calldata, &opcodes, vec![], &DummyBlackBoxSolver);
let mut vm = VM::new(calldata, &opcodes, vec![], &StubbedBlackBoxSolver);

// Process a single VM opcode
//
Expand Down Expand Up @@ -706,7 +657,7 @@ mod tests {
opcodes.push(Opcode::Jump { location: 3 });
opcodes.push(Opcode::JumpIf { condition: destination, location: 4 });

let mut vm = VM::new(calldata, &opcodes, vec![], &DummyBlackBoxSolver);
let mut vm = VM::new(calldata, &opcodes, vec![], &StubbedBlackBoxSolver);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);
Expand Down Expand Up @@ -763,7 +714,7 @@ mod tests {
jump_if_not_opcode,
add_opcode,
];
let mut vm = VM::new(calldata, &opcodes, vec![], &DummyBlackBoxSolver);
let mut vm = VM::new(calldata, &opcodes, vec![], &StubbedBlackBoxSolver);
let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);

Expand Down Expand Up @@ -811,7 +762,7 @@ mod tests {
},
Opcode::Stop { return_data_offset: 1, return_data_size: 1 },
];
let mut vm = VM::new(calldata, opcodes, vec![], &DummyBlackBoxSolver);
let mut vm = VM::new(calldata, opcodes, vec![], &StubbedBlackBoxSolver);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);
Expand Down Expand Up @@ -842,7 +793,7 @@ mod tests {
Opcode::Mov { destination: MemoryAddress::from(2), source: MemoryAddress::from(0) };

let opcodes = &[calldata_copy, mov_opcode];
let mut vm = VM::new(calldata, opcodes, vec![], &DummyBlackBoxSolver);
let mut vm = VM::new(calldata, opcodes, vec![], &StubbedBlackBoxSolver);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);
Expand Down Expand Up @@ -898,7 +849,7 @@ mod tests {
condition: MemoryAddress(1),
},
];
let mut vm = VM::new(calldata, opcodes, vec![], &DummyBlackBoxSolver);
let mut vm = VM::new(calldata, opcodes, vec![], &StubbedBlackBoxSolver);

let status = vm.process_opcode();
assert_eq!(status, VMStatus::InProgress);
Expand Down Expand Up @@ -981,7 +932,7 @@ mod tests {
.chain(cast_opcodes)
.chain([equal_opcode, not_equal_opcode, less_than_opcode, less_than_equal_opcode])
.collect();
let mut vm = VM::new(calldata, &opcodes, vec![], &DummyBlackBoxSolver);
let mut vm = VM::new(calldata, &opcodes, vec![], &StubbedBlackBoxSolver);

// Calldata copy
let status = vm.process_opcode();
Expand Down Expand Up @@ -1276,14 +1227,14 @@ mod tests {
fn brillig_execute_and_get_vm(
calldata: Vec<FieldElement>,
opcodes: &[Opcode],
) -> VM<'_, DummyBlackBoxSolver> {
let mut vm = VM::new(calldata, opcodes, vec![], &DummyBlackBoxSolver);
) -> VM<'_, StubbedBlackBoxSolver> {
let mut vm = VM::new(calldata, opcodes, vec![], &StubbedBlackBoxSolver);
brillig_execute(&mut vm);
assert_eq!(vm.call_stack, vec![]);
vm
}

fn brillig_execute(vm: &mut VM<DummyBlackBoxSolver>) {
fn brillig_execute(vm: &mut VM<StubbedBlackBoxSolver>) {
loop {
let status = vm.process_opcode();
if matches!(status, VMStatus::Finished { .. } | VMStatus::ForeignCallWait { .. }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ pub fn inject_compute_note_hash_and_nullifier(
Ok(())
}

fn generate_compute_note_hash_and_nullifier(note_types: &Vec<String>) -> NoirFunction {
fn generate_compute_note_hash_and_nullifier(note_types: &[String]) -> NoirFunction {
let function_source = generate_compute_note_hash_and_nullifier_source(note_types);

let (function_ast, errors) = parse_program(&function_source);
Expand All @@ -140,7 +140,7 @@ fn generate_compute_note_hash_and_nullifier(note_types: &Vec<String>) -> NoirFun
function_ast.functions.remove(0)
}

fn generate_compute_note_hash_and_nullifier_source(note_types: &Vec<String>) -> String {
fn generate_compute_note_hash_and_nullifier_source(note_types: &[String]) -> String {
// TODO(#4649): The serialized_note parameter is a fixed-size array, but we don't know what length it should have.
// For now we hardcode it to 20, which is the same as MAX_NOTE_FIELDS_LENGTH.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl BrilligArtifact {
self.byte_code.append(&mut byte_code);

// Remove all resolved external calls and transform them to jumps
let is_resolved = |label: &Label| self.labels.get(label).is_some();
let is_resolved = |label: &Label| self.labels.contains_key(label);

let resolved_external_calls = self
.unresolved_external_call_labels
Expand Down
15 changes: 6 additions & 9 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2502,16 +2502,13 @@ mod test {
check_call_opcode(&main_opcodes[0], 1, vec![Witness(0), Witness(1)], vec![Witness(2)]);
check_call_opcode(&main_opcodes[1], 1, vec![Witness(0), Witness(1)], vec![Witness(3)]);

match &main_opcodes[2] {
Opcode::AssertZero(expr) => {
assert_eq!(expr.linear_combinations[0].0, FieldElement::from(1u128));
assert_eq!(expr.linear_combinations[0].1, Witness(2));
if let Opcode::AssertZero(expr) = &main_opcodes[2] {
assert_eq!(expr.linear_combinations[0].0, FieldElement::from(1u128));
assert_eq!(expr.linear_combinations[0].1, Witness(2));

assert_eq!(expr.linear_combinations[1].0, FieldElement::from(-1i128));
assert_eq!(expr.linear_combinations[1].1, Witness(3));
assert_eq!(expr.q_c, FieldElement::from(0u128));
}
_ => {}
assert_eq!(expr.linear_combinations[1].0, FieldElement::from(-1i128));
assert_eq!(expr.linear_combinations[1].1, Witness(3));
assert_eq!(expr.q_c, FieldElement::from(0u128));
}
}

Expand Down
9 changes: 2 additions & 7 deletions compiler/noirc_evaluator/src/ssa/ir/dom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,8 @@ mod tests {
use crate::ssa::{
function_builder::FunctionBuilder,
ir::{
basic_block::BasicBlockId,
dfg::CallStack,
dom::DominatorTree,
function::{Function, InlineType, RuntimeType},
instruction::TerminatorInstruction,
map::Id,
types::Type,
basic_block::BasicBlockId, dfg::CallStack, dom::DominatorTree, function::Function,
instruction::TerminatorInstruction, map::Id, types::Type,
},
};

Expand Down
7 changes: 1 addition & 6 deletions compiler/noirc_evaluator/src/ssa/ir/post_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ impl PostOrder {
mod tests {
use crate::ssa::{
function_builder::FunctionBuilder,
ir::{
function::{Function, InlineType, RuntimeType},
map::Id,
post_order::PostOrder,
types::Type,
},
ir::{function::Function, map::Id, post_order::PostOrder, types::Type},
};

#[test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ mod test {
use crate::ssa::{
function_builder::FunctionBuilder,
ir::{
function::{InlineType, RuntimeType},
instruction::{Binary, BinaryOp, Instruction},
map::Id,
types::Type,
Expand Down
1 change: 0 additions & 1 deletion compiler/noirc_evaluator/src/ssa/opt/constant_folding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ mod test {
use crate::ssa::{
function_builder::FunctionBuilder,
ir::{
function::{InlineType, RuntimeType},
instruction::{Binary, BinaryOp, Instruction, TerminatorInstruction},
map::Id,
types::Type,
Expand Down
1 change: 0 additions & 1 deletion compiler/noirc_evaluator/src/ssa/opt/die.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ mod test {
use crate::ssa::{
function_builder::FunctionBuilder,
ir::{
function::{InlineType, RuntimeType},
instruction::{BinaryOp, Intrinsic},
map::Id,
types::Type,
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/opt/flatten_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ mod test {
function_builder::FunctionBuilder,
ir::{
dfg::DataFlowGraph,
function::{Function, InlineType, RuntimeType},
function::Function,
instruction::{BinaryOp, Instruction, Intrinsic, TerminatorInstruction},
map::Id,
types::Type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,7 @@ mod test {

use crate::ssa::{
function_builder::FunctionBuilder,
ir::{
cfg::ControlFlowGraph,
function::{InlineType, RuntimeType},
map::Id,
types::Type,
},
ir::{cfg::ControlFlowGraph, map::Id, types::Type},
opt::flatten_cfg::branch_analysis::find_branch_ends,
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/opt/inlining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ mod test {
function_builder::FunctionBuilder,
ir::{
basic_block::BasicBlockId,
function::{InlineType, RuntimeType},
function::InlineType,
instruction::{BinaryOp, Intrinsic, TerminatorInstruction},
map::Id,
types::Type,
Expand Down
1 change: 0 additions & 1 deletion compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ mod tests {
ir::{
basic_block::BasicBlockId,
dfg::DataFlowGraph,
function::{InlineType, RuntimeType},
instruction::{BinaryOp, Instruction, Intrinsic, TerminatorInstruction},
map::Id,
types::Type,
Expand Down
8 changes: 2 additions & 6 deletions compiler/noirc_evaluator/src/ssa/opt/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,12 +166,8 @@ mod test {
use crate::ssa::{
function_builder::FunctionBuilder,
ir::{
basic_block::BasicBlockId,
dfg::DataFlowGraph,
function::{InlineType, RuntimeType},
instruction::Instruction,
map::Id,
types::Type,
basic_block::BasicBlockId, dfg::DataFlowGraph, function::RuntimeType,
instruction::Instruction, map::Id, types::Type,
},
};

Expand Down
1 change: 0 additions & 1 deletion compiler/noirc_evaluator/src/ssa/opt/simplify_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ mod test {
use crate::ssa::{
function_builder::FunctionBuilder,
ir::{
function::{InlineType, RuntimeType},
instruction::{BinaryOp, TerminatorInstruction},
map::Id,
types::Type,
Expand Down
7 changes: 1 addition & 6 deletions compiler/noirc_evaluator/src/ssa/opt/unrolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,7 @@ impl<'f> LoopIteration<'f> {
mod tests {
use crate::ssa::{
function_builder::FunctionBuilder,
ir::{
function::{InlineType, RuntimeType},
instruction::BinaryOp,
map::Id,
types::Type,
},
ir::{instruction::BinaryOp, map::Id, types::Type},
};

#[test]
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/lexer/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ mod tests {
.as_ref()
.map(|token_discriminator| {
discriminant(token_discriminator)
== discriminant(&next_token.token())
== discriminant(next_token.token())
})
.unwrap_or(true);

Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1242,7 +1242,7 @@ where
mod test {
use super::test_helpers::*;
use super::*;
use crate::{ArrayLiteral, Literal};
use crate::ArrayLiteral;

#[test]
fn parse_infix() {
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_frontend/src/parser/parser/literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ mod test {
Case { source: r#" r#"foo" "#, expect: "(none)", errors: 2 },
// empty string
Case { source: r#"r"""#, expect: r#"r"""#, errors: 0 },
#[allow(clippy::needless_raw_string_hashes)]
Case { source: r####"r###""###"####, expect: r####"r###""###"####, errors: 0 },
// miscellaneous
Case { source: r##" r#\"foo\"# "##, expect: "plain::r", errors: 2 },
Expand Down
Loading

0 comments on commit 6ee645a

Please sign in to comment.