Skip to content

Conversation

mlugg
Copy link
Member

@mlugg mlugg commented Jan 22, 2025

This PR does two things:

  • Simplify the error return trace to be passed between all functions, not just those that return errors.
    • This makes it possible to (for instance) call std.debug,panic and have it receive the error return trace even though it doesn't return an error.
    • This is also probably a more efficient lowering in practice, since it avoids having many stack frames which have to set up the trace. Broadly speaking, this now only happens at "entry points".
    • This means std.builtin.returnError also gets an implicit error trace parameter, so it no longer needs to take it in explicitly, saving one AIR instruction per error return.
  • Implement the error return trace on the x86_64 backend (by @jacobly0), hence enabling the error_return_trace backend feature.
    • We aim to keep the pointer in r9 at all times
    • This makes the lowering more efficient than what the LLVM backend tends to do; for instance, function calls typically have no overhead for passing the trace, since the caller has it in r9 and the callee expects it in r9

Contributes to #21530.

@mlugg mlugg added the release notes This PR should be mentioned in the release notes. label Jan 22, 2025
mlugg added 3 commits January 22, 2025 02:22
Necessary because the API of `std.builtin.returnError` changed.

Signed-off-by: mlugg <[email protected]>
It's now unnecessary to explicitly pass this, because it receives an
implicit error trace parameter anyway, so can just use
`@errorReturnTrace()`. The previous commit updated Sema to expect this
new interface. This saves an AIR instruction at all `returnError` call
sites.
@mlugg mlugg merged commit 0e815c6 into ziglang:master Jan 22, 2025
10 checks passed
@jacobly0 jacobly0 deleted the new-error-trace branch January 22, 2025 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release notes This PR should be mentioned in the release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants