Skip to content

Commit

Permalink
[1 changes] feat(ssa): Simplify array get from set that writes to the…
Browse files Browse the repository at this point in the history
… same dynamic index (noir-lang/noir#6684)

feat: Reduce memory consumption by storing array length as `u32` during SSA (noir-lang/noir#6606)
chore: add `ram_blowup_regression` to memory report (noir-lang/noir#6683)
chore: update noir-bench-report version (noir-lang/noir#6675)
fix: Prevent hoisting binary instructions which can overflow (noir-lang/noir#6672)
feat(ssa): Hoisting of array get using known induction variable maximum (noir-lang/noir#6639)
feat: better error message when trying to invoke struct function field (noir-lang/noir#6661)
feat: add memory report into the CI (noir-lang/noir#6630)
feat: allow ignoring test failures from foreign calls (noir-lang/noir#6660)
chore: refactor foreign call executors (noir-lang/noir#6659)
fix: correct signed integer handling in `noirc_abi` (noir-lang/noir#6638)
fix: allow multiple `_` parameters, and disallow `_` as an expression you can read from (noir-lang/noir#6657)
feat: allow filtering which SSA passes are printed (noir-lang/noir#6636)
fix: use correct type for attribute arguments (noir-lang/noir#6640)
fix: always return an array of `u8`s when simplifying `Intrinsic::ToRadix` calls (noir-lang/noir#6663)
feat(ssa): Option to set the maximum acceptable Brillig bytecode increase in unrolling (noir-lang/noir#6641)
feat: Sync from aztec-packages (noir-lang/noir#6656)
chore: refactor poseidon2 (noir-lang/noir#6655)
fix: correct types returned by constant EC operations simplified within SSA (noir-lang/noir#6652)
feat: Sync from aztec-packages (noir-lang/noir#6634)
fix: used signed division for signed modulo (noir-lang/noir#6635)
fix(ssa): don't deduplicate constraints in blocks that are not dominated (noir-lang/noir#6627)
chore: pin foundry version in CI (noir-lang/noir#6642)
feat(ssa): Deduplicate intrinsics with predicates (noir-lang/noir#6615)
chore: improve error message of `&T` (noir-lang/noir#6633)
fix: LSP code action wasn't triggering on beginning or end of identifier (noir-lang/noir#6616)
chore!: remove `ec` module from stdlib (noir-lang/noir#6612)
fix(LSP): use generic self type to narrow down methods to complete (noir-lang/noir#6617)
fix!: Disallow `#[export]` on associated methods (noir-lang/noir#6626)
chore: redo typo PR by donatik27 (noir-lang/noir#6575)
chore: redo typo PR by Dimitrolito (noir-lang/noir#6614)
feat: simplify `jmpif`s by reversing branches if condition is negated (noir-lang/noir#5891)
fix: Do not warn on unused functions marked with #[export] (noir-lang/noir#6625)
chore: Add panic for compiler error described in #6620 (noir-lang/noir#6621)
feat(perf): Track last loads per block in mem2reg and remove them if possible (noir-lang/noir#6088)
fix(ssa): Track all local allocations during flattening (noir-lang/noir#6619)
feat(comptime): Implement blackbox functions in comptime interpreter (noir-lang/noir#6551)
chore: derive PartialEq and Hash for FieldElement (noir-lang/noir#6610)
chore: ignore almost-empty directories in nargo_cli tests (noir-lang/noir#6611)
chore: remove temporary allocations from `num_bits` (noir-lang/noir#6600)
chore: Release Noir(1.0.0-beta.0) (noir-lang/noir#6562)
feat: Add `array_refcount` and `slice_refcount` builtins for debugging (noir-lang/noir#6584)
chore!: Require types of globals to be specified (noir-lang/noir#6592)
fix: don't report visibility errors when elaborating comptime value (noir-lang/noir#6498)
fix: preserve newlines between comments when formatting statements (noir-lang/noir#6601)
fix: parse a bit more SSA stuff (noir-lang/noir#6599)
chore!: remove eddsa from stdlib (noir-lang/noir#6591)
chore: Typo in oracles how to (noir-lang/noir#6598)
feat(ssa): Loop invariant code motion (noir-lang/noir#6563)
fix: remove `compiler_version` from new `Nargo.toml` (noir-lang/noir#6590)
feat: Avoid incrementing reference counts in some cases (noir-lang/noir#6568)
chore: fix typo in test name (noir-lang/noir#6589)
fix: consider prereleases to be compatible with pre-1.0.0 releases (noir-lang/noir#6580)
feat: try to inline brillig calls with all constant arguments  (noir-lang/noir#6548)
fix: correct type when simplifying `derive_pedersen_generators` (noir-lang/noir#6579)
feat: Sync from aztec-packages (noir-lang/noir#6576)
  • Loading branch information
AztecBot committed Dec 3, 2024
1 parent 0577c1a commit 4b35f0a
Show file tree
Hide file tree
Showing 83 changed files with 2,782 additions and 1,294 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
68c32b4ffd9b069fe4b119327dbf4018c17ab9d4
304403f24e2a15b57bb054c4402a8d7f8d275668
88 changes: 88 additions & 0 deletions noir/noir-repo/.github/workflows/memory_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Report Peak Memory

on:
push:
branches:
- master
pull_request:

jobs:
build-nargo:
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64-unknown-linux-gnu]

steps:
- name: Checkout Noir repo
uses: actions/checkout@v4

- name: Setup toolchain
uses: dtolnay/[email protected]

- uses: Swatinem/rust-cache@v2
with:
key: ${{ matrix.target }}
cache-on-failure: true
save-if: ${{ github.event_name != 'merge_group' }}

- name: Build Nargo
run: cargo build --package nargo_cli --release

- name: Package artifacts
run: |
mkdir dist
cp ./target/release/nargo ./dist/nargo
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: nargo
path: ./dist/*
retention-days: 3

generate_memory_report:
needs: [build-nargo]
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- uses: actions/checkout@v4

- name: Download nargo binary
uses: actions/download-artifact@v4
with:
name: nargo
path: ./nargo

- name: Set nargo on PATH
run: |
nargo_binary="${{ github.workspace }}/nargo/nargo"
chmod +x $nargo_binary
echo "$(dirname $nargo_binary)" >> $GITHUB_PATH
export PATH="$PATH:$(dirname $nargo_binary)"
nargo -V
- name: Generate Memory report
working-directory: ./test_programs
run: |
chmod +x memory_report.sh
./memory_report.sh
mv memory_report.json ../memory_report.json
- name: Parse memory report
id: memory_report
uses: noir-lang/noir-bench-report@ccb0d806a91d3bd86dba0ba3d580a814eed5673c
with:
report: memory_report.json
header: |
# Memory Report
memory_report: true

- name: Add memory report to sticky comment
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: memory
message: ${{ steps.memory_report.outputs.markdown }}
30 changes: 23 additions & 7 deletions noir/noir-repo/.github/workflows/test-js-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -519,12 +519,25 @@ jobs:
fail-fast: false
matrix:
project:
# Disabled as these are currently failing with many visibility errors
- { repo: AztecProtocol/aztec-nr, path: ./ }
- { repo: noir-lang/ec, path: ./ }
- { repo: noir-lang/eddsa, path: ./ }
- { repo: noir-lang/mimc, path: ./ }
- { repo: noir-lang/noir_sort, path: ./ }
- { repo: noir-lang/noir-edwards, path: ./ }
- { repo: noir-lang/noir-bignum, path: ./ }
- { repo: noir-lang/noir_bigcurve, path: ./ }
- { repo: noir-lang/noir_base64, path: ./ }
- { repo: noir-lang/noir_string_search, path: ./ }
- { repo: noir-lang/sparse_array, path: ./ }
- { repo: noir-lang/noir_rsa, path: ./lib }
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/aztec-nr }
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-contracts }
# Disabled as aztec-packages requires a setup-step in order to generate a `Nargo.toml`
#- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits }
- { repo: noir-lang/noir-edwards, path: ./, ref: 3188ea74fe3b059219a2ea87899589c266256d74 }
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits/crates/parity-lib }
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits/crates/private-kernel-lib }
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits/crates/reset-kernel-lib }
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits/crates/rollup-lib }
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits/crates/types }

name: Check external repo - ${{ matrix.project.repo }}
steps:
- name: Checkout
Expand Down Expand Up @@ -554,9 +567,12 @@ jobs:
# Github actions seems to not expand "**" in globs by default.
shopt -s globstar
sed -i '/^compiler_version/d' ./**/Nargo.toml
- name: Run nargo check
- name: Run nargo test
working-directory: ./test-repo/${{ matrix.project.path }}
run: nargo check
run: nargo test --silence-warnings
env:
NARGO_IGNORE_TEST_FAILURES_FROM_FOREIGN_CALLS: true

# This is a job which depends on all test jobs and reports the overall status.
# This allows us to add/remove test jobs without having to update the required workflows.
Expand Down
1 change: 1 addition & 0 deletions noir/noir-repo/Cargo.lock

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

2 changes: 1 addition & 1 deletion noir/noir-repo/acvm-repo/acvm_js/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function run_if_available {
require_command jq
require_command cargo
require_command wasm-bindgen
#require_command wasm-opt
require_command wasm-opt

self_path=$(dirname "$(readlink -f "$0")")
pname=$(cargo read-manifest | jq -r '.name')
Expand Down
2 changes: 1 addition & 1 deletion noir/noir-repo/compiler/integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0"
},
"dependencies": {
"@aztec/bb.js": "portal:../../../../barretenberg/ts",
"@aztec/bb.js": "0.63.1",
"@noir-lang/noir_js": "workspace:*",
"@noir-lang/noir_wasm": "workspace:*",
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",
Expand Down
29 changes: 26 additions & 3 deletions noir/noir-repo/compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use noirc_abi::{AbiParameter, AbiType, AbiValue};
use noirc_errors::{CustomDiagnostic, FileDiagnostic};
use noirc_evaluator::create_program;
use noirc_evaluator::errors::RuntimeError;
use noirc_evaluator::ssa::SsaProgramArtifact;
use noirc_evaluator::ssa::{SsaLogging, SsaProgramArtifact};
use noirc_frontend::debug::build_debug_crate_file;
use noirc_frontend::hir::def_map::{Contract, CrateDefMap};
use noirc_frontend::hir::Context;
Expand Down Expand Up @@ -70,6 +70,11 @@ pub struct CompileOptions {
#[arg(long, hide = true)]
pub show_ssa: bool,

/// Only show SSA passes whose name contains the provided string.
/// This setting takes precedence over `show_ssa` if it's not empty.
#[arg(long, hide = true)]
pub show_ssa_pass_name: Option<String>,

/// Emit the unoptimized SSA IR to file.
/// The IR will be dumped into the workspace target directory,
/// under `[compiled-package].ssa.json`.
Expand Down Expand Up @@ -126,11 +131,19 @@ pub struct CompileOptions {
#[arg(long)]
pub skip_underconstrained_check: bool,

/// Setting to decide on an inlining strategy for brillig functions.
/// Setting to decide on an inlining strategy for Brillig functions.
/// A more aggressive inliner should generate larger programs but more optimized
/// A less aggressive inliner should generate smaller programs
#[arg(long, hide = true, allow_hyphen_values = true, default_value_t = i64::MAX)]
pub inliner_aggressiveness: i64,

/// Setting the maximum acceptable increase in Brillig bytecode size due to
/// unrolling small loops. When left empty, any change is accepted as long
/// as it required fewer SSA instructions.
/// A higher value results in fewer jumps but a larger program.
/// A lower value keeps the original program if it was smaller, even if it has more jumps.
#[arg(long, hide = true, allow_hyphen_values = true)]
pub max_bytecode_increase_percent: Option<i32>,
}

pub fn parse_expression_width(input: &str) -> Result<ExpressionWidth, std::io::Error> {
Expand Down Expand Up @@ -577,7 +590,16 @@ pub fn compile_no_check(
}
let return_visibility = program.return_visibility;
let ssa_evaluator_options = noirc_evaluator::ssa::SsaEvaluatorOptions {
enable_ssa_logging: options.show_ssa,
ssa_logging: match &options.show_ssa_pass_name {
Some(string) => SsaLogging::Contains(string.clone()),
None => {
if options.show_ssa {
SsaLogging::All
} else {
SsaLogging::None
}
}
},
enable_brillig_logging: options.show_brillig,
force_brillig_output: options.force_brillig,
print_codegen_timings: options.benchmark_codegen,
Expand All @@ -589,6 +611,7 @@ pub fn compile_no_check(
emit_ssa: if options.emit_ssa { Some(context.package_build_path.clone()) } else { None },
skip_underconstrained_check: options.skip_underconstrained_check,
inliner_aggressiveness: options.inliner_aggressiveness,
max_bytecode_increase_percent: options.max_bytecode_increase_percent,
};

let SsaProgramArtifact { program, debug, warnings, names, brillig_names, error_types, .. } =
Expand Down
1 change: 1 addition & 0 deletions noir/noir-repo/compiler/noirc_evaluator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ cfg-if.workspace = true
proptest.workspace = true
similar-asserts.workspace = true
num-traits.workspace = true
test-case.workspace = true

[features]
bn254 = ["noirc_frontend/bn254"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl<'a> From<&'a SsaType> for AcirType {
SsaType::Numeric(numeric_type) => AcirType::NumericType(*numeric_type),
SsaType::Array(elements, size) => {
let elements = elements.iter().map(|e| e.into()).collect();
AcirType::Array(elements, *size)
AcirType::Array(elements, *size as usize)
}
_ => unreachable!("The type {value} cannot be represented in ACIR"),
}
Expand Down
27 changes: 12 additions & 15 deletions noir/noir-repo/compiler/noirc_evaluator/src/acir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ impl<'a> Context<'a> {
AcirValue::Array(_) => {
let block_id = self.block_id(param_id);
let len = if matches!(typ, Type::Array(_, _)) {
typ.flattened_size()
typ.flattened_size() as usize
} else {
return Err(InternalError::Unexpected {
expected: "Block params should be an array".to_owned(),
Expand Down Expand Up @@ -816,7 +816,9 @@ impl<'a> Context<'a> {
let inputs = vecmap(arguments, |arg| self.convert_value(*arg, dfg));
let output_count = result_ids
.iter()
.map(|result_id| dfg.type_of_value(*result_id).flattened_size())
.map(|result_id| {
dfg.type_of_value(*result_id).flattened_size() as usize
})
.sum();

let Some(acir_function_id) =
Expand Down Expand Up @@ -948,7 +950,7 @@ impl<'a> Context<'a> {
let block_id = self.block_id(&array_id);
let array_typ = dfg.type_of_value(array_id);
let len = if matches!(array_typ, Type::Array(_, _)) {
array_typ.flattened_size()
array_typ.flattened_size() as usize
} else {
Self::flattened_value_size(&output)
};
Expand Down Expand Up @@ -1444,7 +1446,7 @@ impl<'a> Context<'a> {
// a separate SSA value and restrictions on slice indices should be generated elsewhere in the SSA.
let array_typ = dfg.type_of_value(array);
let array_len = if !array_typ.contains_slice_element() {
array_typ.flattened_size()
array_typ.flattened_size() as usize
} else {
self.flattened_slice_size(array, dfg)
};
Expand Down Expand Up @@ -1539,7 +1541,7 @@ impl<'a> Context<'a> {
let value = self.convert_value(array, dfg);
let array_typ = dfg.type_of_value(array);
let len = if !array_typ.contains_slice_element() {
array_typ.flattened_size()
array_typ.flattened_size() as usize
} else {
self.flattened_slice_size(array, dfg)
};
Expand Down Expand Up @@ -1810,7 +1812,7 @@ impl<'a> Context<'a> {

return_values
.iter()
.fold(0, |acc, value_id| acc + dfg.type_of_value(*value_id).flattened_size())
.fold(0, |acc, value_id| acc + dfg.type_of_value(*value_id).flattened_size() as usize)
}

/// Converts an SSA terminator's return values into their ACIR representations
Expand Down Expand Up @@ -2156,7 +2158,7 @@ impl<'a> Context<'a> {
let inputs = vecmap(&arguments_no_slice_len, |arg| self.convert_value(*arg, dfg));

let output_count = result_ids.iter().fold(0usize, |sum, result_id| {
sum + dfg.try_get_array_length(*result_id).unwrap_or(1)
sum + dfg.try_get_array_length(*result_id).unwrap_or(1) as usize
});

let vars = self.acir_context.black_box_function(black_box, inputs, output_count)?;
Expand All @@ -2180,7 +2182,7 @@ impl<'a> Context<'a> {
endian,
field,
radix,
array_length as u32,
array_length,
result_type[0].clone().into(),
)
.map(|array| vec![array])
Expand All @@ -2194,12 +2196,7 @@ impl<'a> Context<'a> {
};

self.acir_context
.bit_decompose(
endian,
field,
array_length as u32,
result_type[0].clone().into(),
)
.bit_decompose(endian, field, array_length, result_type[0].clone().into())
.map(|array| vec![array])
}
Intrinsic::ArrayLen => {
Expand All @@ -2220,7 +2217,7 @@ impl<'a> Context<'a> {
let acir_value = self.convert_value(slice_contents, dfg);

let array_len = if !slice_typ.contains_slice_element() {
slice_typ.flattened_size()
slice_typ.flattened_size() as usize
} else {
self.flattened_slice_size(slice_contents, dfg)
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1823,7 +1823,7 @@ impl<'block> BrilligBlock<'block> {
Type::Array(_, nested_size) => {
let inner_array = BrilligArray {
pointer: self.brillig_context.allocate_register(),
size: *nested_size,
size: *nested_size as usize,
};
self.allocate_foreign_call_result_array(element_type, inner_array);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ pub(crate) fn allocate_value<F, Registers: RegisterAllocator>(
}
Type::Array(item_typ, elem_count) => BrilligVariable::BrilligArray(BrilligArray {
pointer: brillig_context.allocate_register(),
size: compute_array_length(&item_typ, elem_count),
size: compute_array_length(&item_typ, elem_count as usize),
}),
Type::Slice(_) => BrilligVariable::BrilligVector(BrilligVector {
pointer: brillig_context.allocate_register(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl FunctionContext {
vecmap(item_type.iter(), |item_typ| {
FunctionContext::ssa_type_to_parameter(item_typ)
}),
*size,
*size as usize,
),
Type::Slice(_) => {
panic!("ICE: Slice parameters cannot be derived from type information")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub(crate) fn type_to_heap_value_type(typ: &Type) -> HeapValueType {
),
Type::Array(elem_type, size) => HeapValueType::Array {
value_types: elem_type.as_ref().iter().map(type_to_heap_value_type).collect(),
size: typ.element_size() * size,
size: typ.element_size() * *size as usize,
},
Type::Slice(elem_type) => HeapValueType::Vector {
value_types: elem_type.as_ref().iter().map(type_to_heap_value_type).collect(),
Expand Down
Loading

0 comments on commit 4b35f0a

Please sign in to comment.