Skip to content

Commit

Permalink
chore: fix warnings (#6863)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench authored Dec 19, 2024
1 parent 0d7642c commit 021d62c
Show file tree
Hide file tree
Showing 39 changed files with 97 additions and 124 deletions.
4 changes: 2 additions & 2 deletions acvm-repo/acir/src/circuit/black_box_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ pub enum BlackBoxFunc {
/// https://tools.ietf.org/html/rfc7693
/// - inputs are a byte array, i.e a vector of (witness, 8)
/// - output is a byte array of length 32, i.e. an array of 32
/// (witness, 8), constrained to be the blake2s of the inputs.
/// (witness, 8), constrained to be the blake2s of the inputs.
Blake2s,

/// Computes the Blake3 hash of the inputs
/// - inputs are a byte array, i.e a vector of (witness, 8)
/// - output is a byte array of length 32, i.e an array of 32
/// (witness, 8), constrained to be the blake3 of the inputs.
/// (witness, 8), constrained to be the blake3 of the inputs.
Blake3,

/// Verifies a ECDSA signature over the secp256k1 curve.
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ impl<F: for<'a> Deserialize<'a>> Program<F> {
where
D: Deserializer<'de>,
{
let bytecode_b64: String = serde::Deserialize::deserialize(deserializer)?;
let bytecode_b64: String = Deserialize::deserialize(deserializer)?;
let program_bytes = base64::engine::general_purpose::STANDARD
.decode(bytecode_b64)
.map_err(D::Error::custom)?;
Expand Down
1 change: 1 addition & 0 deletions acvm-repo/acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub enum Opcode<F> {
/// - **express a constraint** on witnesses; for instance to express that a
/// witness `w` is a boolean, you can add the opcode: `w*w-w=0`
/// - or, to **compute the value** of an arithmetic operation of some inputs.
///
/// For instance, to multiply two witnesses `x` and `y`, you would use the
/// opcode `z-x*y=0`, which would constrain `z` to be `x*y`.
///
Expand Down
9 changes: 5 additions & 4 deletions acvm-repo/acir/src/native_types/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ impl<F> Expression<F> {
///
/// - `mul_term` in an expression contains degree-2 terms
/// - `linear_combinations` contains degree-1 terms
///
/// Hence, it is sufficient to check that there are no `mul_terms`
///
/// Examples:
Expand All @@ -98,11 +99,11 @@ impl<F> Expression<F> {
/// Returns `true` if the expression can be seen as a degree-1 univariate polynomial
///
/// - `mul_terms` in an expression can be univariate, however unless the coefficient
/// is zero, it is always degree-2.
/// is zero, it is always degree-2.
/// - `linear_combinations` contains the sum of degree-1 terms, these terms do not
/// need to contain the same variable and so it can be multivariate. However, we
/// have thus far only checked if `linear_combinations` contains one term, so this
/// method will return false, if the `Expression` has not been simplified.
/// need to contain the same variable and so it can be multivariate. However, we
/// have thus far only checked if `linear_combinations` contains one term, so this
/// method will return false, if the `Expression` has not been simplified.
///
/// Hence, we check in the simplest case if an expression is a degree-1 univariate,
/// by checking if it contains no `mul_terms` and it contains one `linear_combination` term.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ mod tests {
],
q_c: FieldElement::zero(),
}),
Opcode::BlackBoxFuncCall(acir::circuit::opcodes::BlackBoxFuncCall::RANGE {
Opcode::BlackBoxFuncCall(BlackBoxFuncCall::RANGE {
input: FunctionInput::witness(Witness(3), 32),
}),
];
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/src/pwg/blackbox/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::pwg::OpcodeResolutionError;

/// Resolve BigInt opcodes by storing BigInt values (and their moduli) by their ID in the BigIntSolver
/// - When it encounters a bigint operation opcode, it performs the operation on the stored values
/// and store the result using the provided ID.
/// and store the result using the provided ID.
/// - When it gets a to_bytes opcode, it simply looks up the value and resolves the output witness accordingly.
#[derive(Default)]
pub(crate) struct AcvmBigIntSolver {
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acvm/tests/solver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1457,7 +1457,7 @@ fn poseidon2_permutation_zeroes() {
#[test]
fn sha256_compression_zeros() {
let results = solve_array_input_blackbox_call(
[(FieldElement::zero(), false); 24].try_into().unwrap(),
[(FieldElement::zero(), false); 24].into(),
8,
None,
sha256_compression_op,
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/blackbox_solver/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::BlackBoxResolutionError;

/// Resolve BigInt opcodes by storing BigInt values (and their moduli) by their ID in a HashMap:
/// - When it encounters a bigint operation opcode, it performs the operation on the stored values
/// and store the result using the provided ID.
/// and store the result using the provided ID.
/// - When it gets a to_bytes opcode, it simply looks up the value and resolves the output witness accordingly.
#[derive(Default, Debug, Clone, PartialEq, Eq)]

Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub fn report<'files>(
let color_choice =
if std::io::stderr().is_terminal() { ColorChoice::Auto } else { ColorChoice::Never };
let writer = StandardStream::stderr(color_choice);
let config = codespan_reporting::term::Config::default();
let config = term::Config::default();

let stack_trace = stack_trace(files, &custom_diagnostic.call_stack);
let diagnostic = convert_diagnostic(custom_diagnostic, file, stack_trace, deny_warnings);
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/src/acir/acir_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ impl<F: AcirField, B: BlackBoxFunctionSolver<F>> AcirContext<F, B> {
offset: AcirVar,
bits: u32,
) -> Result<(), RuntimeError> {
#[allow(unused_qualifications)]
const fn num_bits<T>() -> usize {
std::mem::size_of::<T>() * 8
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_evaluator/src/acir/generated_acir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@ impl<F: AcirField> GeneratedAcir<F> {
/// This implies that either `y` or `t` or both is `0`.
/// - If `t == 0`, then by definition `t == 0`.
/// - If `y == 0`, this does not mean anything at this point in time, due to it having no
/// constraints.
/// constraints.
///
/// Naively, we could apply the following constraint: `y == 1 - t`.
/// This along with the previous `y * t == 0` constraint means that
Expand Down Expand Up @@ -604,7 +604,7 @@ impl<F: AcirField> GeneratedAcir<F> {
) {
// Check whether we have a call to this Brillig function already exists.
// This helps us optimize the Brillig metadata to only be stored once per Brillig entry point.
let inserted_func_before = self.brillig_locations.get(&brillig_function_index).is_some();
let inserted_func_before = self.brillig_locations.contains_key(&brillig_function_index);

let opcode =
AcirOpcode::BrilligCall { id: brillig_function_index, inputs, outputs, predicate };
Expand Down
34 changes: 17 additions & 17 deletions compiler/noirc_evaluator/src/acir/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
//! This file holds the pass to convert from Noir's SSA IR to ACIR.
use fxhash::FxHashMap as HashMap;
use im::Vector;
use std::collections::{BTreeMap, HashSet};
use std::fmt::Debug;

Expand Down Expand Up @@ -248,7 +247,7 @@ impl Debug for AcirDynamicArray {
#[derive(Debug, Clone)]
pub(crate) enum AcirValue {
Var(AcirVar, AcirType),
Array(Vector<AcirValue>),
Array(im::Vector<AcirValue>),
DynamicArray(AcirDynamicArray),
}

Expand Down Expand Up @@ -1118,7 +1117,7 @@ impl<'a> Context<'a> {
&mut self,
instruction: InstructionId,
dfg: &DataFlowGraph,
array: Vector<AcirValue>,
array: im::Vector<AcirValue>,
index: FieldElement,
store_value: Option<AcirValue>,
) -> Result<bool, RuntimeError> {
Expand Down Expand Up @@ -1303,7 +1302,7 @@ impl<'a> Context<'a> {
match typ {
Type::Numeric(_) => self.array_get_value(&Type::field(), call_data_block, offset),
Type::Array(arc, len) => {
let mut result = Vector::new();
let mut result = im::Vector::new();
for _i in 0..*len {
for sub_type in arc.iter() {
let element = self.get_from_call_data(offset, call_data_block, sub_type)?;
Expand Down Expand Up @@ -1394,7 +1393,7 @@ impl<'a> Context<'a> {
Ok(AcirValue::Var(read, typ))
}
Type::Array(element_types, len) => {
let mut values = Vector::new();
let mut values = im::Vector::new();
for _ in 0..len {
for typ in element_types.as_ref() {
values.push_back(self.array_get_value(typ, block_id, var_index)?);
Expand Down Expand Up @@ -1682,7 +1681,7 @@ impl<'a> Context<'a> {
let read = self.acir_context.read_from_memory(source, &index_var)?;
Ok::<AcirValue, RuntimeError>(AcirValue::Var(read, AcirType::field()))
})?;
let array: Vector<AcirValue> = init_values.into();
let array: im::Vector<AcirValue> = init_values.into();
self.initialize_array(destination, array_len, Some(AcirValue::Array(array)))?;
Ok(())
}
Expand Down Expand Up @@ -2053,8 +2052,9 @@ impl<'a> Context<'a> {
///
/// There are some edge cases to consider:
/// - Constants are not explicitly type casted, so we need to check for this and
/// return the type of the other operand, if we have a constant.
/// return the type of the other operand, if we have a constant.
/// - 0 is not seen as `Field 0` but instead as `Unit 0`
///
/// TODO: The latter seems like a bug, if we cannot differentiate between a function returning
/// TODO nothing and a 0.
///
Expand Down Expand Up @@ -2273,7 +2273,7 @@ impl<'a> Context<'a> {
let slice = self.convert_value(slice_contents, dfg);
let mut new_elem_size = Self::flattened_value_size(&slice);

let mut new_slice = Vector::new();
let mut new_slice = im::Vector::new();
self.slice_intrinsic_input(&mut new_slice, slice)?;

let elements_to_push = &arguments[2..];
Expand Down Expand Up @@ -2344,7 +2344,7 @@ impl<'a> Context<'a> {
let one = self.acir_context.add_constant(FieldElement::one());
let new_slice_length = self.acir_context.add_var(slice_length, one)?;

let mut new_slice = Vector::new();
let mut new_slice = im::Vector::new();
self.slice_intrinsic_input(&mut new_slice, slice)?;

let elements_to_push = &arguments[2..];
Expand Down Expand Up @@ -2418,7 +2418,7 @@ impl<'a> Context<'a> {
}

let slice = self.convert_value(slice_contents, dfg);
let mut new_slice = Vector::new();
let mut new_slice = im::Vector::new();
self.slice_intrinsic_input(&mut new_slice, slice)?;

let mut results = vec![
Expand All @@ -2444,7 +2444,7 @@ impl<'a> Context<'a> {

let slice = self.convert_value(slice_contents, dfg);

let mut new_slice = Vector::new();
let mut new_slice = im::Vector::new();
self.slice_intrinsic_input(&mut new_slice, slice)?;

let element_size = slice_typ.element_size();
Expand Down Expand Up @@ -2631,7 +2631,7 @@ impl<'a> Context<'a> {

let slice_size = Self::flattened_value_size(&slice);

let mut new_slice = Vector::new();
let mut new_slice = im::Vector::new();
self.slice_intrinsic_input(&mut new_slice, slice)?;

// Compiler sanity check
Expand Down Expand Up @@ -2783,7 +2783,7 @@ impl<'a> Context<'a> {

fn slice_intrinsic_input(
&mut self,
old_slice: &mut Vector<AcirValue>,
old_slice: &mut im::Vector<AcirValue>,
input: AcirValue,
) -> Result<(), RuntimeError> {
match input {
Expand Down Expand Up @@ -3356,8 +3356,8 @@ mod test {
// We have two normal Brillig functions that was called multiple times.
// We should have a single locations map for each function's debug metadata.
assert_eq!(main_acir.brillig_locations.len(), 2);
assert!(main_acir.brillig_locations.get(&BrilligFunctionId(0)).is_some());
assert!(main_acir.brillig_locations.get(&BrilligFunctionId(1)).is_some());
assert!(main_acir.brillig_locations.contains_key(&BrilligFunctionId(0)));
assert!(main_acir.brillig_locations.contains_key(&BrilligFunctionId(1)));
}

// Test that given multiple primitive operations that are represented by Brillig directives (e.g. invert/quotient),
Expand Down Expand Up @@ -3492,7 +3492,7 @@ mod test {
// We have one normal Brillig functions that was called twice.
// We should have a single locations map for each function's debug metadata.
assert_eq!(main_acir.brillig_locations.len(), 1);
assert!(main_acir.brillig_locations.get(&BrilligFunctionId(0)).is_some());
assert!(main_acir.brillig_locations.contains_key(&BrilligFunctionId(0)));
}

// Test that given both normal Brillig calls, Brillig stdlib calls, and non-inlined ACIR calls, that we accurately generate ACIR.
Expand Down Expand Up @@ -3585,7 +3585,7 @@ mod test {
);

assert_eq!(main_acir.brillig_locations.len(), 1);
assert!(main_acir.brillig_locations.get(&BrilligFunctionId(0)).is_some());
assert!(main_acir.brillig_locations.contains_key(&BrilligFunctionId(0)));

let foo_acir = &acir_functions[1];
let foo_opcodes = foo_acir.opcodes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl DependencyContext {
self.update_children(&arguments, &results);
}
},
Value::Function(callee) => match all_functions[&callee].runtime() {
Value::Function(callee) => match all_functions[callee].runtime() {
RuntimeType::Brillig(_) => {
// Record arguments/results for each Brillig call for the check
self.tainted.insert(
Expand Down Expand Up @@ -595,7 +595,7 @@ impl Context {
self.value_sets.push(instruction_arguments_and_results);
}
},
Value::Function(callee) => match all_functions[&callee].runtime() {
Value::Function(callee) => match all_functions[callee].runtime() {
RuntimeType::Brillig(_) => {
// For calls to Brillig functions we memorize the mapping of results to argument ValueId's and InstructionId's
// The latter are needed to produce the callstack later
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl FunctionBuilder {
for size in ssa_param_sizes {
let visibilities: Vec<DatabusVisibility> =
flattened_params_databus_visibility.drain(0..size).collect();
let visibility = visibilities.get(0).copied().unwrap_or(DatabusVisibility::None);
let visibility = visibilities.first().copied().unwrap_or(DatabusVisibility::None);
assert!(
visibilities.iter().all(|v| *v == visibility),
"inconsistent databus visibility for ssa param"
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ pub(crate) type InstructionId = Id<Instruction>;
/// These are similar to built-ins in other languages.
/// These can be classified under two categories:
/// - Opcodes which the IR knows the target machine has
/// special support for. (LowLevel)
/// special support for. (LowLevel)
/// - Opcodes which have no function definition in the
/// source code and must be processed by the IR.
/// source code and must be processed by the IR.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub(crate) enum Intrinsic {
ArrayLen,
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 @@ -34,7 +34,7 @@
//! the following transformations of certain instructions within the block are expected:
//!
//! 1. A constraint is multiplied by the condition and changes the constraint to
//! an equality with c:
//! an equality with c:
//!
//! constrain v0
//! ============
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
//!
//! The algorithm is split into two parts:
//! 1. The outer part:
//! A. An (unrolled) CFG can be though of as a linear sequence of blocks where some nodes split
//! off, but eventually rejoin to a new node and continue the linear sequence.
//! B. Follow this sequence in order, and whenever a split is found call
//! `find_join_point_of_branches` and then recur from the join point it returns until the
//! return instruction is found.
//! A. An (unrolled) CFG can be though of as a linear sequence of blocks where some nodes split
//! off, but eventually rejoin to a new node and continue the linear sequence.
//! B. Follow this sequence in order, and whenever a split is found call
//! `find_join_point_of_branches` and then recur from the join point it returns until the
//! return instruction is found.
//!
//! 2. The inner part defined by `find_join_point_of_branches`:
//! A. For each of the two branches in a jmpif block:
//! A. For each of the two branches in a jmpif block:
//! - Check if either has multiple predecessors. If so, it is a join point.
//! - If not, continue to search the linear sequence of successor blocks from that block.
//! - If another split point is found, recur in `find_join_point_of_branches`
Expand Down
8 changes: 5 additions & 3 deletions compiler/noirc_evaluator/src/ssa/opt/mem2reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@
//! - We also track the last instance of a load instruction to each address in a block.
//! If we see that the last load instruction was from the same address as the current load instruction,
//! we move to replace the result of the current load with the result of the previous load.
//!
//! This removal requires a couple conditions:
//! - No store occurs to that address before the next load,
//! - The address is not used as an argument to a call
//! - No store occurs to that address before the next load,
//! - The address is not used as an argument to a call
//!
//! This optimization helps us remove repeated loads for which there are not known values.
//! - On `Instruction::Store { address, value }`:
//! - If the address of the store is known:
Expand Down Expand Up @@ -200,7 +202,7 @@ impl<'f> PerFunctionContext<'f> {
.get(store_address)
.map_or(false, |expression| matches!(expression, Expression::Dereference(_)));

if self.last_loads.get(store_address).is_none()
if !self.last_loads.contains_key(store_address)
&& !store_alias_used
&& !is_dereference
{
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/opt/runtime_separation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl RuntimeSeparatorContext {

if within_brillig {
for called_func_id in called_functions.iter() {
let called_func = &ssa.functions[&called_func_id];
let called_func = &ssa.functions[called_func_id];
if matches!(called_func.runtime(), RuntimeType::Acir(_)) {
self.acir_functions_called_from_brillig.insert(*called_func_id);
}
Expand Down
Loading

0 comments on commit 021d62c

Please sign in to comment.