Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Feb 10, 2025
1 parent 95a41a6 commit eb817c4
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 133 deletions.
132 changes: 0 additions & 132 deletions compiler/noirc_evaluator/src/acir/acir_variable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1656,135 +1656,3 @@ fn fits_in_one_identity<F: AcirField>(expr: &Expression<F>, width: ExpressionWid
/// A Reference to an `AcirVarData`
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub(crate) struct AcirVar(usize);
<<<<<<< HEAD
||||||| parent of 91f98735b2 (feat: remove foreign calls array from `BrilligVM` constructor)

/// Attempts to execute the provided [`Brillig`][`acvm::acir::brillig`] bytecode
///
/// Returns the finished state of the Brillig VM if execution can complete.
///
/// Returns `None` if complete execution of the Brillig bytecode is not possible.
fn execute_brillig<F: AcirField, B: BlackBoxFunctionSolver<F>>(
code: &[BrilligOpcode<F>],
blackbox_solver: &B,
inputs: &[BrilligInputs<F>],
) -> Option<Vec<MemoryValue<F>>> {
// Set input values
let mut calldata: Vec<F> = Vec::new();

// Each input represents a constant or array of constants.
// Iterate over each input and push it into registers and/or memory.
for input in inputs {
match input {
BrilligInputs::Single(expr) => {
calldata.push(*expr.to_const()?);
}
BrilligInputs::Array(expr_arr) => {
// Attempt to fetch all array input values
for expr in expr_arr.iter() {
calldata.push(*expr.to_const()?);
}
}
BrilligInputs::MemoryArray(_) => {
return None;
}
}
}

// Instantiate a Brillig VM given the solved input registers and memory, along with the Brillig bytecode.
let profiling_active = false;
let mut vm = VM::new(calldata, code, Vec::new(), blackbox_solver, profiling_active);

// Run the Brillig VM on these inputs, bytecode, etc!
let vm_status = vm.process_opcodes();

// Check the status of the Brillig VM.
// It may be finished, in-progress, failed, or may be waiting for results of a foreign call.
// If it's finished then we can omit the opcode and just write in the return values.
match vm_status {
VMStatus::Finished { return_data_offset, return_data_size } => Some(
vm.get_memory()[return_data_offset..(return_data_offset + return_data_size)].to_vec(),
),
VMStatus::InProgress => unreachable!("Brillig VM has not completed execution"),
VMStatus::Failure { .. } => {
// TODO: Return an error stating that the brillig function failed.
None
}
VMStatus::ForeignCallWait { .. } => {
// If execution can't complete then keep the opcode

// TODO: We could bake in all the execution up to this point by replacing the inputs
// such that they initialize the registers/memory to the current values and then discard
// any opcodes prior to the one which performed this foreign call.
//
// Seems overkill for now however.
None
}
}
}
=======

/// Attempts to execute the provided [`Brillig`][`acvm::acir::brillig`] bytecode
///
/// Returns the finished state of the Brillig VM if execution can complete.
///
/// Returns `None` if complete execution of the Brillig bytecode is not possible.
fn execute_brillig<F: AcirField, B: BlackBoxFunctionSolver<F>>(
code: &[BrilligOpcode<F>],
blackbox_solver: &B,
inputs: &[BrilligInputs<F>],
) -> Option<Vec<MemoryValue<F>>> {
// Set input values
let mut calldata: Vec<F> = Vec::new();

// Each input represents a constant or array of constants.
// Iterate over each input and push it into registers and/or memory.
for input in inputs {
match input {
BrilligInputs::Single(expr) => {
calldata.push(*expr.to_const()?);
}
BrilligInputs::Array(expr_arr) => {
// Attempt to fetch all array input values
for expr in expr_arr.iter() {
calldata.push(*expr.to_const()?);
}
}
BrilligInputs::MemoryArray(_) => {
return None;
}
}
}

// Instantiate a Brillig VM given the solved input registers and memory, along with the Brillig bytecode.
let profiling_active = false;
let mut vm = VM::new(calldata, code, blackbox_solver, profiling_active);

// Run the Brillig VM on these inputs, bytecode, etc!
let vm_status = vm.process_opcodes();

// Check the status of the Brillig VM.
// It may be finished, in-progress, failed, or may be waiting for results of a foreign call.
// If it's finished then we can omit the opcode and just write in the return values.
match vm_status {
VMStatus::Finished { return_data_offset, return_data_size } => Some(
vm.get_memory()[return_data_offset..(return_data_offset + return_data_size)].to_vec(),
),
VMStatus::InProgress => unreachable!("Brillig VM has not completed execution"),
VMStatus::Failure { .. } => {
// TODO: Return an error stating that the brillig function failed.
None
}
VMStatus::ForeignCallWait { .. } => {
// If execution can't complete then keep the opcode

// TODO: We could bake in all the execution up to this point by replacing the inputs
// such that they initialize the registers/memory to the current values and then discard
// any opcodes prior to the one which performed this foreign call.
//
// Seems overkill for now however.
None
}
}
}
>>>>>>> 91f98735b2 (feat: remove foreign calls array from `BrilligVM` constructor)
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/acir/brillig_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ fn execute_brillig<F: AcirField, B: BlackBoxFunctionSolver<F>>(

// Instantiate a Brillig VM given the solved input registers and memory, along with the Brillig bytecode.
let profiling_active = false;
let mut vm = VM::new(calldata, code, Vec::new(), blackbox_solver, profiling_active);
let mut vm = VM::new(calldata, code, blackbox_solver, profiling_active);

// Run the Brillig VM on these inputs, bytecode, etc!
let vm_status = vm.process_opcodes();
Expand Down

0 comments on commit eb817c4

Please sign in to comment.