zig icon indicating copy to clipboard operation
zig copied to clipboard

Properly reset error return trace index

Open Vexu opened this issue 3 years ago • 3 comments

Currently depends on #12807 to free up two Zir instruction slots, only the last commit is relevant to this PR.

Example:

const std = @import("std");
test {
    return error.SkipZigTest;
}
fn foo() !void {
    return error.DontShow;
}
test {
    foo() catch {
        std.debug.dumpStackTrace(@errorReturnTrace().?.*);
        // return error.Second;
    };
    return error.Wtf;
}

With the comment:

Test [1/2] test_0... SKIP
Test [2/2] test_1... ./a.zig:6:5: 0x20f128 in foo (test)
    return error.DontShow;
    ^
Test [2/2] test_1... FAIL (Wtf)
./a.zig:13:5: 0x20f185 in test_1 (test)
    return error.Wtf;
    ^
0 passed; 1 skipped; 1 failed.

Uncommented:

Test [1/2] test_0... SKIP
Test [2/2] test_1... ./a.zig:6:5: 0x20f138 in foo (test)
    return error.DontShow;
    ^
Test [2/2] test_1... FAIL (Second)
./a.zig:6:5: 0x20f138 in foo (test)
    return error.DontShow;
    ^
./a.zig:11:9: 0x20f18e in test_1 (test)
        return error.Second;
        ^
0 passed; 1 skipped; 1 failed.

Closes #1923

Vexu avatar Sep 12 '22 18:09 Vexu

Hmm, this still doesn't handle this case properly:

const std = @import("std");
test {
    return error.SkipZigTest;
}
fn foo() !void {
    return error.DontShow;
}
test {
    foo() catch {
        foo() catch {};
        std.debug.dumpStackTrace(@errorReturnTrace().?.*);
    };
}

Maybe it'd be better to start off with a simplified version which always resets to zero since it handles all the common cases properly.

Vexu avatar Sep 12 '22 18:09 Vexu

Hmm, this still doesn't handle this case properly:

Not sure if this is good news or bad, but I'm just finishing up an overlapping change that should handle that case correctly. It intends to implement the rest of https://github.com/ziglang/zig/issues/1923#issuecomment-1218495574 (esp. supporting break)

Let me know how we can best coordinate the follow-up change so that I don't step on your toes here 🙂

topolarity avatar Sep 12 '22 20:09 topolarity

If you have a more complete fix then let's go with that, I just want this annoyance fixed to get the full benefit of #12807

Vexu avatar Sep 12 '22 20:09 Vexu

Closing in favor of the more complete solution.

Vexu avatar Sep 28 '22 10:09 Vexu