Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix clippy errors #4684

Merged
merged 5 commits into from
Apr 2, 2024
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
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 @@

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

Expand Down Expand Up @@ -242,7 +242,7 @@

/// Creates a pointer and allocates the bytes that the pointer references to, to the heap
pub(crate) fn allocate(&self, bytes: &[u8]) -> Result<WASMValue, Error> {
let ptr: i32 = self.call("bbmalloc", &bytes.len().into())?.try_into()?;

Check warning on line 245 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (bbmalloc)

let i32_bytes = ptr.to_be_bytes();
let u32_bytes = u32::from_be_bytes(i32_bytes);
Expand All @@ -261,10 +261,10 @@
let function_env = FunctionEnv::new(&mut store, memory.clone());
let custom_imports = imports! {
"env" => {
"logstr" => Function::new_typed_with_env(

Check warning on line 264 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (logstr)
&mut store,
&function_env,
logstr,

Check warning on line 267 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (logstr)
),
"memory" => memory.clone(),
},
Expand Down Expand Up @@ -307,17 +307,17 @@
wasm_bindgen_futures::JsFuture::from(js_module_promise).await.unwrap().into();

let js_instance_promise =
WebAssembly::instantiate_module(&js_module, &custom_imports.as_jsvalue(&store).into());

Check warning on line 310 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (jsvalue)
let js_instance = wasm_bindgen_futures::JsFuture::from(js_instance_promise).await.unwrap();
let module: wasmer::Module = (js_module, wasm_binary).into();
let instance: wasmer::Instance = Instance::from_jsvalue(&mut store, &module, &js_instance)

Check warning on line 313 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (jsvalue)
.map_err(|_| "Error while creating BlackBox Functions vendor instance")
.unwrap();

(instance, memory, store)
}

fn logstr(mut env: FunctionEnvMut<Memory>, ptr: i32) {

Check warning on line 320 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (logstr)
let (memory, store) = env.data_and_store_mut();
let memory_view = memory.view(&store);

Expand All @@ -339,7 +339,7 @@
let memory_view = memory.view(&store);
match memory_view.write(buf_ptr as u64, u8_buffer.as_mut_slice()) {
Ok(_) => {
0_i32 // __WASI_ESUCCESS

Check warning on line 342 in acvm-repo/bn254_blackbox_solver/src/wasm/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (ESUCCESS)
}
Err(_) => {
29_i32 // __WASI_EIO
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 @@
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 @@ -306,7 +306,7 @@
self.set_program_counter(*location)
}
Opcode::Const { destination, value, bit_size } => {
// Consts are not checked in runtime to fit in the bit size, since they can safely be checked statically.

Check warning on line 309 in acvm-repo/brillig_vm/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (Consts)
self.memory.write(*destination, MemoryValue::new(*value, *bit_size));
self.increment_program_counter()
}
Expand Down Expand Up @@ -593,59 +593,10 @@
}
}

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 @@

// 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 @@
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 All @@ -725,7 +676,7 @@
}

#[test]
fn jmpifnot_opcode() {

Check warning on line 679 in acvm-repo/brillig_vm/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (jmpifnot)
let calldata = vec![1u128.into(), 2u128.into()];

let calldata_copy = Opcode::CalldataCopy {
Expand Down Expand Up @@ -763,7 +714,7 @@
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 @@
},
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 @@
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 All @@ -860,7 +811,7 @@
}

#[test]
fn cmov_opcode() {

Check warning on line 814 in acvm-repo/brillig_vm/src/lib.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (cmov)
let calldata = vec![(0u128).into(), (1u128).into(), (2u128).into(), (3u128).into()];

let calldata_copy = Opcode::CalldataCopy {
Expand Down Expand Up @@ -898,7 +849,7 @@
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 @@
.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 @@
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
17 changes: 7 additions & 10 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2401,7 +2401,7 @@ mod test {
ssa::{
function_builder::FunctionBuilder,
ir::{
function::{FunctionId, InlineType, RuntimeType},
function::{FunctionId, InlineType},
instruction::BinaryOp,
map::Id,
types::Type,
Expand Down Expand Up @@ -2516,16 +2516,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
1 change: 0 additions & 1 deletion compiler/noirc_evaluator/src/ssa/function_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,6 @@ mod tests {
use acvm::FieldElement;

use crate::ssa::ir::{
function::{InlineType, RuntimeType},
instruction::{Endian, Intrinsic},
map::Id,
types::Type,
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
Loading
Loading