Skip to content

Commit 4b35f0a

Browse files
committed
[1 changes] feat(ssa): Simplify array get from set that writes to the 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)
1 parent 0577c1a commit 4b35f0a

File tree

83 files changed

+2782
-1294
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+2782
-1294
lines changed

.noir-sync-commit

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
68c32b4ffd9b069fe4b119327dbf4018c17ab9d4
1+
304403f24e2a15b57bb054c4402a8d7f8d275668
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Report Peak Memory
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
9+
jobs:
10+
build-nargo:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
matrix:
14+
target: [x86_64-unknown-linux-gnu]
15+
16+
steps:
17+
- name: Checkout Noir repo
18+
uses: actions/checkout@v4
19+
20+
- name: Setup toolchain
21+
uses: dtolnay/rust-toolchain@1.74.1
22+
23+
- uses: Swatinem/rust-cache@v2
24+
with:
25+
key: ${{ matrix.target }}
26+
cache-on-failure: true
27+
save-if: ${{ github.event_name != 'merge_group' }}
28+
29+
- name: Build Nargo
30+
run: cargo build --package nargo_cli --release
31+
32+
- name: Package artifacts
33+
run: |
34+
mkdir dist
35+
cp ./target/release/nargo ./dist/nargo
36+
37+
- name: Upload artifact
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: nargo
41+
path: ./dist/*
42+
retention-days: 3
43+
44+
generate_memory_report:
45+
needs: [build-nargo]
46+
runs-on: ubuntu-latest
47+
permissions:
48+
pull-requests: write
49+
50+
steps:
51+
- uses: actions/checkout@v4
52+
53+
- name: Download nargo binary
54+
uses: actions/download-artifact@v4
55+
with:
56+
name: nargo
57+
path: ./nargo
58+
59+
- name: Set nargo on PATH
60+
run: |
61+
nargo_binary="${{ github.workspace }}/nargo/nargo"
62+
chmod +x $nargo_binary
63+
echo "$(dirname $nargo_binary)" >> $GITHUB_PATH
64+
export PATH="$PATH:$(dirname $nargo_binary)"
65+
nargo -V
66+
67+
- name: Generate Memory report
68+
working-directory: ./test_programs
69+
run: |
70+
chmod +x memory_report.sh
71+
./memory_report.sh
72+
mv memory_report.json ../memory_report.json
73+
74+
- name: Parse memory report
75+
id: memory_report
76+
uses: noir-lang/noir-bench-report@ccb0d806a91d3bd86dba0ba3d580a814eed5673c
77+
with:
78+
report: memory_report.json
79+
header: |
80+
# Memory Report
81+
memory_report: true
82+
83+
- name: Add memory report to sticky comment
84+
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
85+
uses: marocchino/sticky-pull-request-comment@v2
86+
with:
87+
header: memory
88+
message: ${{ steps.memory_report.outputs.markdown }}

noir/noir-repo/.github/workflows/test-js-packages.yml

+23-7
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,25 @@ jobs:
519519
fail-fast: false
520520
matrix:
521521
project:
522-
# Disabled as these are currently failing with many visibility errors
523-
- { repo: AztecProtocol/aztec-nr, path: ./ }
522+
- { repo: noir-lang/ec, path: ./ }
523+
- { repo: noir-lang/eddsa, path: ./ }
524+
- { repo: noir-lang/mimc, path: ./ }
525+
- { repo: noir-lang/noir_sort, path: ./ }
526+
- { repo: noir-lang/noir-edwards, path: ./ }
527+
- { repo: noir-lang/noir-bignum, path: ./ }
528+
- { repo: noir-lang/noir_bigcurve, path: ./ }
529+
- { repo: noir-lang/noir_base64, path: ./ }
530+
- { repo: noir-lang/noir_string_search, path: ./ }
531+
- { repo: noir-lang/sparse_array, path: ./ }
532+
- { repo: noir-lang/noir_rsa, path: ./lib }
533+
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/aztec-nr }
524534
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-contracts }
525-
# Disabled as aztec-packages requires a setup-step in order to generate a `Nargo.toml`
526-
#- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits }
527-
- { repo: noir-lang/noir-edwards, path: ./, ref: 3188ea74fe3b059219a2ea87899589c266256d74 }
535+
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits/crates/parity-lib }
536+
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits/crates/private-kernel-lib }
537+
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits/crates/reset-kernel-lib }
538+
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits/crates/rollup-lib }
539+
- { repo: AztecProtocol/aztec-packages, path: ./noir-projects/noir-protocol-circuits/crates/types }
540+
528541
name: Check external repo - ${{ matrix.project.repo }}
529542
steps:
530543
- name: Checkout
@@ -554,9 +567,12 @@ jobs:
554567
# Github actions seems to not expand "**" in globs by default.
555568
shopt -s globstar
556569
sed -i '/^compiler_version/d' ./**/Nargo.toml
557-
- name: Run nargo check
570+
571+
- name: Run nargo test
558572
working-directory: ./test-repo/${{ matrix.project.path }}
559-
run: nargo check
573+
run: nargo test --silence-warnings
574+
env:
575+
NARGO_IGNORE_TEST_FAILURES_FROM_FOREIGN_CALLS: true
560576

561577
# This is a job which depends on all test jobs and reports the overall status.
562578
# This allows us to add/remove test jobs without having to update the required workflows.

noir/noir-repo/Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

noir/noir-repo/acvm-repo/acvm_js/build.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function run_if_available {
2525
require_command jq
2626
require_command cargo
2727
require_command wasm-bindgen
28-
#require_command wasm-opt
28+
require_command wasm-opt
2929

3030
self_path=$(dirname "$(readlink -f "$0")")
3131
pname=$(cargo read-manifest | jq -r '.name')

noir/noir-repo/compiler/integration-tests/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"lint": "NODE_NO_WARNINGS=1 eslint . --ext .ts --ignore-path ./.eslintignore --max-warnings 0"
1414
},
1515
"dependencies": {
16-
"@aztec/bb.js": "portal:../../../../barretenberg/ts",
16+
"@aztec/bb.js": "0.63.1",
1717
"@noir-lang/noir_js": "workspace:*",
1818
"@noir-lang/noir_wasm": "workspace:*",
1919
"@nomicfoundation/hardhat-chai-matchers": "^2.0.0",

noir/noir-repo/compiler/noirc_driver/src/lib.rs

+26-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use noirc_abi::{AbiParameter, AbiType, AbiValue};
1313
use noirc_errors::{CustomDiagnostic, FileDiagnostic};
1414
use noirc_evaluator::create_program;
1515
use noirc_evaluator::errors::RuntimeError;
16-
use noirc_evaluator::ssa::SsaProgramArtifact;
16+
use noirc_evaluator::ssa::{SsaLogging, SsaProgramArtifact};
1717
use noirc_frontend::debug::build_debug_crate_file;
1818
use noirc_frontend::hir::def_map::{Contract, CrateDefMap};
1919
use noirc_frontend::hir::Context;
@@ -70,6 +70,11 @@ pub struct CompileOptions {
7070
#[arg(long, hide = true)]
7171
pub show_ssa: bool,
7272

73+
/// Only show SSA passes whose name contains the provided string.
74+
/// This setting takes precedence over `show_ssa` if it's not empty.
75+
#[arg(long, hide = true)]
76+
pub show_ssa_pass_name: Option<String>,
77+
7378
/// Emit the unoptimized SSA IR to file.
7479
/// The IR will be dumped into the workspace target directory,
7580
/// under `[compiled-package].ssa.json`.
@@ -126,11 +131,19 @@ pub struct CompileOptions {
126131
#[arg(long)]
127132
pub skip_underconstrained_check: bool,
128133

129-
/// Setting to decide on an inlining strategy for brillig functions.
134+
/// Setting to decide on an inlining strategy for Brillig functions.
130135
/// A more aggressive inliner should generate larger programs but more optimized
131136
/// A less aggressive inliner should generate smaller programs
132137
#[arg(long, hide = true, allow_hyphen_values = true, default_value_t = i64::MAX)]
133138
pub inliner_aggressiveness: i64,
139+
140+
/// Setting the maximum acceptable increase in Brillig bytecode size due to
141+
/// unrolling small loops. When left empty, any change is accepted as long
142+
/// as it required fewer SSA instructions.
143+
/// A higher value results in fewer jumps but a larger program.
144+
/// A lower value keeps the original program if it was smaller, even if it has more jumps.
145+
#[arg(long, hide = true, allow_hyphen_values = true)]
146+
pub max_bytecode_increase_percent: Option<i32>,
134147
}
135148

136149
pub fn parse_expression_width(input: &str) -> Result<ExpressionWidth, std::io::Error> {
@@ -577,7 +590,16 @@ pub fn compile_no_check(
577590
}
578591
let return_visibility = program.return_visibility;
579592
let ssa_evaluator_options = noirc_evaluator::ssa::SsaEvaluatorOptions {
580-
enable_ssa_logging: options.show_ssa,
593+
ssa_logging: match &options.show_ssa_pass_name {
594+
Some(string) => SsaLogging::Contains(string.clone()),
595+
None => {
596+
if options.show_ssa {
597+
SsaLogging::All
598+
} else {
599+
SsaLogging::None
600+
}
601+
}
602+
},
581603
enable_brillig_logging: options.show_brillig,
582604
force_brillig_output: options.force_brillig,
583605
print_codegen_timings: options.benchmark_codegen,
@@ -589,6 +611,7 @@ pub fn compile_no_check(
589611
emit_ssa: if options.emit_ssa { Some(context.package_build_path.clone()) } else { None },
590612
skip_underconstrained_check: options.skip_underconstrained_check,
591613
inliner_aggressiveness: options.inliner_aggressiveness,
614+
max_bytecode_increase_percent: options.max_bytecode_increase_percent,
592615
};
593616

594617
let SsaProgramArtifact { program, debug, warnings, names, brillig_names, error_types, .. } =

noir/noir-repo/compiler/noirc_evaluator/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ cfg-if.workspace = true
3333
proptest.workspace = true
3434
similar-asserts.workspace = true
3535
num-traits.workspace = true
36+
test-case.workspace = true
3637

3738
[features]
3839
bn254 = ["noirc_frontend/bn254"]

noir/noir-repo/compiler/noirc_evaluator/src/acir/acir_variable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<'a> From<&'a SsaType> for AcirType {
9292
SsaType::Numeric(numeric_type) => AcirType::NumericType(*numeric_type),
9393
SsaType::Array(elements, size) => {
9494
let elements = elements.iter().map(|e| e.into()).collect();
95-
AcirType::Array(elements, *size)
95+
AcirType::Array(elements, *size as usize)
9696
}
9797
_ => unreachable!("The type {value} cannot be represented in ACIR"),
9898
}

noir/noir-repo/compiler/noirc_evaluator/src/acir/mod.rs

+12-15
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ impl<'a> Context<'a> {
571571
AcirValue::Array(_) => {
572572
let block_id = self.block_id(param_id);
573573
let len = if matches!(typ, Type::Array(_, _)) {
574-
typ.flattened_size()
574+
typ.flattened_size() as usize
575575
} else {
576576
return Err(InternalError::Unexpected {
577577
expected: "Block params should be an array".to_owned(),
@@ -816,7 +816,9 @@ impl<'a> Context<'a> {
816816
let inputs = vecmap(arguments, |arg| self.convert_value(*arg, dfg));
817817
let output_count = result_ids
818818
.iter()
819-
.map(|result_id| dfg.type_of_value(*result_id).flattened_size())
819+
.map(|result_id| {
820+
dfg.type_of_value(*result_id).flattened_size() as usize
821+
})
820822
.sum();
821823

822824
let Some(acir_function_id) =
@@ -948,7 +950,7 @@ impl<'a> Context<'a> {
948950
let block_id = self.block_id(&array_id);
949951
let array_typ = dfg.type_of_value(array_id);
950952
let len = if matches!(array_typ, Type::Array(_, _)) {
951-
array_typ.flattened_size()
953+
array_typ.flattened_size() as usize
952954
} else {
953955
Self::flattened_value_size(&output)
954956
};
@@ -1444,7 +1446,7 @@ impl<'a> Context<'a> {
14441446
// a separate SSA value and restrictions on slice indices should be generated elsewhere in the SSA.
14451447
let array_typ = dfg.type_of_value(array);
14461448
let array_len = if !array_typ.contains_slice_element() {
1447-
array_typ.flattened_size()
1449+
array_typ.flattened_size() as usize
14481450
} else {
14491451
self.flattened_slice_size(array, dfg)
14501452
};
@@ -1539,7 +1541,7 @@ impl<'a> Context<'a> {
15391541
let value = self.convert_value(array, dfg);
15401542
let array_typ = dfg.type_of_value(array);
15411543
let len = if !array_typ.contains_slice_element() {
1542-
array_typ.flattened_size()
1544+
array_typ.flattened_size() as usize
15431545
} else {
15441546
self.flattened_slice_size(array, dfg)
15451547
};
@@ -1810,7 +1812,7 @@ impl<'a> Context<'a> {
18101812

18111813
return_values
18121814
.iter()
1813-
.fold(0, |acc, value_id| acc + dfg.type_of_value(*value_id).flattened_size())
1815+
.fold(0, |acc, value_id| acc + dfg.type_of_value(*value_id).flattened_size() as usize)
18141816
}
18151817

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

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

21622164
let vars = self.acir_context.black_box_function(black_box, inputs, output_count)?;
@@ -2180,7 +2182,7 @@ impl<'a> Context<'a> {
21802182
endian,
21812183
field,
21822184
radix,
2183-
array_length as u32,
2185+
array_length,
21842186
result_type[0].clone().into(),
21852187
)
21862188
.map(|array| vec![array])
@@ -2194,12 +2196,7 @@ impl<'a> Context<'a> {
21942196
};
21952197

21962198
self.acir_context
2197-
.bit_decompose(
2198-
endian,
2199-
field,
2200-
array_length as u32,
2201-
result_type[0].clone().into(),
2202-
)
2199+
.bit_decompose(endian, field, array_length, result_type[0].clone().into())
22032200
.map(|array| vec![array])
22042201
}
22052202
Intrinsic::ArrayLen => {
@@ -2220,7 +2217,7 @@ impl<'a> Context<'a> {
22202217
let acir_value = self.convert_value(slice_contents, dfg);
22212218

22222219
let array_len = if !slice_typ.contains_slice_element() {
2223-
slice_typ.flattened_size()
2220+
slice_typ.flattened_size() as usize
22242221
} else {
22252222
self.flattened_slice_size(slice_contents, dfg)
22262223
};

noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,7 @@ impl<'block> BrilligBlock<'block> {
18231823
Type::Array(_, nested_size) => {
18241824
let inner_array = BrilligArray {
18251825
pointer: self.brillig_context.allocate_register(),
1826-
size: *nested_size,
1826+
size: *nested_size as usize,
18271827
};
18281828
self.allocate_foreign_call_result_array(element_type, inner_array);
18291829

noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block_variables.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub(crate) fn allocate_value<F, Registers: RegisterAllocator>(
142142
}
143143
Type::Array(item_typ, elem_count) => BrilligVariable::BrilligArray(BrilligArray {
144144
pointer: brillig_context.allocate_register(),
145-
size: compute_array_length(&item_typ, elem_count),
145+
size: compute_array_length(&item_typ, elem_count as usize),
146146
}),
147147
Type::Slice(_) => BrilligVariable::BrilligVector(BrilligVector {
148148
pointer: brillig_context.allocate_register(),

noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl FunctionContext {
5959
vecmap(item_type.iter(), |item_typ| {
6060
FunctionContext::ssa_type_to_parameter(item_typ)
6161
}),
62-
*size,
62+
*size as usize,
6363
),
6464
Type::Slice(_) => {
6565
panic!("ICE: Slice parameters cannot be derived from type information")

noir/noir-repo/compiler/noirc_evaluator/src/brillig/brillig_ir/brillig_variable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ pub(crate) fn type_to_heap_value_type(typ: &Type) -> HeapValueType {
8888
),
8989
Type::Array(elem_type, size) => HeapValueType::Array {
9090
value_types: elem_type.as_ref().iter().map(type_to_heap_value_type).collect(),
91-
size: typ.element_size() * size,
91+
size: typ.element_size() * *size as usize,
9292
},
9393
Type::Slice(elem_type) => HeapValueType::Vector {
9494
value_types: elem_type.as_ref().iter().map(type_to_heap_value_type).collect(),

0 commit comments

Comments
 (0)