Skip to content

tail call codegen for error returns #690

Open

Description

@andrewrk

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.

Activity

  1. added this to the 0.3.0 milestone on Jan 15, 2018
  2. modified the milestones: 0.3.0, 0.4.0 on Feb 28, 2018
  3. modified the milestones: 0.4.0, 0.5.0 on Feb 7, 2019
  4. modified the milestones: 0.5.0, 0.6.0 on Sep 11, 2019
  5. modified the milestones: 0.6.0, 0.7.0 on Oct 17, 2019
  6. luser commented on Mar 27, 2020

    @luser
  7. modified the milestones: 0.7.0, 0.8.0 on Oct 9, 2020
  8. added
    frontend
    on Oct 9, 2020
  9. added
    enhancement
    on Feb 12, 2021
  10. modified the milestones: 0.8.0, 0.9.0 on Jun 4, 2021
  11. modified the milestones: 0.9.0, 0.10.0 on Nov 21, 2021
  12. modified the milestones: 0.10.0, 0.11.0 on Apr 17, 2022
  13. perillo commented on Feb 12, 2023

    @perillo
    Contributor

    Is __zig_return_error used in stage2?

  14. Vexu commented on Feb 12, 2023

    @Vexu
    Member

    Self hosted uses std.builtin.returnError.

  15. perillo commented on Feb 14, 2023

    @perillo
    Contributor

    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.

  16. modified the milestones: 0.11.0, 0.12.0 on Apr 9, 2023
  17. moved this to To do in Safetyon Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementfrontendoptimization

    Type

    No type

    Projects

    • Status
      To do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions