Skip to content

Commit

Permalink
chore(ssa refactor): Pass predicate to brillig opcodes (#1812)
Browse files Browse the repository at this point in the history
thread predicate through to the brillig opcode
  • Loading branch information
kevaundray authored Jul 4, 2023
1 parent 310368d commit fdad81d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ impl AcirContext {
// Compute the inverse with brillig code
let inverse_code = brillig_directive::directive_invert();
let field_type = AcirType::NumericType(NumericType::NativeField);

let results = self.brillig(
None,
inverse_code,
vec![AcirValue::Var(var, field_type.clone())],
vec![field_type],
Expand Down Expand Up @@ -743,6 +745,7 @@ impl AcirContext {

pub(crate) fn brillig(
&mut self,
predicate: Option<AcirVar>,
code: Vec<BrilligOpcode>,
inputs: Vec<AcirValue>,
outputs: Vec<AcirType>,
Expand Down Expand Up @@ -783,8 +786,8 @@ impl AcirContext {
AcirValue::Array(array_values)
}
});

self.acir_ir.brillig(code, b_inputs, b_outputs);
let predicate = predicate.map(|var| self.vars[&var].to_expression().into_owned());
self.acir_ir.brillig(predicate, code, b_inputs, b_outputs);

outputs_var
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ impl GeneratedAcir {
let inverse_code = brillig_directive::directive_invert();
let inputs = vec![BrilligInputs::Single(expr.clone())];
let outputs = vec![BrilligOutputs::Simple(inverted_witness)];
self.brillig(inverse_code, inputs, outputs);
self.brillig(Some(Expression::one()), inverse_code, inputs, outputs);

inverted_witness
}
Expand Down Expand Up @@ -671,6 +671,7 @@ impl GeneratedAcir {

pub(crate) fn brillig(
&mut self,
predicate: Option<Expression>,
code: Vec<BrilligOpcode>,
inputs: Vec<BrilligInputs>,
outputs: Vec<BrilligOutputs>,
Expand All @@ -680,7 +681,7 @@ impl GeneratedAcir {
outputs,
foreign_call_results: Vec::new(),
bytecode: code,
predicate: None,
predicate,
});
self.push_opcode(opcode);
}
Expand Down
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/ssa_refactor/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ impl Context {

let outputs: Vec<AcirType> = vecmap(result_ids, |result_id| dfg.type_of_value(*result_id).into());

let output_values = self.acir_context.brillig(code, inputs, outputs);
let output_values = self.acir_context.brillig(self.current_side_effects_enabled_var,code, inputs, outputs);
// Compiler sanity check
assert_eq!(result_ids.len(), output_values.len(), "ICE: The number of Brillig output values should match the result ids in SSA");

Expand Down

0 comments on commit fdad81d

Please sign in to comment.