Skip to content

Commit

Permalink
[1 changes] feat: Allow comptime attributes on traits & functions (no…
Browse files Browse the repository at this point in the history
…ir-lang/noir#5496)

feat: skip reading values immediately after it being written into an array (noir-lang/noir#5449)
fix: Don't type error when calling certain trait impls in the interpreter (noir-lang/noir#5471)
feat: LSP hover (noir-lang/noir#5491)
chore: update typo PR script (noir-lang/noir#5488)
feat: Handle ACIR calls in the debugger (noir-lang/noir#5051)
feat: Add unquote function (noir-lang/noir#5497)
feat: Allow arguments to attribute functions (noir-lang/noir#5494)
  • Loading branch information
AztecBot committed Jul 15, 2024
1 parent e44ef70 commit cf5cc28
Show file tree
Hide file tree
Showing 127 changed files with 4,168 additions and 1,257 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
bb6913ac53620fabd73e24ca1a2b1369225903ec
b59a29e5b246121a4d81e4894a4b10f5df4dd5cf
2 changes: 1 addition & 1 deletion noir/noir-repo/acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ mod tests {
use std::collections::BTreeSet;

use super::{
opcodes::{BlackBoxFuncCall, ConstantOrWitnessEnum, FunctionInput},
opcodes::{BlackBoxFuncCall, FunctionInput},
Circuit, Compression, Opcode, PublicInputs,
};
use crate::{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ mod tests {
use crate::{circuit::Opcode, native_types::Witness};
use acir_field::{AcirField, FieldElement};

use super::{BlackBoxFuncCall, ConstantOrWitnessEnum, FunctionInput};
use super::{BlackBoxFuncCall, FunctionInput};

fn keccakf1600_opcode<F: AcirField>() -> Opcode<F> {
let inputs: Box<[FunctionInput<F>; 25]> =
Expand Down
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, BrilligInputs, BrilligOutputs},
opcodes::{BlackBoxFuncCall, BlockId, ConstantOrWitnessEnum, FunctionInput, MemOp},
opcodes::{BlackBoxFuncCall, BlockId, FunctionInput, MemOp},
Circuit, Opcode, Program, PublicInputs,
},
native_types::{Expression, Witness},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ mod tests {
use crate::compiler::optimizers::redundant_range::RangeOptimizer;
use acir::{
circuit::{
opcodes::{BlackBoxFuncCall, ConstantOrWitnessEnum, FunctionInput},
opcodes::{BlackBoxFuncCall, FunctionInput},
Circuit, ExpressionWidth, Opcode, PublicInputs,
},
native_types::{Expression, Witness},
Expand Down
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
4 changes: 2 additions & 2 deletions noir/noir-repo/acvm-repo/blackbox_solver/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct BigIntSolver {
}

impl BigIntSolver {
pub(crate) fn get_bigint(
pub fn get_bigint(
&self,
id: u32,
func: BlackBoxFunc,
Expand All @@ -32,7 +32,7 @@ impl BigIntSolver {
.cloned()
}

pub(crate) fn get_modulus(
pub fn get_modulus(
&self,
id: u32,
func: BlackBoxFunc,
Expand Down
8 changes: 8 additions & 0 deletions noir/noir-repo/acvm-repo/brillig_vm/src/black_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,14 @@ impl BrilligBigintSolver {
rhs: u32,
func: BlackBoxFunc,
) -> Result<u32, BlackBoxResolutionError> {
let modulus_lhs = self.bigint_solver.get_modulus(lhs, func)?;
let modulus_rhs = self.bigint_solver.get_modulus(rhs, func)?;
if modulus_lhs != modulus_rhs {
return Err(BlackBoxResolutionError::Failed(
func,
"moduli should be identical in BigInt operation".to_string(),
));
}
let id = self.create_bigint_id();
self.bigint_solver.bigint_op(lhs, rhs, id, func)?;
Ok(id)
Expand Down
1 change: 1 addition & 0 deletions noir/noir-repo/compiler/fm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ license.workspace = true

[dependencies]
codespan-reporting.workspace = true
iter-extended.workspace = true
serde.workspace = true

[dev-dependencies]
Expand Down
21 changes: 21 additions & 0 deletions noir/noir-repo/compiler/fm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ mod file_map;

pub use file_map::{File, FileId, FileMap, PathString};

use iter_extended::vecmap;
// Re-export for the lsp
pub use codespan_reporting::files as codespan_files;

Expand Down Expand Up @@ -103,6 +104,26 @@ impl FileManager {
pub fn name_to_id(&self, file_name: PathBuf) -> Option<FileId> {
self.file_map.get_file_id(&PathString::from_path(file_name))
}

/// Find a file by its path suffix, e.g. "src/main.nr" is a suffix of
/// "some_dir/package_name/src/main.nr"`
pub fn find_by_path_suffix(&self, suffix: &str) -> Result<Option<FileId>, Vec<PathBuf>> {
let suffix_path: Vec<_> = Path::new(suffix).components().rev().collect();
let results: Vec<_> = self
.path_to_id
.iter()
.filter(|(path, _id)| {
path.components().rev().zip(suffix_path.iter()).all(|(x, y)| &x == y)
})
.collect();
if results.is_empty() {
Ok(None)
} else if results.len() == 1 {
Ok(Some(*results[0].1))
} else {
Err(vecmap(results, |(path, _id)| path.clone()))
}
}
}

pub trait NormalizePath {
Expand Down
11 changes: 10 additions & 1 deletion noir/noir-repo/compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@ pub struct CompileOptions {
#[arg(long, hide = true)]
pub use_legacy: bool,

/// Enable printing results of comptime evaluation: provide a path suffix
/// for the module to debug, e.g. "package_name/src/main.nr"
#[arg(long)]
pub debug_comptime_in_file: Option<String>,

/// Outputs the paths to any modified artifacts
#[arg(long, hide = true)]
pub show_artifact_paths: bool,
Expand Down Expand Up @@ -258,12 +263,14 @@ pub fn check_crate(
deny_warnings: bool,
disable_macros: bool,
use_legacy: bool,
debug_comptime_in_file: Option<&str>,
) -> CompilationResult<()> {
let macros: &[&dyn MacroProcessor] =
if disable_macros { &[] } else { &[&aztec_macros::AztecMacro as &dyn MacroProcessor] };

let mut errors = vec![];
let diagnostics = CrateDefMap::collect_defs(crate_id, context, use_legacy, macros);
let diagnostics =
CrateDefMap::collect_defs(crate_id, context, use_legacy, debug_comptime_in_file, macros);
errors.extend(diagnostics.into_iter().map(|(error, file_id)| {
let diagnostic = CustomDiagnostic::from(&error);
diagnostic.in_file(file_id)
Expand Down Expand Up @@ -301,6 +308,7 @@ pub fn compile_main(
options.deny_warnings,
options.disable_macros,
options.use_legacy,
options.debug_comptime_in_file.as_deref(),
)?;

let main = context.get_main_function(&crate_id).ok_or_else(|| {
Expand Down Expand Up @@ -342,6 +350,7 @@ pub fn compile_contract(
options.deny_warnings,
options.disable_macros,
options.use_legacy,
options.debug_comptime_in_file.as_deref(),
)?;

// TODO: We probably want to error if contracts is empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn stdlib_does_not_produce_constant_warnings() -> Result<(), ErrorsAndWarnings>
let root_crate_id = prepare_crate(&mut context, file_name);

let ((), warnings) =
noirc_driver::check_crate(&mut context, root_crate_id, false, false, false)?;
noirc_driver::check_crate(&mut context, root_crate_id, false, false, false, None)?;

assert_eq!(warnings, Vec::new(), "stdlib is producing {} warnings", warnings.len());

Expand Down
49 changes: 41 additions & 8 deletions noir/noir-repo/compiler/noirc_errors/src/reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub enum DiagnosticKind {
Error,
Bug,
Warning,
Info,
}

/// A count of errors that have been already reported to stderr
Expand All @@ -37,30 +38,57 @@ impl CustomDiagnostic {
}
}

pub fn simple_error(
fn simple_with_kind(
primary_message: String,
secondary_message: String,
secondary_span: Span,
kind: DiagnosticKind,
) -> CustomDiagnostic {
CustomDiagnostic {
message: primary_message,
secondaries: vec![CustomLabel::new(secondary_message, secondary_span)],
notes: Vec::new(),
kind: DiagnosticKind::Error,
kind,
}
}

pub fn simple_error(
primary_message: String,
secondary_message: String,
secondary_span: Span,
) -> CustomDiagnostic {
Self::simple_with_kind(
primary_message,
secondary_message,
secondary_span,
DiagnosticKind::Error,
)
}

pub fn simple_warning(
primary_message: String,
secondary_message: String,
secondary_span: Span,
) -> CustomDiagnostic {
CustomDiagnostic {
message: primary_message,
secondaries: vec![CustomLabel::new(secondary_message, secondary_span)],
notes: Vec::new(),
kind: DiagnosticKind::Warning,
}
Self::simple_with_kind(
primary_message,
secondary_message,
secondary_span,
DiagnosticKind::Warning,
)
}

pub fn simple_info(
primary_message: String,
secondary_message: String,
secondary_span: Span,
) -> CustomDiagnostic {
Self::simple_with_kind(
primary_message,
secondary_message,
secondary_span,
DiagnosticKind::Info,
)
}

pub fn simple_bug(
Expand Down Expand Up @@ -96,6 +124,10 @@ impl CustomDiagnostic {
matches!(self.kind, DiagnosticKind::Warning)
}

pub fn is_info(&self) -> bool {
matches!(self.kind, DiagnosticKind::Info)
}

pub fn is_bug(&self) -> bool {
matches!(self.kind, DiagnosticKind::Bug)
}
Expand Down Expand Up @@ -191,6 +223,7 @@ fn convert_diagnostic(
) -> Diagnostic<fm::FileId> {
let diagnostic = match (cd.kind, deny_warnings) {
(DiagnosticKind::Warning, false) => Diagnostic::warning(),
(DiagnosticKind::Info, _) => Diagnostic::note(),
(DiagnosticKind::Bug, ..) => Diagnostic::bug(),
_ => Diagnostic::error(),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use acvm::{
use crate::brillig::brillig_ir::{
brillig_variable::{BrilligVariable, BrilligVector, SingleAddrVariable},
debug_show::DebugToString,
BrilligBinaryOp, BrilligContext,
BrilligContext,
};

/// Transforms SSA's black box function calls into the corresponding brillig instructions
Expand Down Expand Up @@ -239,11 +239,10 @@ pub(crate) fn convert_black_box_call<F: AcirField + DebugToString>(
BlackBoxFunc::RecursiveAggregation => {}
BlackBoxFunc::BigIntAdd => {
if let (
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(lhs_modulus), BrilligVariable::SingleAddr(rhs), BrilligVariable::SingleAddr(rhs_modulus)],
[BrilligVariable::SingleAddr(output), BrilligVariable::SingleAddr(modulus_id)],
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(_lhs_modulus), BrilligVariable::SingleAddr(rhs), BrilligVariable::SingleAddr(_rhs_modulus)],
[BrilligVariable::SingleAddr(output), BrilligVariable::SingleAddr(_modulus_id)],
) = (function_arguments, function_results)
{
prepare_bigint_output(brillig_context, lhs_modulus, rhs_modulus, modulus_id);
brillig_context.black_box_op_instruction(BlackBoxOp::BigIntAdd {
lhs: lhs.address,
rhs: rhs.address,
Expand All @@ -257,11 +256,10 @@ pub(crate) fn convert_black_box_call<F: AcirField + DebugToString>(
}
BlackBoxFunc::BigIntSub => {
if let (
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(lhs_modulus), BrilligVariable::SingleAddr(rhs), BrilligVariable::SingleAddr(rhs_modulus)],
[BrilligVariable::SingleAddr(output), BrilligVariable::SingleAddr(modulus_id)],
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(_lhs_modulus), BrilligVariable::SingleAddr(rhs), BrilligVariable::SingleAddr(_rhs_modulus)],
[BrilligVariable::SingleAddr(output), BrilligVariable::SingleAddr(_modulus_id)],
) = (function_arguments, function_results)
{
prepare_bigint_output(brillig_context, lhs_modulus, rhs_modulus, modulus_id);
brillig_context.black_box_op_instruction(BlackBoxOp::BigIntSub {
lhs: lhs.address,
rhs: rhs.address,
Expand All @@ -275,11 +273,10 @@ pub(crate) fn convert_black_box_call<F: AcirField + DebugToString>(
}
BlackBoxFunc::BigIntMul => {
if let (
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(lhs_modulus), BrilligVariable::SingleAddr(rhs), BrilligVariable::SingleAddr(rhs_modulus)],
[BrilligVariable::SingleAddr(output), BrilligVariable::SingleAddr(modulus_id)],
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(_lhs_modulus), BrilligVariable::SingleAddr(rhs), BrilligVariable::SingleAddr(_rhs_modulus)],
[BrilligVariable::SingleAddr(output), BrilligVariable::SingleAddr(_modulus_id)],
) = (function_arguments, function_results)
{
prepare_bigint_output(brillig_context, lhs_modulus, rhs_modulus, modulus_id);
brillig_context.black_box_op_instruction(BlackBoxOp::BigIntMul {
lhs: lhs.address,
rhs: rhs.address,
Expand All @@ -293,11 +290,10 @@ pub(crate) fn convert_black_box_call<F: AcirField + DebugToString>(
}
BlackBoxFunc::BigIntDiv => {
if let (
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(lhs_modulus), BrilligVariable::SingleAddr(rhs), BrilligVariable::SingleAddr(rhs_modulus)],
[BrilligVariable::SingleAddr(output), BrilligVariable::SingleAddr(modulus_id)],
[BrilligVariable::SingleAddr(lhs), BrilligVariable::SingleAddr(_lhs_modulus), BrilligVariable::SingleAddr(rhs), BrilligVariable::SingleAddr(_rhs_modulus)],
[BrilligVariable::SingleAddr(output), BrilligVariable::SingleAddr(_modulus_id)],
) = (function_arguments, function_results)
{
prepare_bigint_output(brillig_context, lhs_modulus, rhs_modulus, modulus_id);
brillig_context.black_box_op_instruction(BlackBoxOp::BigIntDiv {
lhs: lhs.address,
rhs: rhs.address,
Expand Down Expand Up @@ -416,27 +412,3 @@ fn convert_array_or_vector<F: AcirField + DebugToString>(
),
}
}

fn prepare_bigint_output<F: AcirField + DebugToString>(
brillig_context: &mut BrilligContext<F>,
lhs_modulus: &SingleAddrVariable,
rhs_modulus: &SingleAddrVariable,
modulus_id: &SingleAddrVariable,
) {
// Check moduli
let condition = brillig_context.allocate_register();
let condition_adr = SingleAddrVariable { address: condition, bit_size: 1 };
brillig_context.binary_instruction(
*lhs_modulus,
*rhs_modulus,
condition_adr,
BrilligBinaryOp::Equals,
);
brillig_context.codegen_constrain(
condition_adr,
Some("moduli should be identical in BigInt operation".to_string()),
);
brillig_context.deallocate_register(condition);

brillig_context.mov_instruction(modulus_id.address, lhs_modulus.address);
}
3 changes: 0 additions & 3 deletions noir/noir-repo/compiler/noirc_evaluator/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ use serde::{Deserialize, Serialize};
pub enum RuntimeError {
#[error(transparent)]
InternalError(#[from] InternalError),
#[error("Index out of bounds, array has size {array_size}, but index was {index}")]
IndexOutOfBounds { index: usize, array_size: usize, call_stack: CallStack },
#[error("Range constraint of {num_bits} bits is too large for the Field size")]
InvalidRangeConstraint { num_bits: u32, call_stack: CallStack },
#[error("The value `{value:?}` cannot fit into `{typ}` which has range `{range}`")]
Expand Down Expand Up @@ -145,7 +143,6 @@ impl RuntimeError {
| InternalError::UndeclaredAcirVar { call_stack }
| InternalError::Unexpected { call_stack, .. },
)
| RuntimeError::IndexOutOfBounds { call_stack, .. }
| RuntimeError::InvalidRangeConstraint { call_stack, .. }
| RuntimeError::TypeConversion { call_stack, .. }
| RuntimeError::UnInitialized { call_stack, .. }
Expand Down
Loading

0 comments on commit cf5cc28

Please sign in to comment.