Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tail call codegen for error returns #690

Open
andrewrk opened this issue Jan 15, 2018 · 4 comments
Open

tail call codegen for error returns #690

andrewrk opened this issue Jan 15, 2018 · 4 comments
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. optimization
Projects
Milestone

Comments

@andrewrk
Copy link
Member

for error unions it looks like this:

  tail call fastcc void @__zig_return_error(%StackTrace* %0, i8* blockaddress(@foo, %ReturnError)), !dbg !50
  ret i16 %6, !dbg !50

We could have __zig_return_error take the sret parameter and populate the error value, then return void, so that it can be a tail call.

for pure errors we can pass the error code and return it, and then return it in the parent, another tail call.

Then look at the generated assembly and make sure we're doing tail calls. This is to keep the size of the code generated small for error return tracing. What is a return statement in code without error return tracing can become a jump instruction in code with error return tracing.

@andrewrk andrewrk added this to the 0.3.0 milestone Jan 15, 2018
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Feb 28, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Feb 7, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.6.0 Sep 11, 2019
@andrewrk andrewrk added this to To do in Safety Oct 17, 2019
@andrewrk andrewrk modified the milestones: 0.6.0, 0.7.0 Oct 17, 2019
@luser
Copy link

luser commented Mar 27, 2020

Perhaps you've already seen it, but Swift's ABI dedicates a register to error return values:
https://github.com/apple/swift/blob/master/docs/ABIStabilityManifesto.md#error-register
https://github.com/apple/swift/blob/master/docs/ABI/RegisterUsage.md

LLVM has a swifterror attribute to support this.

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 9, 2020
@andrewrk andrewrk added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Oct 9, 2020
@SpexGuy SpexGuy added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Feb 12, 2021
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Jun 4, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 21, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 17, 2022
@perillo
Copy link
Contributor

perillo commented Feb 12, 2023

Is __zig_return_error used in stage2?

@Vexu
Copy link
Member

Vexu commented Feb 12, 2023

Self hosted uses std.builtin.returnError.

@perillo
Copy link
Contributor

perillo commented Feb 14, 2023

Self hosted uses std.builtin.returnError.

Thanks.

I'm curious about the reason why an implementation detail is exposed in the standard library, and the reason why the function addErrRetTraceAddr is also public.

@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. frontend Tokenization, parsing, AstGen, Sema, and Liveness. optimization
Projects
Safety
  
To do
Development

No branches or pull requests

5 participants