Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Sync from aztec-packages #6656

Merged
merged 12 commits into from
Nov 29, 2024
2 changes: 1 addition & 1 deletion .aztec-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1bfc15e08873a1f0f3743e259f418b70426b3f25
0577c1a70e9746bd06f07d2813af1be39e01ca02
15 changes: 2 additions & 13 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use iter_extended::vecmap;
use noirc_frontend::hir_def::types::Type as HirType;

use crate::ssa::{ir::function::RuntimeType, opt::flatten_cfg::value_merger::ValueMerger};
use crate::ssa::opt::flatten_cfg::value_merger::ValueMerger;

use super::{
basic_block::BasicBlockId,
Expand Down Expand Up @@ -386,7 +386,7 @@
// These can fail.
Constrain(..) | RangeCheck { .. } => true,

// This should never be side-effectful

Check warning on line 389 in compiler/noirc_evaluator/src/ssa/ir/instruction.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (effectful)
MakeArray { .. } => false,

// These can have different behavior depending on the EnableSideEffectsIf context.
Expand Down Expand Up @@ -435,7 +435,7 @@
// We can deduplicate these instructions if we know the predicate is also the same.
Constrain(..) | RangeCheck { .. } => deduplicate_with_predicate,

// This should never be side-effectful

Check warning on line 438 in compiler/noirc_evaluator/src/ssa/ir/instruction.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (effectful)
MakeArray { .. } => true,

// These can have different behavior depending on the EnableSideEffectsIf context.
Expand Down Expand Up @@ -478,19 +478,8 @@
| ArraySet { .. }
| MakeArray { .. } => true,

// Store instructions must be removed by DIE in acir code, any load
// instructions should already be unused by that point.
//
// Note that this check assumes that it is being performed after the flattening
// pass and after the last mem2reg pass. This is currently the case for the DIE
// pass where this check is done, but does mean that we cannot perform mem2reg
// after the DIE pass.
Store { .. } => {
matches!(function.runtime(), RuntimeType::Acir(_))
&& function.reachable_blocks().len() == 1
}

Constrain(..)
| Store { .. }
| EnableSideEffectsIf { .. }
| IncrementRc { .. }
| DecrementRc { .. }
Expand Down
34 changes: 22 additions & 12 deletions compiler/noirc_evaluator/src/ssa/ir/instruction/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ pub(super) fn simplify_call(
_ => return SimplifyResult::None,
};

let return_type = ctrl_typevars.and_then(|return_types| return_types.first().cloned());

let constant_args: Option<Vec<_>> =
arguments.iter().map(|value_id| dfg.get_numeric_constant(*value_id)).collect();

match intrinsic {
let simplified_result = match intrinsic {
Intrinsic::ToBits(endian) => {
// TODO: simplify to a range constraint if `limb_count == 1`
if let (Some(constant_args), Some(return_type)) =
(constant_args, ctrl_typevars.map(|return_types| return_types.first().cloned()))
{
if let (Some(constant_args), Some(return_type)) = (constant_args, return_type.clone()) {
let field = constant_args[0];
let limb_count = if let Some(Type::Array(_, array_len)) = return_type {
let limb_count = if let Type::Array(_, array_len) = return_type {
array_len as u32
} else {
unreachable!("ICE: Intrinsic::ToRadix return type must be array")
Expand All @@ -67,12 +67,10 @@ pub(super) fn simplify_call(
}
Intrinsic::ToRadix(endian) => {
// TODO: simplify to a range constraint if `limb_count == 1`
if let (Some(constant_args), Some(return_type)) =
(constant_args, ctrl_typevars.map(|return_types| return_types.first().cloned()))
{
if let (Some(constant_args), Some(return_type)) = (constant_args, return_type.clone()) {
let field = constant_args[0];
let radix = constant_args[1].to_u128() as u32;
let limb_count = if let Some(Type::Array(_, array_len)) = return_type {
let limb_count = if let Type::Array(_, array_len) = return_type {
array_len as u32
} else {
unreachable!("ICE: Intrinsic::ToRadix return type must be array")
Expand Down Expand Up @@ -330,7 +328,7 @@ pub(super) fn simplify_call(
}
Intrinsic::FromField => {
let incoming_type = Type::field();
let target_type = ctrl_typevars.unwrap().remove(0);
let target_type = return_type.clone().unwrap();

let truncate = Instruction::Truncate {
value: arguments[0],
Expand All @@ -352,8 +350,8 @@ pub(super) fn simplify_call(
Intrinsic::AsWitness => SimplifyResult::None,
Intrinsic::IsUnconstrained => SimplifyResult::None,
Intrinsic::DerivePedersenGenerators => {
if let Some(Type::Array(_, len)) = ctrl_typevars.unwrap().first() {
simplify_derive_generators(dfg, arguments, *len as u32, block, call_stack)
if let Some(Type::Array(_, len)) = return_type.clone() {
simplify_derive_generators(dfg, arguments, len as u32, block, call_stack)
} else {
unreachable!("Derive Pedersen Generators must return an array");
}
Expand All @@ -370,7 +368,19 @@ pub(super) fn simplify_call(
}
Intrinsic::ArrayRefCount => SimplifyResult::None,
Intrinsic::SliceRefCount => SimplifyResult::None,
};

if let (Some(expected_types), SimplifyResult::SimplifiedTo(result)) =
(return_type, &simplified_result)
{
assert_eq!(
dfg.type_of_value(*result),
expected_types,
"Simplification should not alter return type"
);
}

simplified_result
}

/// Slices have a tuple structure (slice length, slice contents) to enable logic
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub(super) fn simplify_ec_add(

let result_x = dfg.make_constant(result_x, Type::field());
let result_y = dfg.make_constant(result_y, Type::field());
let result_is_infinity = dfg.make_constant(result_is_infinity, Type::bool());
let result_is_infinity = dfg.make_constant(result_is_infinity, Type::field());

let typ = Type::Array(Arc::new(vec![Type::field()]), 3);

Expand Down Expand Up @@ -107,7 +107,7 @@ pub(super) fn simplify_msm(

let result_x = dfg.make_constant(result_x, Type::field());
let result_y = dfg.make_constant(result_y, Type::field());
let result_is_infinity = dfg.make_constant(result_is_infinity, Type::bool());
let result_is_infinity = dfg.make_constant(result_is_infinity, Type::field());

let elements = im::vector![result_x, result_y, result_is_infinity];
let typ = Type::Array(Arc::new(vec![Type::field()]), 3);
Expand Down
Loading
Loading