Skip to content

Commit

Permalink
chore: disallow inserting ACIR-only instructions into brillig functions
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Jan 10, 2025
1 parent 2903052 commit 33cad9b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ impl<'block> BrilligBlock<'block> {
self.brillig_context.deallocate_register(rc_register);
}
Instruction::EnableSideEffectsIf { .. } => {
todo!("enable_side_effects not supported by brillig")
unreachable!("enable_side_effects not supported by brillig")
}
Instruction::IfElse { .. } => {
unreachable!("IfElse instructions should not be possible in brillig")
Expand Down
13 changes: 12 additions & 1 deletion compiler/noirc_evaluator/src/ssa/ir/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use iter_extended::vecmap;
use serde::{Deserialize, Serialize};
use serde_with::serde_as;
use serde_with::DisplayFromStr;
use tracing::warn;

/// The DataFlowGraph contains most of the actual data in a function including
/// its blocks, instructions, and values. This struct is largely responsible for
Expand Down Expand Up @@ -181,7 +182,16 @@ impl DataFlowGraph {

/// Check if the function runtime would simply ignore this instruction.
pub(crate) fn is_handled_by_runtime(&self, instruction: &Instruction) -> bool {
!(self.runtime().is_acir() && instruction.is_brillig_only())
match self.runtime() {
RuntimeType::Acir(_) => !matches!(
instruction,
Instruction::IncrementRc { .. } | Instruction::DecrementRc { .. }
),
RuntimeType::Brillig(_) => !matches!(
instruction,
Instruction::EnableSideEffectsIf { .. } | Instruction::IfElse { .. }
),
}
}

fn insert_instruction_without_simplification(
Expand Down Expand Up @@ -228,6 +238,7 @@ impl DataFlowGraph {
call_stack: CallStackId,
) -> InsertInstructionResult {
if !self.is_handled_by_runtime(&instruction) {
warn!("Attempted to insert instruction not handled by runtime: {instruction:?}");
return InsertInstructionResult::InstructionRemoved;
}
match instruction.simplify(self, block, ctrl_typevars.clone(), call_stack) {
Expand Down
6 changes: 0 additions & 6 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,12 +1058,6 @@ impl Instruction {
Instruction::Noop => Remove,
}
}

/// Some instructions are only to be used in Brillig and should be eliminated
/// after runtime separation, never to be be reintroduced in an ACIR runtime.
pub(crate) fn is_brillig_only(&self) -> bool {
matches!(self, Instruction::IncrementRc { .. } | Instruction::DecrementRc { .. })
}
}

/// Given a chain of operations like:
Expand Down

0 comments on commit 33cad9b

Please sign in to comment.