Skip to content

Commit fe37187

Browse files
authored
chore: align call stack frame numbers/names (#11873)
1 parent 363fc8a commit fe37187

File tree

6 files changed

+43
-24
lines changed

6 files changed

+43
-24
lines changed

compiler/noirc_errors/src/reporter.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ pub fn stack_trace<'files>(
290290

291291
let repeating_sequences = find_repeating_sequences(call_stack);
292292

293+
// Compute the length of the longest frame number so we show them like this:
294+
// 1: ..
295+
// 23: ..
296+
// 234: ..
297+
let maximum_frame_string_length = compute_maximum_frame_string_length(&repeating_sequences);
298+
293299
let mut result = "Call stack:\n".to_string();
294300
let mut index = 1;
295301

@@ -311,7 +317,7 @@ pub fn stack_trace<'files>(
311317
} else {
312318
"│ "
313319
};
314-
result += &format!("{prefix}{index}: {name}\n");
320+
result += &format!("{prefix}{index:>maximum_frame_string_length$}: {name}\n");
315321

316322
let prefix =
317323
if times == 1 { if has_repetitions { " " } else { "" } } else { "│ " };
@@ -327,6 +333,19 @@ pub fn stack_trace<'files>(
327333
result
328334
}
329335

336+
/// Computes the maximum number of digits to represent all **shown** frames in the callstack.
337+
fn compute_maximum_frame_string_length(repeating_sequences: &[(Vec<Location>, usize)]) -> usize {
338+
let mut index = 1;
339+
let mut maximum_index = 0;
340+
for (sequence, times) in repeating_sequences {
341+
index += sequence.len();
342+
// In a group, the maximum shown frame is the last one in the group
343+
maximum_index = index;
344+
index += sequence.len() * (times - 1);
345+
}
346+
maximum_index.to_string().len()
347+
}
348+
330349
pub fn line_and_column_from_span(source: &str, span: &Span) -> (u32, u32) {
331350
let mut line = 1;
332351
let mut column = 0;

tooling/nargo_cli/tests/snapshots/execution_failure/brillig_entry_points_shared_recursive/execute__tests__acir_stderr.snap

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/nargo_cli/tests/snapshots/execution_failure/brillig_entry_points_shared_recursive/execute__tests__comptime_stderr.snap

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/nargo_cli/tests/snapshots/execution_failure/mutually_recursive_simple_functions/execute__tests__acir_stderr.snap

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/nargo_cli/tests/snapshots/execution_failure/mutually_recursive_simple_functions/execute__tests__brillig_stderr.snap

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tooling/nargo_cli/tests/snapshots/execution_failure/mutually_recursive_simple_functions/execute__tests__comptime_stderr.snap

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)