Skip to content

Commit

Permalink
Merge branch 'master' into aztec-packages
Browse files Browse the repository at this point in the history
* master: (36 commits)
  fix: ignore compression of blocks after msg.len in sha256_var (#6206)
  feat(perf): Optimize array set from get (#6207)
  chore(refactor): Array set optimization context struct for analysis (#6204)
  fix: type variables by default should have Any kind (#6203)
  feat: remove orphaned blocks from cfg to improve `simplify_cfg` pass. (#6198)
  fix(ssa): Check if result of array set is used in value of another array set (#6197)
  fix(docs): Rename recursion.md to recursion.mdx (#6195)
  feat: skip `remove_enable_side_effects` pass on brillig functions (#6199)
  feat!: Syncing TypeVariableKind with Kind (#6094)
  feat(perf): Simplify the cfg after DIE (#6184)
  feat: refactor SSA passes to run on individual functions (#6072)
  chore: Remove macros_api module (#6190)
  fix: ensure to_bytes returns the canonical decomposition (#6084)
  chore: rename `DefinitionKind::GenericType` (#6182)
  feat(perf): Remove redundant inc rc without instructions between (#6183)
  chore: reexport `CrateName` through `nargo` (#6177)
  feat(perf): Remove inc_rc instructions for arrays which are never mutably borrowed (#6168)
  chore(docs): Add link to more info about proving backend to Solidity verifier page (#5754)
  feat: let `Module::functions` and `Module::structs` return them in definition order (#6178)
  chore: split `test_program`s into modules (#6101)
  ...
  • Loading branch information
TomAFrench committed Oct 2, 2024
2 parents fa3fba9 + 76eec71 commit fc2b3f3
Show file tree
Hide file tree
Showing 133 changed files with 1,755 additions and 1,179 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 18 additions & 10 deletions compiler/noirc_driver/src/abi_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ use noirc_abi::{
Abi, AbiErrorType, AbiParameter, AbiReturnType, AbiType, AbiValue, AbiVisibility, Sign,
};
use noirc_frontend::ast::{Signedness, Visibility};
use noirc_frontend::TypeBinding;
use noirc_frontend::{
hir::Context,
hir_def::{expr::HirArrayLiteral, function::Param, stmt::HirPattern, types::Type},
macros_api::{HirExpression, HirLiteral},
hir_def::{
expr::{HirArrayLiteral, HirExpression, HirLiteral},
function::Param,
stmt::HirPattern,
types::Type,
},
node_interner::{FuncId, NodeInterner},
};
use noirc_frontend::{TypeBinding, TypeVariableKind};

/// Arranges a function signature and a generated circuit's return witnesses into a
/// `noirc_abi::Abi`.
Expand Down Expand Up @@ -68,13 +72,18 @@ pub(super) fn abi_type_from_hir_type(context: &Context, typ: &Type) -> AbiType {

AbiType::Integer { sign, width: (*bit_width).into() }
}
Type::TypeVariable(binding, TypeVariableKind::IntegerOrField)
| Type::TypeVariable(binding, TypeVariableKind::Integer) => match &*binding.borrow() {
TypeBinding::Bound(typ) => abi_type_from_hir_type(context, typ),
TypeBinding::Unbound(_) => {
abi_type_from_hir_type(context, &Type::default_int_or_field_type())
Type::TypeVariable(binding) => {
if binding.is_integer() || binding.is_integer_or_field() {
match &*binding.borrow() {
TypeBinding::Bound(typ) => abi_type_from_hir_type(context, typ),
TypeBinding::Unbound(_id, _kind) => {
abi_type_from_hir_type(context, &Type::default_int_or_field_type())
}
}
} else {
unreachable!("{typ} cannot be used in the abi")
}
},
}
Type::Bool => AbiType::Boolean,
Type::String(size) => {
let size = size
Expand Down Expand Up @@ -102,7 +111,6 @@ pub(super) fn abi_type_from_hir_type(context: &Context, typ: &Type) -> AbiType {
| Type::Constant(..)
| Type::InfixExpr(..)
| Type::TraitAsType(..)
| Type::TypeVariable(_, _)
| Type::NamedGeneric(..)
| Type::Forall(..)
| Type::Quoted(_)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use super::{
};
use acvm::acir::{brillig::MemoryAddress, AcirField};

pub(crate) const MAX_STACK_SIZE: usize = 2048;
pub(crate) const MAX_STACK_SIZE: usize = 32768;
pub(crate) const MAX_SCRATCH_SPACE: usize = 64;

impl<F: AcirField + DebugToString> BrilligContext<F, Stack> {
Expand Down
1 change: 1 addition & 0 deletions compiler/noirc_evaluator/src/ssa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub(crate) fn optimize_into_acir(
.run_pass(Ssa::remove_enable_side_effects, "After EnableSideEffectsIf removal:")
.run_pass(Ssa::fold_constants_using_constraints, "After Constraint Folding:")
.run_pass(Ssa::dead_instruction_elimination, "After Dead Instruction Elimination:")
.run_pass(Ssa::simplify_cfg, "After Simplifying:")
.run_pass(Ssa::array_set_optimization, "After Array Set Optimizations:")
.finish();

Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_evaluator/src/ssa/ir/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl ControlFlowGraph {

/// Clears out a given block's successors. This also removes the given block from
/// being a predecessor of any of its previous successors.
fn invalidate_block_successors(&mut self, basic_block_id: BasicBlockId) {
pub(crate) fn invalidate_block_successors(&mut self, basic_block_id: BasicBlockId) {
let node = self
.data
.get_mut(&basic_block_id)
Expand Down
30 changes: 26 additions & 4 deletions compiler/noirc_evaluator/src/ssa/ir/instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,9 +630,9 @@ impl Instruction {
}
}
Instruction::ArraySet { array, index, value, .. } => {
let array = dfg.get_array_constant(*array);
let index = dfg.get_numeric_constant(*index);
if let (Some((array, element_type)), Some(index)) = (array, index) {
let array_const = dfg.get_array_constant(*array);
let index_const = dfg.get_numeric_constant(*index);
if let (Some((array, element_type)), Some(index)) = (array_const, index_const) {
let index =
index.try_to_u32().expect("Expected array index to fit in u32") as usize;

Expand All @@ -641,7 +641,8 @@ impl Instruction {
return SimplifiedTo(new_array);
}
}
None

try_optimize_array_set_from_previous_get(dfg, *array, *index, *value)
}
Instruction::Truncate { value, bit_size, max_bit_size } => {
if bit_size == max_bit_size {
Expand Down Expand Up @@ -817,6 +818,27 @@ fn try_optimize_array_get_from_previous_set(
SimplifyResult::None
}

fn try_optimize_array_set_from_previous_get(
dfg: &DataFlowGraph,
array_id: ValueId,
target_index: ValueId,
target_value: ValueId,
) -> SimplifyResult {
match &dfg[target_value] {
Value::Instruction { instruction, .. } => match &dfg[*instruction] {
Instruction::ArrayGet { array, index } => {
if *array == array_id && *index == target_index {
SimplifyResult::SimplifiedTo(array_id)
} else {
SimplifyResult::None
}
}
_ => SimplifyResult::None,
},
_ => SimplifyResult::None,
}
}

pub(crate) type ErrorType = HirType;

pub(crate) fn error_selector_from_type(typ: &ErrorType) -> ErrorSelector {
Expand Down
Loading

0 comments on commit fc2b3f3

Please sign in to comment.