Skip to content

Commit

Permalink
Hardcode BB support for memory gates
Browse files Browse the repository at this point in the history
  • Loading branch information
guipublic committed May 25, 2023
1 parent 075110d commit 6ac418a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 20 deletions.
10 changes: 2 additions & 8 deletions crates/noirc_evaluator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,7 @@ pub fn create_circuit(
let mut evaluator = Evaluator::default();

// First evaluate the main function
evaluator.evaluate_main_alt(
program.clone(),
is_opcode_supported,
enable_logging,
show_output,
)?;
evaluator.evaluate_main_alt(program.clone(), enable_logging, show_output)?;

let Evaluator {
current_witness_index,
Expand Down Expand Up @@ -152,7 +147,6 @@ impl Evaluator {
pub fn evaluate_main_alt(
&mut self,
program: Program,
is_opcode_supported: IsOpcodeSupported,
enable_logging: bool,
show_output: bool,
) -> Result<(), RuntimeError> {
Expand All @@ -165,7 +159,7 @@ impl Evaluator {
ir_gen.ssa_gen_main()?;

//Generates ACIR representation:
ir_gen.context.ir_to_acir(self, is_opcode_supported, enable_logging, show_output)?;
ir_gen.context.ir_to_acir(self, enable_logging, show_output)?;
Ok(())
}

Expand Down
4 changes: 1 addition & 3 deletions crates/noirc_evaluator/src/ssa/acir_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use acvm::acir::native_types::{Expression, Witness};
mod operations;

mod internal_var;
use acvm::compiler::transformers::IsOpcodeSupported;
pub(crate) use internal_var::InternalVar;
mod constraints;
mod internal_var_cache;
Expand All @@ -36,7 +35,6 @@ impl Acir {
evaluator: &mut Evaluator,
ctx: &SsaContext,
root: &BasicBlock,
is_opcode_supported: IsOpcodeSupported,
show_output: bool,
) -> Result<(), RuntimeError> {
let mut current_block = Some(root);
Expand All @@ -48,7 +46,7 @@ impl Acir {
//TODO we should rather follow the jumps
current_block = block.left.map(|block_id| &ctx[block_id]);
}
self.memory.acir_gen(evaluator, is_opcode_supported, ctx);
self.memory.acir_gen(evaluator, ctx);
Ok(())
}

Expand Down
16 changes: 10 additions & 6 deletions crates/noirc_evaluator/src/ssa/acir_gen/acir_mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,15 +389,19 @@ impl AcirMem {
let item = MemOp { operation: op, value, index };
self.array_heap_mut(*array_id).push(item);
}
pub(crate) fn acir_gen(
&self,
evaluator: &mut Evaluator,
is_opcode_supported: IsOpcodeSupported,
ctx: &SsaContext,
) {
pub(crate) fn acir_gen(&self, evaluator: &mut Evaluator, ctx: &SsaContext) {
//Temporary hack - We hardcode Barretenberg support here.
//TODO: to remove once opcodesupported usage is clarified
let is_opcode_supported: OpcodeSupported = |o| match o {
AcirOpcode::Block(_) => false,
AcirOpcode::ROM(_) | AcirOpcode::RAM(_) => true,
_ => unreachable!(),
};
for mem in &self.virtual_memory {
let array = &ctx.mem[*mem.0];
mem.1.acir_gen(evaluator, array.id, array.len, is_opcode_supported);
}
}
}

type OpcodeSupported = fn(&AcirOpcode) -> bool;
4 changes: 1 addition & 3 deletions crates/noirc_evaluator/src/ssa/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use crate::ssa::{
{block, builtin, flatten, function, inline, integer, node, optimizations},
};
use crate::Evaluator;
use acvm::compiler::transformers::IsOpcodeSupported;
use acvm::FieldElement;
use iter_extended::vecmap;
use noirc_errors::Location;
Expand Down Expand Up @@ -702,7 +701,6 @@ impl SsaContext {
pub(crate) fn ir_to_acir(
&mut self,
evaluator: &mut Evaluator,
is_opcode_supported: IsOpcodeSupported,
enable_logging: bool,
show_output: bool,
) -> Result<(), RuntimeError> {
Expand Down Expand Up @@ -749,7 +747,7 @@ impl SsaContext {
self.log(enable_logging, "\noverflow:", "");
//ACIR
let mut acir = Acir::default();
acir.acir_gen(evaluator, self, &self[self.first_block], is_opcode_supported, show_output)?;
acir.acir_gen(evaluator, self, &self[self.first_block], show_output)?;
if enable_logging {
print_acir_circuit(&evaluator.opcodes);
println!("DONE");
Expand Down

0 comments on commit 6ac418a

Please sign in to comment.