Skip to content
Closed
6 changes: 3 additions & 3 deletions compiler/noirc_evaluator/src/acir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ impl<'a> Context<'a> {
Instruction::ArrayGet { .. } | Instruction::ArraySet { .. } => {
self.handle_array_operation(instruction_id, dfg)?;
}
Instruction::Allocate => {
Instruction::Allocate { .. } => {
return Err(RuntimeError::UnknownReference {
call_stack: self.acir_context.get_call_stack().clone(),
});
Expand Down Expand Up @@ -805,7 +805,7 @@ impl<'a> Context<'a> {
let mut warnings = Vec::new();

match instruction {
Instruction::Call { func, arguments } => {
Instruction::Call { func, arguments, result_types: _ } => {
let function_value = &dfg[*func];
match function_value {
Value::Function(id) => {
Expand Down Expand Up @@ -1009,7 +1009,7 @@ impl<'a> Context<'a> {

// Pass the instruction between array methods rather than the internal fields themselves
let (array, index, store_value) = match dfg[instruction] {
Instruction::ArrayGet { array, index } => (array, index, None),
Instruction::ArrayGet { array, index, result_type: _ } => (array, index, None),
Instruction::ArraySet { array, index, value, mutable } => {
mutable_array_set = mutable;
(array, index, Some(value))
Expand Down
33 changes: 13 additions & 20 deletions compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,7 @@ impl<'block> BrilligBlock<'block> {
// the block parameters need to be defined/allocated before the given block. Variable liveness provides when the block parameters are defined.
// For the entry block, the defined block params will be the params of the function + any extra params of blocks it's the immediate dominator of.
for param_id in self.function_context.liveness.defined_block_params(&self.block_id) {
let value = &dfg[param_id];
let param_type = match value {
Value::Param { typ, .. } => typ,
_ => unreachable!("ICE: Only Param type values should appear in block parameters"),
};
match param_type {
match dfg.type_of_value(param_id) {
// Simple parameters and arrays are passed as already filled registers
// In the case of arrays, the values should already be in memory and the register should
// Be a valid pointer to the array.
Expand Down Expand Up @@ -279,7 +274,7 @@ impl<'block> BrilligBlock<'block> {
self.brillig_context.deallocate_single_addr(condition);
}
}
Instruction::Allocate => {
Instruction::Allocate { .. } => {
let result_value = dfg.instruction_results(instruction_id)[0];
let pointer = self.variables.define_single_addr_variable(
self.function_context,
Expand All @@ -296,7 +291,7 @@ impl<'block> BrilligBlock<'block> {
self.brillig_context
.store_instruction(address_var.address, source_variable.extract_register());
}
Instruction::Load { address } => {
Instruction::Load { address, result_type: _ } => {
let target_variable = self.variables.define_variable(
self.function_context,
self.brillig_context,
Expand All @@ -319,7 +314,7 @@ impl<'block> BrilligBlock<'block> {
);
self.brillig_context.not_instruction(condition_register, result_register);
}
Instruction::Call { func, arguments } => match &dfg[*func] {
Instruction::Call { func, arguments, result_types: _ } => match &dfg[*func] {
Value::ForeignFunction(func_name) => {
let result_ids = dfg.instruction_results(instruction_id);

Expand Down Expand Up @@ -376,7 +371,8 @@ impl<'block> BrilligBlock<'block> {
// Update the dynamic slice length maintained in SSA
if let ValueOrArray::MemoryAddress(len_index) = output_values[i - 1]
{
let element_size = dfg[result_ids[i]].get_type().element_size();
let element_size =
dfg.type_of_value(result_ids[i]).element_size();
self.brillig_context
.mov_instruction(len_index, heap_vector.size);
self.brillig_context.codegen_usize_op_in_place(
Expand Down Expand Up @@ -678,7 +674,7 @@ impl<'block> BrilligBlock<'block> {
let source_variable = self.convert_ssa_single_addr_value(*value, dfg);
self.convert_cast(destination_variable, source_variable);
}
Instruction::ArrayGet { array, index } => {
Instruction::ArrayGet { array, index, result_type: _ } => {
let result_ids = dfg.instruction_results(instruction_id);
let destination_variable = self.variables.define_variable(
self.function_context,
Expand Down Expand Up @@ -1283,8 +1279,8 @@ impl<'block> BrilligBlock<'block> {
result_variable: SingleAddrVariable,
) {
let binary_type = type_of_binary_operation(
dfg[binary.lhs].get_type().as_ref(),
dfg[binary.rhs].get_type().as_ref(),
&dfg.type_of_value(binary.lhs),
&dfg.type_of_value(binary.rhs),
binary.operator,
);

Expand Down Expand Up @@ -1792,24 +1788,23 @@ impl<'block> BrilligBlock<'block> {
result: ValueId,
dfg: &DataFlowGraph,
) -> BrilligVariable {
let typ = dfg[result].get_type();
match typ.as_ref() {
match dfg.type_of_value(result) {
Type::Numeric(_) => self.variables.define_variable(
self.function_context,
self.brillig_context,
result,
dfg,
),

Type::Array(..) => {
typ @ Type::Array(..) => {
let variable = self.variables.define_variable(
self.function_context,
self.brillig_context,
result,
dfg,
);
let array = variable.extract_array();
self.allocate_foreign_call_result_array(typ.as_ref(), array);
self.allocate_foreign_call_result_array(&typ, array);

variable
}
Expand All @@ -1829,9 +1824,7 @@ impl<'block> BrilligBlock<'block> {

variable
}
_ => {
unreachable!("ICE: unsupported return type for black box call {typ:?}")
}
typ => unreachable!("ICE: unsupported return type for black box call {typ:?}"),
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ impl DependencyContext {
Instruction::Store { address, value } => {
self.memory_slots.insert(*address, function.dfg.resolve(*value));
}
Instruction::Load { address } => {
Instruction::Load { address, result_type: _ } => {
// Recall the value stored at address as parent for the results
if let Some(value_id) = self.memory_slots.get(address) {
self.update_children(&[*value_id], &results);
Expand Down Expand Up @@ -564,7 +564,7 @@ impl Context {
self.value_sets.push(instruction_arguments_and_results);
}

Instruction::Call { func: func_id, arguments: argument_ids } => {
Instruction::Call { func: func_id, arguments: argument_ids, result_types: _ } => {
match &function.dfg[*func_id] {
Value::Intrinsic(intrinsic) => match intrinsic {
Intrinsic::ApplyRangeConstraint
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_evaluator/src/ssa/function_builder/data_bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl FunctionBuilder {
/// Insert a value into a data bus builder
fn add_to_data_bus(&mut self, value: ValueId, databus: &mut DataBusBuilder) {
assert!(databus.databus.is_none(), "initializing finalized call data");
let typ = self.current_function.dfg[value].get_type().into_owned();
let typ = self.current_function.dfg.type_of_value(value);
match typ {
Type::Numeric(_) => {
databus.values.push_back(value);
Expand Down Expand Up @@ -230,7 +230,7 @@ impl FunctionBuilder {
let ssa_param_sizes: Vec<usize> = ssa_params
.iter()
.map(|ssa_param| {
self.current_function.dfg[*ssa_param].get_type().flattened_size() as usize
self.current_function.dfg.type_of_value(*ssa_param).flattened_size() as usize
})
.collect();

Expand Down
48 changes: 21 additions & 27 deletions compiler/noirc_evaluator/src/ssa/function_builder/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
pub(crate) mod data_bus;

use std::{borrow::Cow, collections::BTreeMap, sync::Arc};
use std::{borrow::Cow, collections::BTreeMap};

use acvm::{acir::circuit::ErrorSelector, FieldElement};
use noirc_errors::Location;
Expand Down Expand Up @@ -164,13 +164,11 @@ impl FunctionBuilder {
pub(crate) fn insert_instruction(
&mut self,
instruction: Instruction,
ctrl_typevars: Option<Vec<Type>>,
) -> InsertInstructionResult {
let block = self.current_block();
self.current_function.dfg.insert_instruction_and_results(
instruction,
block,
ctrl_typevars,
self.call_stack.clone(),
)
}
Expand All @@ -191,8 +189,7 @@ impl FunctionBuilder {
/// given amount of field elements. Returns the result of the allocate instruction,
/// which is always a Reference to the allocated data.
pub(crate) fn insert_allocate(&mut self, element_type: Type) -> ValueId {
let reference_type = Type::Reference(Arc::new(element_type));
self.insert_instruction(Instruction::Allocate, Some(vec![reference_type])).first()
self.insert_instruction(Instruction::Allocate { element_type }).first()
}

pub(crate) fn set_location(&mut self, location: Location) -> &mut FunctionBuilder {
Expand All @@ -213,15 +210,15 @@ impl FunctionBuilder {
/// which should point to a previous Allocate instruction. Note that this is limited to loading
/// a single value. Loading multiple values (such as a tuple) will require multiple loads.
/// Returns the element that was loaded.
pub(crate) fn insert_load(&mut self, address: ValueId, type_to_load: Type) -> ValueId {
self.insert_instruction(Instruction::Load { address }, Some(vec![type_to_load])).first()
pub(crate) fn insert_load(&mut self, address: ValueId, result_type: Type) -> ValueId {
self.insert_instruction(Instruction::Load { address, result_type }).first()
}

/// Insert a Store instruction at the end of the current block, storing the given element
/// at the given address. Expects that the address points somewhere
/// within a previous Allocate instruction.
pub(crate) fn insert_store(&mut self, address: ValueId, value: ValueId) {
self.insert_instruction(Instruction::Store { address, value }, None);
self.insert_instruction(Instruction::Store { address, value });
}

/// Insert a binary instruction at the end of the current block.
Expand All @@ -241,19 +238,19 @@ impl FunctionBuilder {
);
}
let instruction = Instruction::Binary(Binary { lhs, rhs, operator });
self.insert_instruction(instruction, None).first()
self.insert_instruction(instruction).first()
}

/// Insert a not instruction at the end of the current block.
/// Returns the result of the instruction.
pub(crate) fn insert_not(&mut self, rhs: ValueId) -> ValueId {
self.insert_instruction(Instruction::Not(rhs), None).first()
self.insert_instruction(Instruction::Not(rhs)).first()
}

/// Insert a cast instruction at the end of the current block.
/// Returns the result of the cast instruction.
pub(crate) fn insert_cast(&mut self, value: ValueId, typ: NumericType) -> ValueId {
self.insert_instruction(Instruction::Cast(value, typ), None).first()
self.insert_instruction(Instruction::Cast(value, typ)).first()
}

/// Insert a truncate instruction at the end of the current block.
Expand All @@ -264,8 +261,7 @@ impl FunctionBuilder {
bit_size: u32,
max_bit_size: u32,
) -> ValueId {
self.insert_instruction(Instruction::Truncate { value, bit_size, max_bit_size }, None)
.first()
self.insert_instruction(Instruction::Truncate { value, bit_size, max_bit_size }).first()
}

/// Insert a constrain instruction at the end of the current block.
Expand All @@ -275,7 +271,7 @@ impl FunctionBuilder {
rhs: ValueId,
assert_message: Option<ConstrainError>,
) {
self.insert_instruction(Instruction::Constrain(lhs, rhs, assert_message), None);
self.insert_instruction(Instruction::Constrain(lhs, rhs, assert_message));
}

/// Insert a [`Instruction::RangeCheck`] instruction at the end of the current block.
Expand All @@ -285,10 +281,7 @@ impl FunctionBuilder {
max_bit_size: u32,
assert_message: Option<String>,
) {
self.insert_instruction(
Instruction::RangeCheck { value, max_bit_size, assert_message },
None,
);
self.insert_instruction(Instruction::RangeCheck { value, max_bit_size, assert_message });
}

/// Insert a call instruction at the end of the current block and return
Expand All @@ -299,7 +292,8 @@ impl FunctionBuilder {
arguments: Vec<ValueId>,
result_types: Vec<Type>,
) -> Cow<[ValueId]> {
self.insert_instruction(Instruction::Call { func, arguments }, Some(result_types)).results()
let call = Instruction::Call { func, arguments, result_types };
self.insert_instruction(call).results()
}

/// Insert an instruction to extract an element from an array
Expand All @@ -309,8 +303,8 @@ impl FunctionBuilder {
index: ValueId,
element_type: Type,
) -> ValueId {
let element_type = Some(vec![element_type]);
self.insert_instruction(Instruction::ArrayGet { array, index }, element_type).first()
let get = Instruction::ArrayGet { array, index, result_type: element_type };
self.insert_instruction(get).first()
}

/// Insert an instruction to create a new array with the given index replaced with a new value
Expand All @@ -320,7 +314,7 @@ impl FunctionBuilder {
index: ValueId,
value: ValueId,
) -> ValueId {
self.insert_instruction(Instruction::ArraySet { array, index, value, mutable: false }, None)
self.insert_instruction(Instruction::ArraySet { array, index, value, mutable: false })
.first()
}

Expand All @@ -330,26 +324,26 @@ impl FunctionBuilder {
index: ValueId,
value: ValueId,
) -> ValueId {
self.insert_instruction(Instruction::ArraySet { array, index, value, mutable: true }, None)
self.insert_instruction(Instruction::ArraySet { array, index, value, mutable: true })
.first()
}

/// Insert an instruction to increment an array's reference count. This only has an effect
/// in unconstrained code where arrays are reference counted and copy on write.
pub(crate) fn insert_inc_rc(&mut self, value: ValueId) {
self.insert_instruction(Instruction::IncrementRc { value }, None);
self.insert_instruction(Instruction::IncrementRc { value });
}

/// Insert an instruction to decrement an array's reference count. This only has an effect
/// in unconstrained code where arrays are reference counted and copy on write.
pub(crate) fn insert_dec_rc(&mut self, value: ValueId) {
self.insert_instruction(Instruction::DecrementRc { value }, None);
self.insert_instruction(Instruction::DecrementRc { value });
}

/// Insert an enable_side_effects_if instruction. These are normally only automatically
/// inserted during the flattening pass when branching is removed.
pub(crate) fn insert_enable_side_effects_if(&mut self, condition: ValueId) {
self.insert_instruction(Instruction::EnableSideEffectsIf { condition }, None);
self.insert_instruction(Instruction::EnableSideEffectsIf { condition });
}

/// Insert a `make_array` instruction to create a new array or slice.
Expand All @@ -360,7 +354,7 @@ impl FunctionBuilder {
typ: Type,
) -> ValueId {
assert!(matches!(typ, Type::Array(..) | Type::Slice(_)));
self.insert_instruction(Instruction::MakeArray { elements, typ }, None).first()
self.insert_instruction(Instruction::MakeArray { elements, typ }).first()
}

/// Terminates the current block with the given terminator instruction
Expand Down
Loading