Na茂vely, I thought unroll might be a better keyword and @andrewrk said he considered it before, but went for inline as it's well-known.
I don't have a strong opinion, but still think unroll better expresses the intent.
unrollPros:
Cons:
inlinePros:
Cons:
inline is solely used for inlining functions and is more than a suggestion (minor)Other propositions ?
Why not comptime?
Why not
comptime?
You can, in fact, put comptime in front of a loop already, because you can put comptime in front of any expression. If you do that, it means the entire loop will not only be unrolled, but also executed at compile time. So you could not, for example, call an external function inside the comptime loop because external function calls are not allowed at comptime.
inline (or the proposed unroll) is different in that the loop can still do runtime stuff (such as printing to stderr) - it's just that the loop branching and the iteration variable(s) will be comptime.
I understand, but since comptime followed by runtime stuff is not currently allowed, then there is no ambiguity if the keyword comptime were to be used in place of inline. You _would_ lose the ability to run comptime-compatible code at runtime with what inline currently does, but you might argue that such code should preferentially be run at comptime anyway (as is already the case with top-level const declarations which are implicitly comptime-run).
then there is no ambiguity if the keyword
comptimewere to be used in place ofinline
There is ambiguity, if you consider that getting a compile error in some cases is desired behavior. comptime guarantees that the expression that follows will be executed at compile time or be a compile error. Making it do the inline loop functionality, removes the ability to get a compile error when there would be a runtime side effect.
I think it's a reasonable proposal. I'm ambivalent about it. I'm making an executive decision here to stick with status quo. I do think that inline is still correct.
Most helpful comment
There is ambiguity, if you consider that getting a compile error in some cases is desired behavior.
comptimeguarantees that the expression that follows will be executed at compile time or be a compile error. Making it do theinlineloop functionality, removes the ability to get a compile error when there would be a runtime side effect.