Skip to content

Properly reset error return trace index#12825

Closed
Vexu wants to merge 2 commits intoziglang:masterfrom
Vexu:fix-err-ret-trace
Closed

Properly reset error return trace index#12825
Vexu wants to merge 2 commits intoziglang:masterfrom
Vexu:fix-err-ret-trace

Conversation

@Vexu
Copy link
Member

@Vexu Vexu commented Sep 12, 2022

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
Copy link
Member Author

Vexu commented Sep 12, 2022

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 Vexu force-pushed the fix-err-ret-trace branch from 019feed to fa5d844 Compare September 12, 2022 18:54
@topolarity
Copy link
Contributor

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 #1923 (comment) (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 🙂

@Vexu
Copy link
Member Author

Vexu commented Sep 12, 2022

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
Copy link
Member Author

Vexu commented Sep 28, 2022

Closing in favor of the more complete solution.

@Vexu Vexu closed this Sep 28, 2022
@Vexu Vexu deleted the fix-err-ret-trace branch May 27, 2023 11:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

when handling a returned error, if the expression/block does not try/return error, reset error return trace index to 0

2 participants