Skip to content

Commit

Permalink
chore: remove dead code from noirc_evaluator
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Sep 25, 2023
1 parent 0490549 commit 99a626c
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 143 deletions.
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 @@ -60,20 +60,6 @@ impl AcirType {
pub(crate) fn field() -> Self {
AcirType::NumericType(NumericType::NativeField)
}

/// 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 @@ -312,17 +298,6 @@ impl AcirContext {
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 @@ -552,31 +527,6 @@ impl AcirContext {
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 Down Expand Up @@ -630,35 +580,6 @@ impl AcirContext {
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 @@ -892,17 +813,6 @@ impl AcirContext {
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
Original file line number Diff line number Diff line change
Expand Up @@ -581,10 +581,6 @@ impl GeneratedAcir {
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 @@ impl GeneratedAcir {
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
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 @@ -1401,15 +1401,6 @@ impl Context {
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 @@ -1450,13 +1441,6 @@ impl Context {
}
}
}

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

0 comments on commit 99a626c

Please sign in to comment.