Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
95 commits
Select commit Hold shift + click to select a range
cf0eeb9
location tree for debug_info
guipublic Jan 13, 2025
17ff57d
forgot to commit files from tooling
guipublic Jan 13, 2025
eeb1e9f
cargo.lock
guipublic Jan 13, 2025
aa74a7b
Merge branch 'master' into gd/issue_6946
guipublic Jan 13, 2025
0984da7
fix test case
guipublic Jan 13, 2025
a3eb219
set call_stack_id during acir-gen
guipublic Jan 14, 2025
fb962e0
Merge branch 'master' into gd/issue_6946
guipublic Jan 14, 2025
3548030
update ts DebugInfo
guipublic Jan 14, 2025
70f5563
update comment
guipublic Jan 14, 2025
9c06c93
Merge branch 'master' into gd/issue_6946
guipublic Jan 14, 2025
ca52a8e
format
guipublic Jan 14, 2025
4283acf
Merge branch 'master' into gd/issue_6946
TomAFrench Jan 14, 2025
8683746
put call stack in correct order
guipublic Jan 14, 2025
354b075
Merge branch 'master' into gd/issue_6946
guipublic Jan 15, 2025
b3332d5
code review
guipublic Jan 15, 2025
22357be
Merge branch 'master' into gd/issue_6946
TomAFrench Jan 15, 2025
41a9c09
code review
guipublic Jan 16, 2025
60a4fdc
code review
guipublic Jan 16, 2025
6b38614
Merge branch 'master' into gd/issue_6946
guipublic Jan 16, 2025
bed3b77
Separate brillig/acir opcode locations in DebugInfo
guipublic Jan 17, 2025
0ce7133
Merge branch 'master' into gd/issue_6946
guipublic Jan 17, 2025
3db55aa
commit missing file
guipublic Jan 17, 2025
f57145d
Merge branch 'master' into gd/issue_6946
guipublic Jan 17, 2025
201d371
fix unit case
guipublic Jan 17, 2025
0220c80
Merge branch 'master' into gd/issue_6946
guipublic Jan 17, 2025
c8fae47
fix unit test
guipublic Jan 17, 2025
07d8d7f
Merge branch 'master' into gd/issue_6946
guipublic Jan 17, 2025
df0abf3
Fix unit test
guipublic Jan 17, 2025
5e96be1
Merge branch 'master' into gd/issue_6946
guipublic Jan 17, 2025
d2ae968
Merge branch 'master' into gd/issue_6946
guipublic Jan 20, 2025
6f23a8c
fix merge conflict
guipublic Jan 20, 2025
b273687
Merge branch 'master' into gd/issue_6946
guipublic Jan 20, 2025
91496e4
code review: remove string serialisation for AcirOpcodeLocation
guipublic Jan 24, 2025
27ed000
Merge branch 'master' into gd/issue_6946
guipublic Jan 24, 2025
37bfadb
fix merge issue
guipublic Jan 24, 2025
0f43935
Merge branch 'master' into gd/issue_6946
guipublic Jan 28, 2025
5262488
Merge branch 'master' into gd/issue_6946
guipublic Feb 4, 2025
b326ea8
Merge branch 'master' into gd/issue_6946
guipublic Feb 4, 2025
edb58b8
Merge branch 'master' into gd/issue_6946
guipublic Feb 5, 2025
5b0fedb
Merge branch 'master' into gd/issue_6946
guipublic Feb 6, 2025
0e037ec
Merge branch 'master' into gd/issue_6946
vezenovm Feb 6, 2025
5e94272
Merge branch 'master' into gd/issue_6946
guipublic Feb 6, 2025
5a74021
Merge branch 'master' into gd/issue_6946
guipublic Feb 6, 2025
54b6de7
Merge branch 'master' into gd/issue_6946
guipublic Feb 7, 2025
f4c4ec4
Merge branch 'master' into gd/issue_6946
guipublic Feb 7, 2025
7be438e
Update acvm-repo/acir/src/circuit/mod.rs
vezenovm Feb 12, 2025
a549811
Update compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
vezenovm Feb 12, 2025
06a233f
Update compiler/noirc_evaluator/src/brillig/brillig_gen/brillig_block.rs
vezenovm Feb 12, 2025
7cbfca7
Merge branch 'master' into gd/issue_6946
vezenovm Feb 12, 2025
9f98cba
code review
guipublic Feb 7, 2025
f9a3205
Merge branch 'master' into gd/issue_6946
guipublic Feb 25, 2025
6c330a6
code review
guipublic Feb 25, 2025
389f701
code review
guipublic Feb 25, 2025
302d7d2
Merge branch 'master' into gd/issue_6946
guipublic Feb 25, 2025
865da61
Merge branch 'master' into gd/issue_6946
guipublic Feb 26, 2025
f078667
feat: Port callstack resolution from aztec to noirjs
sirasistant Mar 10, 2025
d839aa7
Merge branch 'master' into arv/resolve_callstacks
TomAFrench Mar 12, 2025
d80ad82
.
TomAFrench Mar 12, 2025
9dccf1a
Merge branch 'master' into arv/resolve_callstacks
TomAFrench Mar 12, 2025
863ef02
Merge branch 'master' into gd/issue_6946
guipublic Mar 18, 2025
fe8330d
Merge branch 'master' into gd/issue_6946
guipublic Mar 18, 2025
2436d0d
Merge branch 'master' into gd/issue_6946
guipublic Mar 18, 2025
ca75cfc
fix merge from master
guipublic Mar 18, 2025
d2fb561
Merge branch 'master' into arv/resolve_callstacks
guipublic Mar 18, 2025
d12d5f2
Merge branch 'master' into arv/resolve_callstacks
guipublic Mar 18, 2025
323ec28
Merge branch 'master' into arv/resolve_callstacks
guipublic Mar 19, 2025
6512c4a
Merge branch 'master' into gd/issue_6946
guipublic Mar 20, 2025
e1dfcc2
Merge branch 'master' into arv/resolve_callstacks
guipublic Mar 20, 2025
4a4db6a
Merge branch 'master' into arv/resolve_callstacks
guipublic Mar 20, 2025
19ad519
Merge branch 'master' into gd/issue_6946
guipublic Mar 20, 2025
5260da8
M::erge branch 'arv/resolve_callstacks' into gd/issue_6946
guipublic Mar 20, 2025
ea205b1
avoid short circuiting if no assertion payload
sirasistant Mar 21, 2025
77b89eb
Merge branch 'arv/resolve_callstacks' into gd/issue_6946
guipublic Mar 21, 2025
2c86dad
JS Callstack extraction for location tree Debug Info
guipublic Mar 24, 2025
e39d697
Merge branch 'master' into gd/issue_6946
guipublic Mar 24, 2025
f895021
format
guipublic Mar 24, 2025
a6cf909
Merge branch 'master' into gd/issue_6946
guipublic Mar 25, 2025
633f337
Merge branch 'master' into gd/issue_6946
guipublic Apr 18, 2025
bcacb51
Merge branch 'master' into gd/issue_6946
guipublic Apr 18, 2025
c328165
fix merge issues
guipublic Apr 18, 2025
66400a8
use location tree in fuzzer
guipublic Apr 22, 2025
0f225cc
Merge branch 'master' into gd/issue_6946
guipublic Apr 22, 2025
9e72973
update snapshots
guipublic Apr 22, 2025
1b80896
Merge branch 'master' into gd/issue_6946
guipublic Apr 22, 2025
b42ce8e
update snapshots
guipublic Apr 22, 2025
897ff8e
snapshots
guipublic Apr 22, 2025
ef3da53
Merge branch 'master' into gd/issue_6946
guipublic Apr 22, 2025
811919b
snapshots..
guipublic Apr 22, 2025
da6a1f7
snapshots
guipublic Apr 22, 2025
2aecba7
..snapshots
guipublic Apr 22, 2025
c3b3706
snapshots
guipublic Apr 22, 2025
e500408
Merge branch 'master' into gd/issue_6946
guipublic Apr 22, 2025
5f4e39c
snapshots
guipublic Apr 22, 2025
b9b55e4
Merge branch 'master' into gd/issue_6946
guipublic Apr 23, 2025
2020eda
snapshots
guipublic Apr 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion Cargo.lock

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

18 changes: 18 additions & 0 deletions acvm-repo/acir/src/circuit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,24 @@ pub enum OpcodeLocation {
Brillig { acir_index: usize, brillig_index: usize },
}

/// Opcodes are locatable so that callers can
/// map opcodes to debug information related to their context.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
pub struct AcirOpcodeLocation(usize);
impl std::fmt::Display for AcirOpcodeLocation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}

impl AcirOpcodeLocation {
pub fn new(index: usize) -> Self {
AcirOpcodeLocation(index)
}
pub fn index(&self) -> usize {
self.0
}
}
/// Index of Brillig opcode within a list of Brillig opcodes.
/// To be used by callers for resolving debug information.
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
Expand Down
15 changes: 14 additions & 1 deletion acvm-repo/acvm/src/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::HashMap;

use acir::{
AcirField,
circuit::{AssertionPayload, Circuit, ExpressionWidth, OpcodeLocation},
circuit::{AcirOpcodeLocation, AssertionPayload, Circuit, ExpressionWidth, OpcodeLocation},
};

// The various passes that we can use over ACIR
Expand Down Expand Up @@ -57,6 +57,19 @@ impl AcirTransformationMap {
},
)
}

pub fn new_acir_locations(
&self,
old_location: AcirOpcodeLocation,
) -> impl Iterator<Item = AcirOpcodeLocation> + '_ {
let old_acir_index = old_location.index();

self.old_indices_to_new_indices.get(&old_acir_index).into_iter().flat_map(
move |new_indices| {
new_indices.iter().map(move |new_index| AcirOpcodeLocation::new(*new_index))
},
)
}
}

/// Update the assert messages to point to the new opcode locations.
Expand Down
21 changes: 14 additions & 7 deletions compiler/noirc_driver/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ pub(crate) fn filter_relevant_files(
let mut files_with_debug_symbols: BTreeSet<FileId> = debug_symbols
.iter()
.flat_map(|function_symbols| {
function_symbols
.locations
.values()
.flat_map(|call_stack| call_stack.iter().map(|location| location.file))
function_symbols.acir_locations.values().flat_map(|call_stack_id| {
function_symbols
.location_tree
.get_call_stack(*call_stack_id)
.into_iter()
.map(|location| location.file)
})
})
.collect();

Expand All @@ -33,9 +36,13 @@ pub(crate) fn filter_relevant_files(
.flat_map(|function_symbols| {
let brillig_location_maps =
function_symbols.brillig_locations.values().flat_map(|brillig_location_map| {
brillig_location_map
.values()
.flat_map(|call_stack| call_stack.iter().map(|location| location.file))
brillig_location_map.values().flat_map(|call_stack_id| {
function_symbols
.location_tree
.get_call_stack(*call_stack_id)
.into_iter()
.map(|location| location.file)
})
});
brillig_location_maps
})
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ acvm.workspace = true
codespan-reporting.workspace = true
codespan.workspace = true
fm.workspace = true
fxhash.workspace = true
noirc_printable_type.workspace = true
serde.workspace = true
serde_with = "3.2.0"
tracing.workspace = true
flate2.workspace = true
serde_json.workspace = true
Expand Down
Original file line number Diff line number Diff line change
@@ -1,48 +1,71 @@
use fxhash::FxHashMap;
use serde::{Deserialize, Serialize};

use noirc_errors::Location;
use crate::Location;

pub type CallStack = Vec<Location>;

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct CallStackId(u32);

impl CallStackId {
pub(crate) fn root() -> Self {
pub fn root() -> Self {
Self::new(0)
}

fn new(id: usize) -> Self {
pub fn new(id: usize) -> Self {
Self(id as u32)
}

pub(crate) fn index(&self) -> usize {
pub fn index(&self) -> usize {
self.0 as usize
}

pub(crate) fn is_root(&self) -> bool {
pub fn is_root(&self) -> bool {
self.0 == 0
}
}

#[derive(Debug, Clone, Serialize, Deserialize, Hash)]
pub struct LocationNodeDebugInfo {
pub parent: Option<CallStackId>,
pub value: Location,
}

#[derive(Debug, Clone, Serialize, Deserialize, Default, Hash)]
pub struct LocationTree {
pub locations: Vec<LocationNodeDebugInfo>,
}

impl LocationTree {
/// Construct a CallStack from a CallStackId
pub fn get_call_stack(&self, mut call_stack: CallStackId) -> CallStack {
let mut result = Vec::new();
while let Some(parent) = self.locations[call_stack.index()].parent {
result.push(self.locations[call_stack.index()].value);
call_stack = parent;
}
result.reverse();
result
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct LocationNode {
pub(crate) parent: Option<CallStackId>,
pub(crate) children: Vec<CallStackId>,
pub(crate) children_hash: FxHashMap<u64, CallStackId>,
pub(crate) value: Location,
pub struct LocationNode {
pub parent: Option<CallStackId>,
pub children: Vec<CallStackId>,
pub children_hash: FxHashMap<u64, CallStackId>,
pub value: Location,
}

impl LocationNode {
pub(crate) fn new(parent: Option<CallStackId>, value: Location) -> Self {
pub fn new(parent: Option<CallStackId>, value: Location) -> Self {
LocationNode { parent, children: Vec::new(), children_hash: FxHashMap::default(), value }
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub(crate) struct CallStackHelper {
locations: Vec<LocationNode>,
pub struct CallStackHelper {
pub locations: Vec<LocationNode>,
}

impl Default for CallStackHelper {
Expand All @@ -56,7 +79,7 @@ impl Default for CallStackHelper {

impl CallStackHelper {
/// Construct a CallStack from a CallStackId
pub(crate) fn get_call_stack(&self, mut call_stack: CallStackId) -> CallStack {
pub fn get_call_stack(&self, mut call_stack: CallStackId) -> CallStack {
let mut result = Vec::new();
while let Some(parent) = self.locations[call_stack.index()].parent {
result.push(self.locations[call_stack.index()].value);
Expand All @@ -67,7 +90,7 @@ impl CallStackHelper {
}

/// Returns a new CallStackId which extends the call_stack with the provided call_stack.
pub(crate) fn extend_call_stack(
pub fn extend_call_stack(
&mut self,
mut call_stack: CallStackId,
locations: &CallStack,
Expand All @@ -79,7 +102,7 @@ impl CallStackHelper {
}

/// Adds a location to the call stack
pub(crate) fn add_child(&mut self, call_stack: CallStackId, location: Location) -> CallStackId {
pub fn add_child(&mut self, call_stack: CallStackId, location: Location) -> CallStackId {
let key = fxhash::hash64(&location);
if let Some(result) = self.locations[call_stack.index()].children_hash.get(&key) {
if self.locations[result.index()].value == location {
Expand All @@ -97,11 +120,7 @@ impl CallStackHelper {
}

/// Retrieve the CallStackId corresponding to call_stack with the last 'len' locations removed.
pub(crate) fn unwind_call_stack(
&self,
mut call_stack: CallStackId,
mut len: usize,
) -> CallStackId {
pub fn unwind_call_stack(&self, mut call_stack: CallStackId, mut len: usize) -> CallStackId {
while len > 0 {
if let Some(parent) = self.locations[call_stack.index()].parent {
len -= 1;
Expand All @@ -113,7 +132,7 @@ impl CallStackHelper {
call_stack
}

pub(crate) fn add_location_to_root(&mut self, location: Location) -> CallStackId {
pub fn add_location_to_root(&mut self, location: Location) -> CallStackId {
if self.locations.is_empty() {
self.locations.push(LocationNode::new(None, location));
CallStackId::root()
Expand All @@ -123,7 +142,18 @@ impl CallStackHelper {
}

/// Get (or create) a CallStackId corresponding to the given locations
pub(crate) fn get_or_insert_locations(&mut self, locations: CallStack) -> CallStackId {
self.extend_call_stack(CallStackId::root(), &locations)
pub fn get_or_insert_locations(&mut self, locations: &CallStack) -> CallStackId {
self.extend_call_stack(CallStackId::root(), locations)
}

// Clone the locations into a LocationTree
pub fn to_location_tree(&self) -> LocationTree {
LocationTree {
locations: self
.locations
.iter()
.map(|node| LocationNodeDebugInfo { value: node.value, parent: node.parent })
.collect(),
}
}
}
50 changes: 34 additions & 16 deletions compiler/noirc_errors/src/debug_info.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use acvm::acir::circuit::AcirOpcodeLocation;
use acvm::acir::circuit::BrilligOpcodeLocation;
use acvm::acir::circuit::OpcodeLocation;
use acvm::acir::circuit::brillig::BrilligFunctionId;
Expand All @@ -9,14 +10,16 @@ use flate2::read::DeflateDecoder;
use flate2::write::DeflateEncoder;
use serde::Deserializer;
use serde::Serializer;
use serde_with::DisplayFromStr;
use serde_with::serde_as;
//use serde_with::DisplayFromStr;
//use serde_with::serde_as;
use std::collections::BTreeMap;
use std::io::Read;
use std::io::Write;
use std::mem;

use crate::Location;
use crate::call_stack::CallStackId;
use crate::call_stack::LocationTree;
use noirc_printable_type::PrintableType;
use serde::{
Deserialize, Serialize, de::Error as DeserializationError, ser::Error as SerializationError,
Expand Down Expand Up @@ -93,16 +96,13 @@ impl ProgramDebugInfo {
}
}

#[serde_as]
#[derive(Default, Debug, Clone, Deserialize, Serialize, Hash)]
pub struct DebugInfo {
/// Map opcode index of an ACIR circuit into the source code location
/// Serde does not support mapping keys being enums for json, so we indicate
/// that they should be serialized to/from strings.
#[serde_as(as = "BTreeMap<DisplayFromStr, _>")]
pub locations: BTreeMap<OpcodeLocation, Vec<Location>>,
pub brillig_locations:
BTreeMap<BrilligFunctionId, BTreeMap<BrilligOpcodeLocation, Vec<Location>>>,
BTreeMap<BrilligFunctionId, BTreeMap<BrilligOpcodeLocation, CallStackId>>,
pub location_tree: LocationTree,
/// Map opcode index of an ACIR circuit into the source code location
pub acir_locations: BTreeMap<AcirOpcodeLocation, CallStackId>,
pub variables: DebugVariables,
pub functions: DebugFunctions,
pub types: DebugTypes,
Expand All @@ -113,11 +113,12 @@ pub struct DebugInfo {

impl DebugInfo {
pub fn new(
locations: BTreeMap<OpcodeLocation, Vec<Location>>,
brillig_locations: BTreeMap<
BrilligFunctionId,
BTreeMap<BrilligOpcodeLocation, Vec<Location>>,
BTreeMap<BrilligOpcodeLocation, CallStackId>,
>,
location_map: BTreeMap<AcirOpcodeLocation, CallStackId>,
location_tree: LocationTree,
variables: DebugVariables,
functions: DebugFunctions,
types: DebugTypes,
Expand All @@ -126,7 +127,15 @@ impl DebugInfo {
BTreeMap<ProcedureDebugId, (usize, usize)>,
>,
) -> Self {
Self { locations, brillig_locations, variables, functions, types, brillig_procedure_locs }
Self {
brillig_locations,
acir_locations: location_map,
location_tree,
variables,
functions,
types,
brillig_procedure_locs,
}
}

/// Updates the locations map when the [`Circuit`][acvm::acir::circuit::Circuit] is modified.
Expand All @@ -136,16 +145,25 @@ impl DebugInfo {
/// Note: One old `OpcodeLocation` might have transformed into more than one new `OpcodeLocation`.
#[tracing::instrument(level = "trace", skip(self, update_map))]
pub fn update_acir(&mut self, update_map: AcirTransformationMap) {
let old_locations = mem::take(&mut self.locations);
let old_locations = mem::take(&mut self.acir_locations);

for (old_opcode_location, source_locations) in old_locations {
update_map.new_locations(old_opcode_location).for_each(|new_opcode_location| {
self.locations.insert(new_opcode_location, source_locations.clone());
update_map.new_acir_locations(old_opcode_location).for_each(|new_opcode_location| {
self.acir_locations.insert(new_opcode_location, source_locations);
});
}
}

pub fn acir_opcode_location(&self, loc: &AcirOpcodeLocation) -> Option<Vec<Location>> {
self.acir_locations
.get(loc)
.map(|call_stack_id| self.location_tree.get_call_stack(*call_stack_id))
}

pub fn opcode_location(&self, loc: &OpcodeLocation) -> Option<Vec<Location>> {
self.locations.get(loc).cloned()
match loc {
OpcodeLocation::Brillig { .. } => None, //TODO: need brillig function id in order to look into brillig_locations
OpcodeLocation::Acir(loc) => self.acir_opcode_location(&AcirOpcodeLocation::new(*loc)),
}
}
}
1 change: 1 addition & 0 deletions compiler/noirc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#![warn(unreachable_pub)]
#![warn(clippy::semicolon_if_nothing_returned)]

pub mod call_stack;
pub mod debug_info;
mod position;
pub mod reporter;
Expand Down
Loading
Loading