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: remove dead code from noirc_evaluator #2822

Merged
merged 2 commits into from
Sep 25, 2023
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
90 changes: 0 additions & 90 deletions compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
FieldElement,
};
use acvm::{BlackBoxFunctionSolver, BlackBoxResolutionError};
use fxhash::FxHashMap as HashMap;

Check warning on line 23 in compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (fxhash)
use iter_extended::{try_vecmap, vecmap};
use std::{borrow::Cow, hash::Hash};

Expand Down Expand Up @@ -65,20 +65,6 @@
pub(crate) fn unsigned(bit_size: u32) -> Self {
AcirType::NumericType(NumericType::Unsigned { bit_size })
}

/// Returns a boolean type
fn boolean() -> Self {
AcirType::NumericType(NumericType::Unsigned { bit_size: 1 })
}

/// True if type is signed
pub(crate) fn is_signed(&self) -> bool {
let numeric_type = match self {
AcirType::NumericType(numeric_type) => numeric_type,
AcirType::Array(_, _) => return false,
};
matches!(numeric_type, NumericType::Signed { .. })
}
}

impl From<SsaType> for AcirType {
Expand Down Expand Up @@ -290,7 +276,7 @@
let inverted_var = self.add_data(AcirVarData::Const(constant.inverse()));

// Check that the inverted var is valid.
// This check prevents invalid divisons by zero.

Check warning on line 279 in compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (divisons)
let should_be_one = self.mul_var(inverted_var, var)?;
self.maybe_eq_predicate(should_be_one, predicate)?;

Expand All @@ -310,24 +296,13 @@
let inverted_var = Self::expect_one_var(results);

// Check that the inverted var is valid.
// This check prevents invalid divisons by zero.

Check warning on line 299 in compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (divisons)
let should_be_one = self.mul_var(inverted_var, var)?;
self.maybe_eq_predicate(should_be_one, predicate)?;

Ok(inverted_var)
}

// Constrains `var` to be equal to the constant value `1`
pub(crate) fn assert_eq_one(
&mut self,
var: AcirVar,
assert_message: Option<String>,
) -> Result<(), RuntimeError> {
let one = self.add_constant(FieldElement::one());
self.assert_eq_var(var, one, assert_message)?;
Ok(())
}

// Constrains `var` to be equal to predicate if the predicate is true
// or to be equal to 0 if the predicate is false.
//
Expand Down Expand Up @@ -557,31 +532,6 @@
self.sub_var(max, x)
}

/// Returns an `AcirVar` that is constrained to be `lhs << rhs`.
///
/// We convert left shifts to multiplications, so this is equivalent to
/// `lhs * 2^rhs`.
///
/// We currently require `rhs` to be a constant
/// however this can be extended, see #1478.
pub(crate) fn shift_left_var(
&mut self,
lhs: AcirVar,
rhs: AcirVar,
_typ: AcirType,
) -> Result<AcirVar, RuntimeError> {
let rhs_data = &self.vars[&rhs];

// Compute 2^{rhs}
let two_pow_rhs = match rhs_data.as_constant() {
Some(exponent) => FieldElement::from(2_i128).pow(&exponent),
None => unimplemented!("rhs must be a constant when doing a right shift"),
};
let two_pow_rhs_var = self.add_constant(two_pow_rhs);

self.mul_var(lhs, two_pow_rhs_var)
}

/// Returns the quotient and remainder such that lhs = rhs * quotient + remainder
fn euclidean_division_var(
&mut self,
Expand All @@ -606,7 +556,7 @@
/// Returns the quotient and remainder such that lhs = rhs * quotient + remainder
/// and |remainder| < |rhs|
/// and remainder has the same sign than lhs
/// Note that this is not the euclidian division, where we have instead remainder < |rhs|

Check warning on line 559 in compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (euclidian)
fn signed_division_var(
&mut self,
lhs: AcirVar,
Expand Down Expand Up @@ -635,35 +585,6 @@
Ok(remainder)
}

/// Returns an `AcirVar` that is constrained to be `lhs >> rhs`.
///
/// We convert right shifts to divisions, so this is equivalent to
/// `lhs / 2^rhs`.
///
/// We currently require `rhs` to be a constant
/// however this can be extended, see #1478.
///
/// This code is doing a field division instead of an integer division,
/// see #1479 about how this is expected to change.
pub(crate) fn shift_right_var(
&mut self,
lhs: AcirVar,
rhs: AcirVar,
typ: AcirType,
predicate: AcirVar,
) -> Result<AcirVar, RuntimeError> {
let rhs_data = &self.vars[&rhs];

// Compute 2^{rhs}
let two_pow_rhs = match rhs_data.as_constant() {
Some(exponent) => FieldElement::from(2_i128).pow(&exponent),
None => unimplemented!("rhs must be a constant when doing a right shift"),
};
let two_pow_rhs_var = self.add_constant(two_pow_rhs);

self.div_var(lhs, two_pow_rhs_var, typ, predicate)
}

/// Converts the `AcirVar` to a `Witness` if it hasn't been already, and appends it to the
/// `GeneratedAcir`'s return witnesses.
pub(crate) fn return_var(&mut self, acir_var: AcirVar) -> Result<(), InternalError> {
Expand Down Expand Up @@ -691,7 +612,7 @@
}

/// Returns an `AcirVar` which will be constrained to be lhs mod 2^{rhs}
/// In order to do this, we 'simply' perform euclidian division of lhs by 2^{rhs}

Check warning on line 615 in compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (euclidian)
/// The remainder of the division is then lhs mod 2^{rhs}
pub(crate) fn truncate_var(
&mut self,
Expand Down Expand Up @@ -897,17 +818,6 @@
self.radix_decompose(endian, input_var, two_var, limb_count_var, result_element_type)
}

/// Flatten the given Vector of AcirValues into a single vector of only variables.
/// Each AcirValue::Array in the vector is recursively flattened, so each element
/// will flattened into the resulting Vec. E.g. flatten_values([1, [2, 3]) == [1, 2, 3].
fn flatten_values(values: Vec<AcirValue>) -> Vec<AcirVar> {
let mut acir_vars = Vec::with_capacity(values.len());
for value in values {
Self::flatten_value(&mut acir_vars, value);
}
acir_vars
}

/// Recursive helper for flatten_values to flatten a single AcirValue into the result vector.
pub(crate) fn flatten_value(acir_vars: &mut Vec<AcirVar>, value: AcirValue) {
match value {
Expand Down Expand Up @@ -1027,7 +937,7 @@
}

/// Recursively create acir values for returned arrays. This is necessary because a brillig returned array can have nested arrays as elements.
/// A singular array of witnesses is collected for a top level array, by deflattening the assigned witnesses at each level.

Check warning on line 940 in compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/acir_variable.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (deflattening)
fn brillig_array_output(
&mut self,
element_types: &[AcirType],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,8 @@
}

/// Signed division lhs / rhs
/// We derive the signed division from the unsigned euclidian division.

Check warning on line 361 in compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (euclidian)
/// note that this is not euclidian division!

Check warning on line 362 in compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (euclidian)
// if x is a signed integer, then sign(x)x >= 0
// so if a and b are signed integers, we can do the unsigned division:
// sign(a)a = q1*sign(b)b + r1
Expand Down Expand Up @@ -581,10 +581,6 @@
num_bits::<u128>() as u32 - a.leading_zeros()
}

fn bit_size_u32(a: u32) -> u32 where {
num_bits::<u32>() as u32 - a.leading_zeros()
}

assert!(
bits < FieldElement::max_num_bits(),
"range check with bit size of the prime field is not implemented yet"
Expand Down Expand Up @@ -624,21 +620,6 @@
Ok(())
}

/// Computes the expression x(x-1)
///
/// If the above is constrained to zero, then it can only be
/// true, iff x equals zero or one.
fn boolean_expr(&mut self, expr: &Expression) -> Expression {
let expr_as_witness = self.create_witness_for_expression(expr);
let mut expr_squared = Expression::default();
expr_squared.push_multiplication_term(
FieldElement::one(),
expr_as_witness,
expr_as_witness,
);
&expr_squared - expr
}

/// Adds an inversion brillig opcode.
///
/// This code will invert `expr` without applying constraints
Expand Down Expand Up @@ -818,7 +799,7 @@
let two_max_bits: FieldElement = two.pow(&FieldElement::from(max_bits as i128));
let comparison_evaluation = (a - b) + two_max_bits;

// Euclidian division by 2^{max_bits} : 2^{max_bits} + a - b = q * 2^{max_bits} + r

Check warning on line 802 in compiler/noirc_evaluator/src/ssa/acir_gen/acir_ir/generated_acir.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (Euclidian)
//
// 2^{max_bits} is of max_bits+1 bit size
// If a>b, then a-b is less than 2^{max_bits} - 1, so 2^{max_bits} + a - b is less than 2^{max_bits} + 2^{max_bits} - 1 = 2^{max_bits+1} - 1
Expand Down
16 changes: 0 additions & 16 deletions compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
acir::{circuit::opcodes::BlockId, native_types::Expression},
FieldElement,
};
use fxhash::FxHashMap as HashMap;

Check warning on line 32 in compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (fxhash)
use im::Vector;
use iter_extended::{try_vecmap, vecmap};
use noirc_frontend::Distinctness;
Expand Down Expand Up @@ -1657,15 +1657,6 @@
acir_vars
}

fn bit_count(&self, lhs: ValueId, dfg: &DataFlowGraph) -> u32 {
match dfg.type_of_value(lhs) {
Type::Numeric(NumericType::Signed { bit_size }) => bit_size,
Type::Numeric(NumericType::Unsigned { bit_size }) => bit_size,
Type::Numeric(NumericType::NativeField) => FieldElement::max_num_bits(),
_ => 0,
}
}

/// Convert a Vec<AcirVar> into a Vec<AcirValue> using the given result ids.
/// If the type of a result id is an array, several acir vars are collected into
/// a single AcirValue::Array of the same length.
Expand Down Expand Up @@ -1706,13 +1697,6 @@
}
}
}

/// Creates a default, meaningless value meant only to be a valid value of the given type.
fn create_default_value(&mut self, param_type: &Type) -> Result<AcirValue, RuntimeError> {
self.create_value_from_type(param_type, &mut |this, _| {
Ok(this.acir_context.add_constant(FieldElement::zero()))
})
}
}

#[cfg(test)]
Expand Down
5 changes: 0 additions & 5 deletions compiler/noirc_evaluator/src/ssa/function_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,11 +342,6 @@ impl FunctionBuilder {
pub(crate) fn import_intrinsic_id(&mut self, intrinsic: Intrinsic) -> ValueId {
self.current_function.dfg.import_intrinsic(intrinsic)
}

/// Removes the given instruction from the current block or panics otherwise.
pub(crate) fn remove_instruction_from_current_block(&mut self, instruction: InstructionId) {
self.current_function.dfg[self.current_block].remove_instruction(instruction);
}
}

impl std::ops::Index<ValueId> for FunctionBuilder {
Expand Down
9 changes: 0 additions & 9 deletions compiler/noirc_evaluator/src/ssa/ir/basic_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,13 +145,4 @@ impl BasicBlock {
None => vec![].into_iter(),
}
}

/// Removes the given instruction from this block if present or panics otherwise.
pub(crate) fn remove_instruction(&mut self, instruction: InstructionId) {
let index =
self.instructions.iter().position(|id| *id == instruction).unwrap_or_else(|| {
panic!("remove_instruction: No such instruction {instruction:?} in block")
});
self.instructions.remove(index);
}
}
5 changes: 1 addition & 4 deletions compiler/noirc_evaluator/src/ssa/ir/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::ssa::ir::instruction::SimplifyResult;

use super::{
basic_block::{BasicBlock, BasicBlockId},
function::{FunctionId, Signature},
function::FunctionId,
instruction::{
Instruction, InstructionId, InstructionResultType, Intrinsic, TerminatorInstruction,
},
Expand Down Expand Up @@ -61,9 +61,6 @@ pub(crate) struct DataFlowGraph {
/// represented by only 1 ValueId within this function.
foreign_functions: HashMap<String, ValueId>,

/// Function signatures of external methods
signatures: DenseMap<Signature>,

/// All blocks in a function
blocks: DenseMap<BasicBlock>,

Expand Down
Loading