Skip to content

Commit

Permalink
Merge branch 'master' into aztec-packages
Browse files Browse the repository at this point in the history
* master: (21 commits)
  feat: add `Expr::resolve` and `TypedExpr::as_function_definition` (#5859)
  feat: LSP signature help for assert and assert_eq (#5862)
  fix(sha256): Add extra checks against message size when constructing msg blocks (#5861)
  feat: show backtrace on comptime assertion failures (#5842)
  feat: add `Expr::as_assert` (#5857)
  chore: underconstrained check in parallel (#5848)
  feat(meta): Comptime keccak (#5854)
  feat(optimization): Avoid merging identical (by ID) arrays (#5853)
  feat: add `FunctionDef::body` (#5825)
  fix(sha256): Fix upper bound when building msg block and delay final block compression under certain cases  (#5838)
  feat: remove unnecessary copying of vector size during reversal (#5852)
  chore: Add missing cases to arithmetic generics (#5841)
  feat: warn on unused imports (#5847)
  chore: add documentation to `to_be_bytes`, etc. (#5843)
  feat: simplify constant calls to `poseidon2_permutation`, `schnorr_verify` and `embedded_curve_add` (#5140)
  chore: don't require empty `Prover.toml` for programs with zero arguments but a return value (#5845)
  fix!: Check unused generics are bound (#5840)
  chore(perf): Simplify poseidon2 algorithm  (#5811)
  chore: redo typo PR by nnsW3 (#5834)
  fix(sha256): Perform compression per block and utilize ROM instead of RAM when setting up the message block (#5760)
  ...
  • Loading branch information
TomAFrench committed Aug 30, 2024
2 parents 65c5896 + bceee55 commit ac63c0f
Show file tree
Hide file tree
Showing 123 changed files with 3,585 additions and 639 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ criterion = "0.5.0"
# https://github.com/tikv/pprof-rs/pull/172
pprof = { version = "0.13", features = ["flamegraph", "criterion"] }


cfg-if = "1.0.0"
dirs = "4"
serde = { version = "1.0.136", features = ["derive"] }
serde_json = "1.0"
Expand All @@ -154,6 +154,7 @@ color-eyre = "0.6.2"
rand = "0.8.5"
proptest = "1.2.0"
proptest-derive = "0.4.0"
rayon = "1.8.0"

im = { version = "15.1", features = ["serde"] }
tracing = "0.1.40"
Expand Down
2 changes: 1 addition & 1 deletion acvm-repo/acir_field/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ ark-bn254.workspace = true
ark-bls12-381 = { workspace = true, optional = true }
ark-ff.workspace = true

cfg-if = "1.0.0"
cfg-if.workspace = true

[dev-dependencies]
proptest.workspace = true
Expand Down
1 change: 1 addition & 0 deletions aztec_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ noirc_frontend.workspace = true
noirc_errors.workspace = true
iter-extended.workspace = true
convert_case = "0.6.0"
im.workspace = true
regex = "1.10"
tiny-keccak = { version = "2.0.0", features = ["keccak"] }
12 changes: 10 additions & 2 deletions aztec_macros/src/utils/parse_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ fn empty_statement(statement: &mut Statement) {
StatementKind::For(for_loop_statement) => empty_for_loop_statement(for_loop_statement),
StatementKind::Comptime(statement) => empty_statement(statement),
StatementKind::Semi(expression) => empty_expression(expression),
StatementKind::Break | StatementKind::Continue | StatementKind::Error => (),
StatementKind::Break
| StatementKind::Continue
| StatementKind::Interned(_)
| StatementKind::Error => (),
}
}

Expand Down Expand Up @@ -271,12 +274,15 @@ fn empty_expression(expression: &mut Expression) {
ExpressionKind::Unsafe(block_expression, _span) => {
empty_block_expression(block_expression);
}
ExpressionKind::Quote(..) | ExpressionKind::Resolved(_) | ExpressionKind::Error => (),
ExpressionKind::AsTraitPath(path) => {
empty_unresolved_type(&mut path.typ);
empty_path(&mut path.trait_path);
empty_ident(&mut path.impl_item);
}
ExpressionKind::Quote(..)
| ExpressionKind::Resolved(_)
| ExpressionKind::Interned(_)
| ExpressionKind::Error => (),
}
}

Expand Down Expand Up @@ -353,6 +359,7 @@ fn empty_unresolved_type(unresolved_type: &mut UnresolvedType) {
| UnresolvedTypeData::Unit
| UnresolvedTypeData::Quoted(_)
| UnresolvedTypeData::Resolved(_)
| UnresolvedTypeData::Interned(_)
| UnresolvedTypeData::Unspecified
| UnresolvedTypeData::Error => (),
}
Expand Down Expand Up @@ -531,6 +538,7 @@ fn empty_lvalue(lvalue: &mut LValue) {
empty_expression(index);
}
LValue::Dereference(lvalue, _) => empty_lvalue(lvalue),
LValue::Interned(..) => (),
}
}

Expand Down
4 changes: 4 additions & 0 deletions compiler/noirc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ rust-embed.workspace = true
tracing.workspace = true

aztec_macros = { path = "../../aztec_macros" }

[features]
bn254 = ["noirc_frontend/bn254", "noirc_evaluator/bn254"]
bls12_381 = ["noirc_frontend/bls12_381", "noirc_evaluator/bls12_381"]
26 changes: 23 additions & 3 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ pub struct CompileOptions {
pub skip_underconstrained_check: bool,
}

#[derive(Clone, Debug, Default)]
pub struct CheckOptions {
pub compile_options: CompileOptions,
pub error_on_unused_imports: bool,
}

impl CheckOptions {
pub fn new(compile_options: &CompileOptions, error_on_unused_imports: bool) -> Self {
Self { compile_options: compile_options.clone(), error_on_unused_imports }
}
}

pub fn parse_expression_width(input: &str) -> Result<ExpressionWidth, std::io::Error> {
use std::io::{Error, ErrorKind};
let width = input
Expand Down Expand Up @@ -278,8 +290,10 @@ pub fn add_dep(
pub fn check_crate(
context: &mut Context,
crate_id: CrateId,
options: &CompileOptions,
check_options: &CheckOptions,
) -> CompilationResult<()> {
let options = &check_options.compile_options;

let macros: &[&dyn MacroProcessor] =
if options.disable_macros { &[] } else { &[&aztec_macros::AztecMacro] };

Expand All @@ -289,6 +303,7 @@ pub fn check_crate(
context,
options.debug_comptime_in_file.as_deref(),
options.arithmetic_generics,
check_options.error_on_unused_imports,
macros,
);
errors.extend(diagnostics.into_iter().map(|(error, file_id)| {
Expand Down Expand Up @@ -322,7 +337,10 @@ pub fn compile_main(
options: &CompileOptions,
cached_program: Option<CompiledProgram>,
) -> CompilationResult<CompiledProgram> {
let (_, mut warnings) = check_crate(context, crate_id, options)?;
let error_on_unused_imports = true;
let check_options = CheckOptions::new(options, error_on_unused_imports);

let (_, mut warnings) = check_crate(context, crate_id, &check_options)?;

let main = context.get_main_function(&crate_id).ok_or_else(|| {
// TODO(#2155): This error might be a better to exist in Nargo
Expand Down Expand Up @@ -357,7 +375,9 @@ pub fn compile_contract(
crate_id: CrateId,
options: &CompileOptions,
) -> CompilationResult<CompiledContract> {
let (_, warnings) = check_crate(context, crate_id, options)?;
let error_on_unused_imports = true;
let check_options = CheckOptions::new(options, error_on_unused_imports);
let (_, warnings) = check_crate(context, crate_id, &check_options)?;

// TODO: We probably want to error if contracts is empty
let contracts = context.get_all_contracts(&crate_id);
Expand Down
18 changes: 12 additions & 6 deletions compiler/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl CustomDiagnostic {
) -> CustomDiagnostic {
CustomDiagnostic {
message: primary_message,
secondaries: vec![CustomLabel::new(secondary_message, secondary_span)],
secondaries: vec![CustomLabel::new(secondary_message, secondary_span, None)],
notes: Vec::new(),
kind,
}
Expand Down Expand Up @@ -98,7 +98,7 @@ impl CustomDiagnostic {
) -> CustomDiagnostic {
CustomDiagnostic {
message: primary_message,
secondaries: vec![CustomLabel::new(secondary_message, secondary_span)],
secondaries: vec![CustomLabel::new(secondary_message, secondary_span, None)],
notes: Vec::new(),
kind: DiagnosticKind::Bug,
}
Expand All @@ -113,7 +113,11 @@ impl CustomDiagnostic {
}

pub fn add_secondary(&mut self, message: String, span: Span) {
self.secondaries.push(CustomLabel::new(message, span));
self.secondaries.push(CustomLabel::new(message, span, None));
}

pub fn add_secondary_with_file(&mut self, message: String, span: Span, file: fm::FileId) {
self.secondaries.push(CustomLabel::new(message, span, Some(file)));
}

pub fn is_error(&self) -> bool {
Expand Down Expand Up @@ -153,11 +157,12 @@ impl std::fmt::Display for CustomDiagnostic {
pub struct CustomLabel {
pub message: String,
pub span: Span,
pub file: Option<fm::FileId>,
}

impl CustomLabel {
fn new(message: String, span: Span) -> CustomLabel {
CustomLabel { message, span }
fn new(message: String, span: Span, file: Option<fm::FileId>) -> CustomLabel {
CustomLabel { message, span, file }
}
}

Expand Down Expand Up @@ -234,7 +239,8 @@ fn convert_diagnostic(
.map(|sl| {
let start_span = sl.span.start() as usize;
let end_span = sl.span.end() as usize;
Label::secondary(file_id, start_span..end_span).with_message(&sl.message)
let file = sl.file.unwrap_or(file_id);
Label::secondary(file, start_span..end_span).with_message(&sl.message)
})
.collect()
} else {
Expand Down
8 changes: 7 additions & 1 deletion compiler/noirc_evaluator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ serde_json.workspace = true
serde_with = "3.2.0"
tracing.workspace = true
chrono = "0.4.37"
rayon.workspace = true
cfg-if.workspace = true

[dev-dependencies]
proptest.workspace = true
proptest.workspace = true

[features]
bn254 = ["noirc_frontend/bn254"]
bls12_381= []
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use acvm::{acir::AcirField, FieldElement};
use fxhash::{FxHashMap as HashMap, FxHashSet as HashSet};
use iter_extended::vecmap;
use num_bigint::BigUint;
use std::rc::Rc;
use std::sync::Arc;

use super::brillig_black_box::convert_black_box_call;
use super::brillig_block_variables::BlockVariables;
Expand Down Expand Up @@ -1643,7 +1643,7 @@ impl<'block> BrilligBlock<'block> {

fn initialize_constant_array_runtime(
&mut self,
item_types: Rc<Vec<Type>>,
item_types: Arc<Vec<Type>>,
item_to_repeat: Vec<ValueId>,
item_count: usize,
pointer: MemoryAddress,
Expand Down
14 changes: 4 additions & 10 deletions compiler/noirc_evaluator/src/brillig/brillig_ir/codegen_memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,20 +276,14 @@ impl<F: AcirField + DebugToString, Registers: RegisterAllocator> BrilligContext<
let index_at_end_of_array = self.allocate_register();
let end_value_register = self.allocate_register();

self.codegen_loop(iteration_count, |ctx, iterator_register| {
// Load both values
ctx.codegen_array_get(pointer, iterator_register, start_value_register);
self.mov_instruction(index_at_end_of_array, vector.size);

self.codegen_loop(iteration_count, |ctx, iterator_register| {
// The index at the end of array is size - 1 - iterator
ctx.mov_instruction(index_at_end_of_array, size);
ctx.codegen_usize_op_in_place(index_at_end_of_array, BrilligBinaryOp::Sub, 1);
ctx.memory_op_instruction(
index_at_end_of_array,
iterator_register.address,
index_at_end_of_array,
BrilligBinaryOp::Sub,
);

// Load both values
ctx.codegen_array_get(vector.pointer, iterator_register, start_value_register);
ctx.codegen_array_get(
pointer,
SingleAddrVariable::new_usize(index_at_end_of_array),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::ssa::ir::{instruction::Endian, types::NumericType};
use acvm::acir::circuit::brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs};
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};
use acvm::{
acir::AcirField,
Expand Down Expand Up @@ -1459,7 +1458,6 @@ impl<F: AcirField> AcirContext<F> {
name,
BlackBoxFunc::MultiScalarMul
| BlackBoxFunc::Keccakf1600
| BlackBoxFunc::Sha256Compression
| BlackBoxFunc::Blake2s
| BlackBoxFunc::Blake3
| BlackBoxFunc::AND
Expand Down Expand Up @@ -2152,7 +2150,11 @@ fn execute_brillig<F: AcirField>(
}

// Instantiate a Brillig VM given the solved input registers and memory, along with the Brillig bytecode.
let mut vm = VM::new(calldata, code, Vec::new(), &blackbox_solver::StubbedBlackBoxSolver);
//
// We pass a stubbed solver here as a concrete solver implies a field choice which conflicts with this function
// being generic.
let solver = acvm::blackbox_solver::StubbedBlackBoxSolver;
let mut vm = VM::new(calldata, code, Vec::new(), &solver);

// Run the Brillig VM on these inputs, bytecode, etc!
let vm_status = vm.process_opcodes();
Expand Down
Loading

0 comments on commit ac63c0f

Please sign in to comment.