Skip to content

Commit 09236d2

Browse files
authored
Merge pull request #12837 from topolarity/err-ret-trace-improvements-1923
stage2: Pop error trace frames for handled errors (#1923)
2 parents b9103bd + c36a2c2 commit 09236d2

File tree

23 files changed

+2089
-863
lines changed

23 files changed

+2089
-863
lines changed

lib/std/builtin.zig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -869,8 +869,10 @@ pub noinline fn returnError(st: *StackTrace) void {
869869
}
870870

871871
pub inline fn addErrRetTraceAddr(st: *StackTrace, addr: usize) void {
872-
st.instruction_addresses[st.index & (st.instruction_addresses.len - 1)] = addr;
873-
st.index +%= 1;
872+
if (st.index < st.instruction_addresses.len)
873+
st.instruction_addresses[st.index] = addr;
874+
875+
st.index += 1;
874876
}
875877

876878
const std = @import("std.zig");

lib/std/debug.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,14 @@ pub fn writeStackTrace(
411411
const return_address = stack_trace.instruction_addresses[frame_index];
412412
try printSourceAtAddress(debug_info, out_stream, return_address - 1, tty_config);
413413
}
414+
415+
if (stack_trace.index > stack_trace.instruction_addresses.len) {
416+
const dropped_frames = stack_trace.index - stack_trace.instruction_addresses.len;
417+
418+
tty_config.setColor(out_stream, .Bold);
419+
try out_stream.print("({d} additional stack frames skipped...)\n", .{dropped_frames});
420+
tty_config.setColor(out_stream, .Reset);
421+
}
414422
}
415423

416424
pub const StackIterator = struct {

src/Air.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,10 @@ pub const Inst = struct {
733733
/// Uses the `ty_op` field.
734734
addrspace_cast,
735735

736+
/// Saves the error return trace index, if any. Otherwise, returns 0.
737+
/// Uses the `ty_pl` field.
738+
save_err_return_trace_index,
739+
736740
pub fn fromCmpOp(op: std.math.CompareOperator, optimized: bool) Tag {
737741
switch (op) {
738742
.lt => return if (optimized) .cmp_lt_optimized else .cmp_lt,
@@ -1179,6 +1183,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index) Type {
11791183
.slice_len,
11801184
.ret_addr,
11811185
.frame_addr,
1186+
.save_err_return_trace_index,
11821187
=> return Type.usize,
11831188

11841189
.wasm_memory_grow => return Type.i32,

0 commit comments

Comments
 (0)