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

Get rid of "always_" prefixes from std.builtin.CallModifier field names #22825

Open
wooster0 opened this issue Feb 9, 2025 · 1 comment
Open
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@wooster0
Copy link
Contributor

wooster0 commented Feb 9, 2025

I think the "always_" prefixes of std.builtin.CallModifier.always_inline and .always_tail are redundant.

Compare the following:

    @call(.always_inline, function, .{argument});
    @call(.@"inline", function, .{argument});

Why do I need to say "always"? Inlining a function call or not is not some kind of probability thing that has a something-% chance of happening; it either happens or doesn't.
And if it couldn't happen, the compiler emits an error.

I'm guessing this relates to how an optimizer might decide to inline a function if it thinks that'd optimize the code, based on the case and the code around the call.

However why can't we just trust Zig here to inline the call if I say so and not if I tell it not to, regardless of optimizers? I don't think they play a role here.
If Zig doesn't call my function in the way I told it to (and doesn't emit a compile error), it might even lead to behavioral changes on my end so I don't think this is much different from other things, like my function returning if I tell it to using the return keyword. I should be able to trust Zig there. Otherwise, would it be alwaysreturn or pleasereturn?

Whatever I said about inlining applies to tail calling as well.

As for never_inline and never_tail, instead of "never" I think the meaning is simply "don't". So perhaps those should also be renamed, to no_inline and no_tail.
You can already find instances of "no_inline" and "no_tail" in the Zig codebase so the naming isn't unusual. As another precedent: the noinline keyword.

In fact if this is rejected, shouldn't std.builtin.CallModifier.compile_time be renamed to always_compile_time for consistency? Or the inline keyword to alwaysinline?

@mlugg
Copy link
Member

mlugg commented Feb 9, 2025

Or the inline keyword to alwaysinline?

Damn, I was just about to comment this in support of this proposal before I finished reading it!

In fact, I personally dislike lots of CallModifier fields. Going through each one:

  • .auto is fine
  • .async_kw, while N/A for now, is completely redundant with async
  • .never_tail is fine, but (per this proposal) might want a rename
  • .never_inline is fine, but (per this proposal) might want a rename
  • .no_async, while N/A for now, is completely redundant with nosuspend
  • .always_tail is fine, but (per this proposal) might want a rename
  • .always_inline is fine, but (per this proposal) might want a rename
  • .compile_time is completely redundant with comptime

My ideal CallModifier would probably only have 5 or so fields.

@mlugg mlugg added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Feb 9, 2025
@mlugg mlugg added this to the 0.15.0 milestone Feb 9, 2025
@mlugg mlugg added the breaking Implementing this issue could cause existing code to no longer compile or have different behavior. label Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking Implementing this issue could cause existing code to no longer compile or have different behavior. proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

2 participants