Skip to content

Commit

Permalink
chore: Delete unused brillig methods (#4887)
Browse files Browse the repository at this point in the history
# Description

## Problem\*

Leftover work from #4848 that I forgot to include

## Summary\*



## Additional Context



## Documentation\*

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

# PR Checklist\*

- [X] I have tested the changes locally.
- [X] I have formatted the changes with [Prettier](https://prettier.io/)
and/or `cargo fmt` on default settings.
  • Loading branch information
vezenovm authored Apr 23, 2024
1 parent 0c8175c commit 9704bd0
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 121 deletions.
91 changes: 0 additions & 91 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 @@ -1468,97 +1468,6 @@ impl AcirContext {
id
}

// TODO: Delete this method once we remove the `Brillig` opcode
pub(crate) fn brillig(
&mut self,
predicate: AcirVar,
generated_brillig: GeneratedBrillig,
inputs: Vec<AcirValue>,
outputs: Vec<AcirType>,
attempt_execution: bool,
unsafe_return_values: bool,
) -> Result<Vec<AcirValue>, RuntimeError> {
let b_inputs = try_vecmap(inputs, |i| -> Result<_, InternalError> {
match i {
AcirValue::Var(var, _) => Ok(BrilligInputs::Single(self.var_to_expression(var)?)),
AcirValue::Array(vars) => {
let mut var_expressions: Vec<Expression> = Vec::new();
for var in vars {
self.brillig_array_input(&mut var_expressions, var)?;
}
Ok(BrilligInputs::Array(var_expressions))
}
AcirValue::DynamicArray(AcirDynamicArray { block_id, .. }) => {
Ok(BrilligInputs::MemoryArray(block_id))
}
}
})?;

// Optimistically try executing the brillig now, if we can complete execution they just return the results.
// This is a temporary measure pending SSA optimizations being applied to Brillig which would remove constant-input opcodes (See #2066)
//
// We do _not_ want to do this in the situation where the `main` function is unconstrained, as if execution succeeds
// the entire program will be replaced with witness constraints to its outputs.
if attempt_execution {
if let Some(brillig_outputs) =
self.execute_brillig(&generated_brillig.byte_code, &b_inputs, &outputs)
{
return Ok(brillig_outputs);
}
}

// Otherwise we must generate ACIR for it and execute at runtime.
let mut b_outputs = Vec::new();
let outputs_var = vecmap(outputs, |output| match output {
AcirType::NumericType(_) => {
let witness_index = self.acir_ir.next_witness_index();
b_outputs.push(BrilligOutputs::Simple(witness_index));
let var = self.add_data(AcirVarData::Witness(witness_index));
AcirValue::Var(var, output.clone())
}
AcirType::Array(element_types, size) => {
let (acir_value, witnesses) = self.brillig_array_output(&element_types, size);
b_outputs.push(BrilligOutputs::Array(witnesses));
acir_value
}
});
let predicate = self.var_to_expression(predicate)?;
self.acir_ir.brillig(Some(predicate), generated_brillig, b_inputs, b_outputs);

fn range_constraint_value(
context: &mut AcirContext,
value: &AcirValue,
) -> Result<(), RuntimeError> {
match value {
AcirValue::Var(var, typ) => {
let numeric_type = match typ {
AcirType::NumericType(numeric_type) => numeric_type,
_ => unreachable!("`AcirValue::Var` may only hold primitive values"),
};
context.range_constrain_var(*var, numeric_type, None)?;
}
AcirValue::Array(values) => {
for value in values {
range_constraint_value(context, value)?;
}
}
AcirValue::DynamicArray(_) => {
unreachable!("Brillig opcodes cannot return dynamic arrays")
}
}
Ok(())
}

// This is a hack to ensure that if we're compiling a brillig entrypoint function then
// we don't also add a number of range constraints.
if !unsafe_return_values {
for output_var in &outputs_var {
range_constraint_value(self, output_var)?;
}
}
Ok(outputs_var)
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn brillig_call(
&mut self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{

use acvm::acir::{
circuit::{
brillig::{Brillig as AcvmBrillig, BrilligInputs, BrilligOutputs},
brillig::{BrilligInputs, BrilligOutputs},
opcodes::{BlackBoxFuncCall, FunctionInput, Opcode as AcirOpcode},
OpcodeLocation,
},
Expand Down Expand Up @@ -625,35 +625,6 @@ impl GeneratedAcir {
Ok(())
}

// TODO: Delete this method once we remove the `Brillig` opcode
pub(crate) fn brillig(
&mut self,
predicate: Option<Expression>,
generated_brillig: GeneratedBrillig,
inputs: Vec<BrilligInputs>,
outputs: Vec<BrilligOutputs>,
) {
let opcode = AcirOpcode::Brillig(AcvmBrillig {
inputs,
outputs,
bytecode: generated_brillig.byte_code,
predicate,
});
self.push_opcode(opcode);
for (brillig_index, call_stack) in generated_brillig.locations {
self.locations.insert(
OpcodeLocation::Brillig { acir_index: self.opcodes.len() - 1, brillig_index },
call_stack,
);
}
for (brillig_index, message) in generated_brillig.assert_messages {
self.assert_messages.insert(
OpcodeLocation::Brillig { acir_index: self.opcodes.len() - 1, brillig_index },
message,
);
}
}

pub(crate) fn brillig_call(
&mut self,
predicate: Option<Expression>,
Expand Down

0 comments on commit 9704bd0

Please sign in to comment.