Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't use dummy location when inserting debug code #7482

Merged
merged 1 commit into from
Feb 21, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions compiler/noirc_frontend/src/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@
let func_body = &mut func.body.statements;
let mut statements = take(func_body);

self.walk_scope(&mut statements, func.location.span);
self.walk_scope(&mut statements, func.location);

// walk_scope ensures that the last statement is the return value of the function
let last_stmt = statements.pop().expect("at least one statement after walk_scope");
Expand All @@ -139,7 +139,7 @@

// Modify a vector of statements in-place, adding instrumentation for sets and drops.
// This function will consume a scope level.
fn walk_scope(&mut self, statements: &mut Vec<ast::Statement>, span: Span) {
fn walk_scope(&mut self, statements: &mut Vec<ast::Statement>, location: Location) {
statements.iter_mut().for_each(|stmt| self.walk_statement(stmt));

// extract and save the return value from the scope if there is one
Expand All @@ -166,8 +166,8 @@
}
};

let span = Span::empty(span.end());
let location = Location::new(span, FileId::dummy());
let span = Span::empty(location.span.end());
let location = Location::new(span, location.file);

// drop scope variables
let scope_vars = self.scope.pop().unwrap_or_default();
Expand Down Expand Up @@ -315,7 +315,7 @@
}
ast::LValue::Dereference(_lv, location) => {
// TODO: this is a dummy statement for now, but we should
// somehow track the derefence and update the pointed to

Check warning on line 318 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (derefence)
// variable
ast::Statement {
kind: ast::StatementKind::Expression(uint_expr(0, *location)),
Expand Down Expand Up @@ -384,7 +384,7 @@
match &mut expr.kind {
ast::ExpressionKind::Block(ast::BlockExpression { ref mut statements, .. }) => {
self.scope.push(HashMap::default());
self.walk_scope(statements, expr.location.span);
self.walk_scope(statements, expr.location);
}
ast::ExpressionKind::Prefix(prefix_expr) => {
self.walk_expr(&mut prefix_expr.rhs);
Expand Down Expand Up @@ -726,9 +726,9 @@
ast::Pattern::Tuple(patterns, _) => {
stack.extend(patterns.iter().map(|pattern| (pattern, false)));
}
ast::Pattern::Struct(_, pids, _) => {

Check warning on line 729 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (pids)
stack.extend(pids.iter().map(|(_, pattern)| (pattern, is_mut)));

Check warning on line 730 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (pids)
vars.extend(pids.iter().map(|(id, _)| (id.clone(), false)));

Check warning on line 731 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (pids)
}
ast::Pattern::Interned(_, _) => (),
}
Expand All @@ -739,7 +739,7 @@
fn pattern_to_string(pattern: &ast::Pattern) -> String {
match pattern {
ast::Pattern::Identifier(id) => id.0.contents.clone(),
ast::Pattern::Mutable(mpat, _, _) => format!("mut {}", pattern_to_string(mpat.as_ref())),

Check warning on line 742 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (mpat)

Check warning on line 742 in compiler/noirc_frontend/src/debug/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (mpat)
ast::Pattern::Tuple(elements, _) => format!(
"({})",
elements.iter().map(pattern_to_string).collect::<Vec<String>>().join(", ")
Expand Down
Loading