Skip to content

Commit

Permalink
chore: Add docs for each comptime method (noir-lang/noir#5802)
Browse files Browse the repository at this point in the history
chore: Add comptime docs (noir-lang/noir#5800)
fix: Handle multiple entry points for Brillig call stack resolution after metadata deduplication (noir-lang/noir#5788)
fix(acir_gen): Nested dynamic array initialization (noir-lang/noir#5810)
fix: honor function visibility in LSP completion (noir-lang/noir#5809)
feat: LSP completion now works better in the middle of idents (noir-lang/noir#5795)
feat: Explicit Associated Types & Constants (noir-lang/noir#5739)
feat: add `Expr::as_cast` and `UnresolvedType::is_field` (noir-lang/noir#5801)
feat: add `Expr` methods: as_comptime, as_unsafe, is_break, is_continue (noir-lang/noir#5799)
fix: do not use predicate for index in array operation, when the index is safe (noir-lang/noir#5779)
chore: Toggle underconstrained check (noir-lang/noir#5724)
feat: Add `Expr::as_block` and `Expr::has_semicolon` (noir-lang/noir#5784)
feat: LSP hover and go-to-definition for crates (noir-lang/noir#5786)
fix(acvm): Clear ACIR call stack after successful circuit execution (noir-lang/noir#5783)
chore: sanitize url's to only allow github (noir-lang/noir#5776)
chore: enable constant inputs for more blackbox (noir-lang/noir#5647)
chore: move sha2 functions into the `hash` module (noir-lang/noir#5768)
  • Loading branch information
AztecBot committed Aug 24, 2024
2 parents 2269815 + e52297d commit 331e938
Show file tree
Hide file tree
Showing 43 changed files with 1,618 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .noir-sync-commit
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1c84038e4a1b2515f4f91aca4c833dd3b6c05d91
de0f8eeeeaa2f35b6d1e3b7f77cd3e4a1b2db9ba
26 changes: 26 additions & 0 deletions noir/noir-repo/acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,28 @@ pub struct ResolvedOpcodeLocation {
/// map opcodes to debug information related to their context.
pub enum OpcodeLocation {
Acir(usize),
// TODO(https://github.com/noir-lang/noir/issues/5792): We can not get rid of this enum field entirely just yet as this format is still
// used for resolving assert messages which is a breaking serialization change.
Brillig { acir_index: usize, brillig_index: usize },
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct BrilligOpcodeLocation(pub usize);

impl OpcodeLocation {
// Utility method to allow easily comparing a resolved Brillig location and a debug Brillig location.
// This method is useful when fetching Brillig debug locations as this does not need an ACIR index,
// and just need the Brillig index.
pub fn to_brillig_location(self) -> Option<BrilligOpcodeLocation> {
match self {
OpcodeLocation::Brillig { brillig_index, .. } => {
Some(BrilligOpcodeLocation(brillig_index))
}
_ => None,
}
}
}

impl std::fmt::Display for OpcodeLocation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Expand Down Expand Up @@ -204,6 +223,13 @@ impl FromStr for OpcodeLocation {
}
}

impl std::fmt::Display for BrilligOpcodeLocation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let index = self.0;
write!(f, "{index}")
}
}

impl<F> Circuit<F> {
pub fn num_vars(&self) -> u32 {
self.current_witness_index + 1
Expand Down
10 changes: 7 additions & 3 deletions noir/noir-repo/compiler/noirc_errors/src/debug_info.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use acvm::acir::circuit::brillig::BrilligFunctionId;
use acvm::acir::circuit::BrilligOpcodeLocation;
use acvm::acir::circuit::OpcodeLocation;
use acvm::compiler::AcirTransformationMap;

Expand Down Expand Up @@ -98,8 +99,8 @@ pub struct DebugInfo {
/// that they should be serialized to/from strings.
#[serde_as(as = "BTreeMap<DisplayFromStr, _>")]
pub locations: BTreeMap<OpcodeLocation, Vec<Location>>,
#[serde_as(as = "BTreeMap<_, BTreeMap<DisplayFromStr, _>>")]
pub brillig_locations: BTreeMap<BrilligFunctionId, BTreeMap<OpcodeLocation, Vec<Location>>>,
pub brillig_locations:
BTreeMap<BrilligFunctionId, BTreeMap<BrilligOpcodeLocation, Vec<Location>>>,
pub variables: DebugVariables,
pub functions: DebugFunctions,
pub types: DebugTypes,
Expand All @@ -116,7 +117,10 @@ pub struct OpCodesCount {
impl DebugInfo {
pub fn new(
locations: BTreeMap<OpcodeLocation, Vec<Location>>,
brillig_locations: BTreeMap<BrilligFunctionId, BTreeMap<OpcodeLocation, Vec<Location>>>,
brillig_locations: BTreeMap<
BrilligFunctionId,
BTreeMap<BrilligOpcodeLocation, Vec<Location>>,
>,
variables: DebugVariables,
functions: DebugFunctions,
types: DebugTypes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1933,6 +1933,9 @@ impl<F: AcirField> AcirContext<F> {
}
Some(optional_value) => {
let mut values = Vec::new();
if let AcirValue::DynamicArray(_) = optional_value {
unreachable!("Dynamic array should already be initialized");
}
self.initialize_array_inner(&mut values, optional_value)?;
values
}
Expand Down Expand Up @@ -1962,8 +1965,16 @@ impl<F: AcirField> AcirContext<F> {
self.initialize_array_inner(witnesses, value)?;
}
}
AcirValue::DynamicArray(_) => {
unreachable!("Dynamic array should already be initialized");
AcirValue::DynamicArray(AcirDynamicArray { block_id, len, .. }) => {
let dynamic_array_values = try_vecmap(0..len, |i| {
let index_var = self.add_constant(i);

let read = self.read_from_memory(block_id, &index_var)?;
Ok::<AcirValue, InternalError>(AcirValue::Var(read, AcirType::field()))
})?;
for value in dynamic_array_values {
self.initialize_array_inner(witnesses, value)?;
}
}
}
Ok(())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! `GeneratedAcir` is constructed as part of the `acir_gen` pass to accumulate all of the ACIR
//! program as it is being converted from SSA form.
use std::collections::BTreeMap;
use std::{collections::BTreeMap, u32};

use crate::{
brillig::{brillig_gen::brillig_directive, brillig_ir::artifact::GeneratedBrillig},
Expand All @@ -11,7 +11,7 @@ use acvm::acir::{
circuit::{
brillig::{BrilligFunctionId, BrilligInputs, BrilligOutputs},
opcodes::{BlackBoxFuncCall, FunctionInput, Opcode as AcirOpcode},
AssertionPayload, OpcodeLocation,
AssertionPayload, BrilligOpcodeLocation, OpcodeLocation,
},
native_types::Witness,
BlackBoxFunc,
Expand Down Expand Up @@ -53,7 +53,7 @@ pub(crate) struct GeneratedAcir<F: AcirField> {

/// Brillig function id -> Opcodes locations map
/// This map is used to prevent redundant locations being stored for the same Brillig entry point.
pub(crate) brillig_locations: BTreeMap<BrilligFunctionId, OpcodeToLocationsMap>,
pub(crate) brillig_locations: BTreeMap<BrilligFunctionId, BrilligOpcodeToLocationsMap>,

/// Source code location of the current instruction being processed
/// None if we do not know the location
Expand All @@ -77,6 +77,8 @@ pub(crate) struct GeneratedAcir<F: AcirField> {
/// Correspondence between an opcode index (in opcodes) and the source code call stack which generated it
pub(crate) type OpcodeToLocationsMap = BTreeMap<OpcodeLocation, CallStack>;

pub(crate) type BrilligOpcodeToLocationsMap = BTreeMap<BrilligOpcodeLocation, CallStack>;

#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)]
pub(crate) enum BrilligStdlibFunc {
Inverse,
Expand Down Expand Up @@ -590,6 +592,7 @@ impl<F: AcirField> GeneratedAcir<F> {
return;
}

// TODO(https://github.com/noir-lang/noir/issues/5792)
for (brillig_index, message) in generated_brillig.assert_messages.iter() {
self.assertion_payloads.insert(
OpcodeLocation::Brillig {
Expand All @@ -605,13 +608,10 @@ impl<F: AcirField> GeneratedAcir<F> {
}

for (brillig_index, call_stack) in generated_brillig.locations.iter() {
self.brillig_locations.entry(brillig_function_index).or_default().insert(
OpcodeLocation::Brillig {
acir_index: self.opcodes.len() - 1,
brillig_index: *brillig_index,
},
call_stack.clone(),
);
self.brillig_locations
.entry(brillig_function_index)
.or_default()
.insert(BrilligOpcodeLocation(*brillig_index), call_stack.clone());
}
}

Expand All @@ -625,6 +625,7 @@ impl<F: AcirField> GeneratedAcir<F> {
OpcodeLocation::Acir(index) => index,
_ => panic!("should not have brillig index"),
};

match &mut self.opcodes[acir_index] {
AcirOpcode::BrilligCall { id, .. } => *id = brillig_function_index,
_ => panic!("expected brillig call opcode"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,9 @@ fn resolve_external_dep(
resolve_path_to_ns(&dep_directive, dep_module.krate, importing_crate, def_maps, path_references)
}

// Issue an error if the given private function is being called from a non-child module, or
// if the given pub(crate) function is being called from another crate
fn can_reference_module_id(
// Returns false if the given private function is being called from a non-child module, or
// if the given pub(crate) function is being called from another crate. Otherwise returns true.
pub fn can_reference_module_id(
def_maps: &BTreeMap<CrateId, CrateDefMap>,
importing_crate: CrateId,
current_module: LocalModuleId,
Expand Down
4 changes: 4 additions & 0 deletions noir/noir-repo/cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,15 @@
"keccakf",
"krate",
"libc",
"Linea",
"losslessly",
"lvalue",
"Maddiaa",
"mathbb",
"memfs",
"memset",
"merkle",
"metaprogramming",
"metas",
"microcontroller",
"minreq",
Expand Down Expand Up @@ -166,6 +168,7 @@
"pseudocode",
"pubkey",
"quantile",
"quasiquote",
"rangemap",
"repr",
"reqwest",
Expand Down Expand Up @@ -204,6 +207,7 @@
"typevar",
"typevars",
"udiv",
"umap",
"underconstrained",
"uninstantiated",
"unnormalized",
Expand Down
Loading

0 comments on commit 331e938

Please sign in to comment.