Skip to content

Commit

Permalink
feat: user super:: in LSP autocompletion if possible (noir-lang/noi…
Browse files Browse the repository at this point in the history
…r#5751)

fix: unconstrained fn mismatch is now a warning (noir-lang/noir#5764)
feat(perf): mem2reg function state for value loads to optimize across blocks (noir-lang/noir#5757)
feat: add `Expr::as_array`, `Expr::as_repeated_element_array` and same for slice (noir-lang/noir#5750)
chore: Add Brillig loop bytecode size regression and update noir-gates-diff report (noir-lang/noir#5747)
feat: fault-tolerant parsing of `fn` and `impl` (noir-lang/noir#5753)
fix: add missing trait impls for integer types to stdlib (noir-lang/noir#5738)
chore: refactor ACIR function IDs from raw integers to struct (noir-lang/noir#5748)
feat: (LSP) suggest names that match any part of the current prefix (noir-lang/noir#5752)
feat: LSP auto-import completion (noir-lang/noir#5741)
fix: Allow comptime code to use break without also being `unconstrained` (noir-lang/noir#5744)
feat: add `Expr::as_any_integer` and `Expr::as_member_access` (noir-lang/noir#5742)
chore: clarify Field use (noir-lang/noir#5740)
feat: add `Expr::as_binary_op` (noir-lang/noir#5734)
chore(docs): expanding solidity verifier chain list (noir-lang/noir#5587)
chore: apply some new lints across workspace (noir-lang/noir#5736)
feat: suggest trait methods in LSP completion (noir-lang/noir#5735)
feat: LSP autocomplete constructor fields (noir-lang/noir#5732)
feat: add `Expr::as_unary` (noir-lang/noir#5731)
chore: count brillig opcodes in nargo info (noir-lang/noir#5189)
feat: suggest tuple fields in LSP completion (noir-lang/noir#5730)
feat: add `Expr::as_bool` (noir-lang/noir#5729)
feat: add `Expr` methods: `as_tuple`, `as_parenthesized`, `as_index`, `as_if` (noir-lang/noir#5726)
feat: LSP signature help (noir-lang/noir#5725)
chore: split LSP completion.rs into several files (noir-lang/noir#5723)
feat: add `TraitImpl::trait_generic_args` and `TraitImpl::methods` (noir-lang/noir#5722)
fix: let LSP autocompletion work in more contexts (noir-lang/noir#5719)
fix(frontend): Continue type check if we are missing an unsafe block (noir-lang/noir#5720)
feat: add `unsafe` blocks for calling unconstrained code from constrained functions (noir-lang/noir#4429)
  • Loading branch information
AztecBot committed Aug 20, 2024
2 parents bdc0c65 + 551576d commit 173225e
Show file tree
Hide file tree
Showing 48 changed files with 1,188 additions and 359 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
cdbb940a883ae32dd84c667ec06b0d155f2d7520
5192e537708fc9ec51f53bb6a6629c9d682532d5
2 changes: 1 addition & 1 deletion noir/noir-repo/.github/workflows/gates_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
- name: Compare gates reports
id: gates_diff
uses: vezenovm/noir-gates-diff@acf12797860f237117e15c0d6e08d64253af52b6
uses: noir-lang/noir-gates-diff@1931aaaa848a1a009363d6115293f7b7fc72bb87
with:
report: gates_report.json
summaryQuantile: 0.9 # only display the 10% most significant circuit size diffs in the summary (defaults to 20%)
Expand Down
92 changes: 92 additions & 0 deletions noir/noir-repo/.github/workflows/gates_report_brillig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Report Brillig bytecode size diff

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/rust-toolchain@1.74.1

- 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
7z a -ttar -so -an ./dist/* | 7z a -si ./nargo-x86_64-unknown-linux-gnu.tar.gz
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: nargo
path: ./dist/*
retention-days: 3

compare_brillig_bytecode_size_reports:
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 Brillig bytecode size report
working-directory: ./test_programs
run: |
chmod +x gates_report_brillig.sh
./gates_report_brillig.sh
mv gates_report_brillig.json ../gates_report_brillig.json
- name: Compare Brillig bytecode size reports
id: brillig_bytecode_diff
uses: noir-lang/noir-gates-diff@3fb844067b25d1b59727ea600b614503b33503f4
with:
report: gates_report_brillig.json
header: |
# Changes to Brillig bytecode sizes
brillig_report: true
summaryQuantile: 0.9 # only display the 10% most significant bytecode size diffs in the summary (defaults to 20%)

- name: Add bytecode size diff to sticky comment
if: github.event_name == 'pull_request' || github.event_name == 'pull_request_target'
uses: marocchino/sticky-pull-request-comment@v2
with:
header: brillig
# delete the comment in case changes no longer impact brillig bytecode sizes
delete: ${{ !steps.brillig_bytecode_diff.outputs.markdown }}
message: ${{ steps.brillig_bytecode_diff.outputs.markdown }}
1 change: 1 addition & 0 deletions noir/noir-repo/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ tooling/noir_js/lib
!compiler/wasm/noir-script/target

gates_report.json
gates_report_brillig.json

# Github Actions scratch space
# This gives a location to download artifacts into the repository in CI without making git dirty.
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.

6 changes: 5 additions & 1 deletion noir/noir-repo/acvm-repo/acir/src/circuit/opcodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ use super::{
brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs},
directives::Directive,
};

pub mod function_id;
pub use function_id::AcirFunctionId;

use crate::native_types::{Expression, Witness};
use acir_field::AcirField;
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -125,7 +129,7 @@ pub enum Opcode<F> {
Call {
/// Id for the function being called. It is the responsibility of the executor
/// to fetch the appropriate circuit from this id.
id: u32,
id: AcirFunctionId,
/// Inputs to the function call
inputs: Vec<Witness>,
/// Outputs of the function call
Expand Down
17 changes: 17 additions & 0 deletions noir/noir-repo/acvm-repo/acir/src/circuit/opcodes/function_id.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use serde::{Deserialize, Serialize};

#[derive(Clone, Copy, PartialEq, Eq, Debug, Serialize, Deserialize, Hash)]
#[serde(transparent)]
pub struct AcirFunctionId(pub u32);

impl AcirFunctionId {
pub fn as_usize(&self) -> usize {
self.0 as usize
}
}

impl std::fmt::Display for AcirFunctionId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::collections::BTreeSet;
use acir::{
circuit::{
brillig::{BrilligBytecode, BrilligFunctionId, BrilligInputs, BrilligOutputs},
opcodes::{BlackBoxFuncCall, BlockId, FunctionInput, MemOp},
opcodes::{AcirFunctionId, BlackBoxFuncCall, BlockId, FunctionInput, MemOp},
Circuit, Opcode, Program, PublicInputs,
},
native_types::{Expression, Witness},
Expand Down Expand Up @@ -381,13 +381,13 @@ fn nested_acir_call_circuit() {
// x
// }
let nested_call = Opcode::Call {
id: 1,
id: AcirFunctionId(1),
inputs: vec![Witness(0), Witness(1)],
outputs: vec![Witness(2)],
predicate: None,
};
let nested_call_two = Opcode::Call {
id: 1,
id: AcirFunctionId(1),
inputs: vec![Witness(0), Witness(1)],
outputs: vec![Witness(3)],
predicate: None,
Expand Down Expand Up @@ -419,7 +419,7 @@ fn nested_acir_call_circuit() {
q_c: FieldElement::one() + FieldElement::one(),
});
let call = Opcode::Call {
id: 2,
id: AcirFunctionId(2),
inputs: vec![Witness(2), Witness(1)],
outputs: vec![Witness(3)],
predicate: None,
Expand Down
6 changes: 3 additions & 3 deletions noir/noir-repo/acvm-repo/acvm/src/pwg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use acir::{
brillig::ForeignCallResult,
circuit::{
brillig::{BrilligBytecode, BrilligFunctionId},
opcodes::{BlockId, ConstantOrWitnessEnum, FunctionInput},
opcodes::{AcirFunctionId, BlockId, ConstantOrWitnessEnum, FunctionInput},
AssertionPayload, ErrorSelector, ExpressionOrMemory, Opcode, OpcodeLocation,
RawAssertionPayload, ResolvedAssertionPayload, STRING_ERROR_SELECTOR,
},
Expand Down Expand Up @@ -575,7 +575,7 @@ impl<'a, F: AcirField, B: BlackBoxFunctionSolver<F>> ACVM<'a, F, B> {
else {
unreachable!("Not executing a Call opcode");
};
if *id == 0 {
if *id == AcirFunctionId(0) {
return Err(OpcodeResolutionError::AcirMainCallAttempted {
opcode_location: ErrorLocation::Resolved(OpcodeLocation::Acir(
self.instruction_pointer(),
Expand Down Expand Up @@ -716,7 +716,7 @@ pub(crate) fn is_predicate_false<F: AcirField>(
#[derive(Debug, Clone, PartialEq)]
pub struct AcirCallWaitInfo<F> {
/// Index in the list of ACIR function's that should be called
pub id: u32,
pub id: AcirFunctionId,
/// Initial witness for the given circuit to be called
pub initial_witness: WitnessMap<F>,
}
4 changes: 2 additions & 2 deletions noir/noir-repo/acvm-repo/acvm_js/src/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> ProgramExecutor<'a, B> {
acvm.resolve_pending_foreign_call(result);
}
ACVMStatus::RequiresAcirCall(call_info) => {
let acir_to_call = &self.functions[call_info.id as usize];
let acir_to_call = &self.functions[call_info.id.as_usize()];
let initial_witness = call_info.initial_witness;
let call_solved_witness = self
.execute_circuit(acir_to_call, initial_witness, witness_stack)
Expand All @@ -267,7 +267,7 @@ impl<'a, B: BlackBoxFunctionSolver<FieldElement>> ProgramExecutor<'a, B> {
}
}
acvm.resolve_pending_acir_call(call_resolved_outputs);
witness_stack.push(call_info.id, call_solved_witness.clone());
witness_stack.push(call_info.id.0, call_solved_witness.clone());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::ssa::ir::dfg::CallStack;
use crate::ssa::ir::types::Type as SsaType;
use crate::ssa::ir::{instruction::Endian, types::NumericType};
use acvm::acir::circuit::brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs};
use acvm::acir::circuit::opcodes::{BlockId, BlockType, MemOp};
use acvm::acir::circuit::opcodes::{AcirFunctionId, BlockId, BlockType, MemOp};
use acvm::acir::circuit::{AssertionPayload, ExpressionOrMemory, ExpressionWidth, Opcode};
use acvm::blackbox_solver;
use acvm::brillig_vm::{MemoryValue, VMStatus, VM};
Expand Down Expand Up @@ -1983,7 +1983,7 @@ impl<F: AcirField> AcirContext<F> {

pub(crate) fn call_acir_function(
&mut self,
id: u32,
id: AcirFunctionId,
inputs: Vec<AcirValue>,
output_count: usize,
predicate: AcirVar,
Expand Down
56 changes: 45 additions & 11 deletions noir/noir-repo/compiler/noirc_evaluator/src/ssa/acir_gen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use crate::brillig::brillig_ir::BrilligContext;
use crate::brillig::{brillig_gen::brillig_fn::FunctionContext as BrilligFunctionContext, Brillig};
use crate::errors::{InternalError, InternalWarning, RuntimeError, SsaReport};
pub(crate) use acir_ir::generated_acir::GeneratedAcir;
use acvm::acir::circuit::opcodes::BlockType;
use acvm::acir::circuit::opcodes::{AcirFunctionId, BlockType};
use noirc_frontend::monomorphization::ast::InlineType;

use acvm::acir::circuit::brillig::{BrilligBytecode, BrilligFunctionId};
Expand Down Expand Up @@ -775,7 +775,7 @@ impl<'a> Context<'a> {
.get(id)
.expect("ICE: should have an associated final index");
let output_vars = self.acir_context.call_acir_function(
*acir_function_id,
AcirFunctionId(*acir_function_id),
inputs,
output_count,
self.current_side_effects_enabled_var,
Expand Down Expand Up @@ -2867,9 +2867,13 @@ fn can_omit_element_sizes_array(array_typ: &Type) -> bool {

#[cfg(test)]
mod test {

use acvm::{
acir::{
circuit::{brillig::BrilligFunctionId, ExpressionWidth, Opcode, OpcodeLocation},
circuit::{
brillig::BrilligFunctionId, opcodes::AcirFunctionId, ExpressionWidth, Opcode,
OpcodeLocation,
},
native_types::Witness,
},
FieldElement,
Expand Down Expand Up @@ -3020,8 +3024,18 @@ mod test {
let main_opcodes = main_acir.opcodes();
assert_eq!(main_opcodes.len(), 3, "Should have two calls to `foo`");

check_call_opcode(&main_opcodes[0], 1, vec![Witness(0), Witness(1)], vec![Witness(2)]);
check_call_opcode(&main_opcodes[1], 1, vec![Witness(0), Witness(1)], vec![Witness(3)]);
check_call_opcode(
&main_opcodes[0],
AcirFunctionId(1),
vec![Witness(0), Witness(1)],
vec![Witness(2)],
);
check_call_opcode(
&main_opcodes[1],
AcirFunctionId(1),
vec![Witness(0), Witness(1)],
vec![Witness(3)],
);

if let Opcode::AssertZero(expr) = &main_opcodes[2] {
assert_eq!(expr.linear_combinations[0].0, FieldElement::from(1u128));
Expand Down Expand Up @@ -3076,9 +3090,19 @@ mod test {
let main_opcodes = main_acir.opcodes();
assert_eq!(main_opcodes.len(), 3, "Should have two calls to `foo` and an assert");

check_call_opcode(&main_opcodes[0], 1, vec![Witness(0), Witness(1)], vec![Witness(2)]);
check_call_opcode(
&main_opcodes[0],
AcirFunctionId(1),
vec![Witness(0), Witness(1)],
vec![Witness(2)],
);
// The output of the first call should be the input of the second call
check_call_opcode(&main_opcodes[1], 1, vec![Witness(2), Witness(1)], vec![Witness(3)]);
check_call_opcode(
&main_opcodes[1],
AcirFunctionId(1),
vec![Witness(2), Witness(1)],
vec![Witness(3)],
);
}

fn basic_nested_call(inline_type: InlineType) {
Expand Down Expand Up @@ -3167,9 +3191,19 @@ mod test {
assert_eq!(main_opcodes.len(), 3, "Should have two calls to `foo` and an assert");

// Both of these should call func_with_nested_foo_call f1
check_call_opcode(&main_opcodes[0], 1, vec![Witness(0), Witness(1)], vec![Witness(2)]);
check_call_opcode(
&main_opcodes[0],
AcirFunctionId(1),
vec![Witness(0), Witness(1)],
vec![Witness(2)],
);
// The output of the first call should be the input of the second call
check_call_opcode(&main_opcodes[1], 1, vec![Witness(0), Witness(1)], vec![Witness(3)]);
check_call_opcode(
&main_opcodes[1],
AcirFunctionId(1),
vec![Witness(0), Witness(1)],
vec![Witness(3)],
);

let func_with_nested_call_acir = &acir_functions[1];
let func_with_nested_call_opcodes = func_with_nested_call_acir.opcodes();
Expand All @@ -3182,15 +3216,15 @@ mod test {
// Should call foo f2
check_call_opcode(
&func_with_nested_call_opcodes[1],
2,
AcirFunctionId(2),
vec![Witness(3), Witness(1)],
vec![Witness(4)],
);
}

fn check_call_opcode(
opcode: &Opcode<FieldElement>,
expected_id: u32,
expected_id: AcirFunctionId,
expected_inputs: Vec<Witness>,
expected_outputs: Vec<Witness>,
) {
Expand Down
Loading

0 comments on commit 173225e

Please sign in to comment.