-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Disallow the use of the comptime keyword before an expression or statement when it is superfluous #8364
Comments
I think I disagree with the premise, that is the issue this is trying to solve. To elaborate however, from my perspective, if someone wrote It is about distinguishing what these concepts mean, and not the grammatical details of "where do I put the keyword". (That being said, I also don't know any other language to feature the concept of Edit: I may have gone off-the-rails a bit, because I didn't understand the code examples as what was the initial concern:
I don't think this is an issue either:
Besides this uninformed opinion, here are some practical counterpoints to consider:
I think this change would overall hinder explicitness and introduce a new complexity that is avoided by status-quo. |
Wasn't #425 scrapped (sadly)? |
I think it would definitely be reasonable to disallow the // compile error: redundant comptime on decl initializer
const foo = comptime fn () void { };
// compile error: redundant comptime on return type expression
const bar = fn () comptime u8 { };
const baz = blk: {
// allowed, this is an execution scope.
const x = comptime fn () void {};
// compile error: redundant comptime on return type expression
const y = fn () comptime void {};
// compile error: redundant comptime on type expression
const z: comptime fn () void = fn() void {};
// allowed but weird, neither of these are at top-level in a type expression
const w: (comptime fn () (comptime void)) = fn() void {};
break :blk w;
}; We could also safely disallow
This is true, but if we can have the compiler identify these misunderstandings and point people towards the right path, IMO that's worth doing. I don't think anyone who does understand this distinction would want to put |
I enthusiastically support this, especially from a learning perspective. Also, allowing me to throw the It's like if I were cooking right next to an expert chef and he knows I need to just melt a little butter for the sauce, but I start throwing whole sticks of butter into a pan. I say, "Can I use this much butter? This feels like a lot." And he just raises an eyebrow and says, "Sure, you could use that much butter." |
Currently,
comptime
expressions can be superfluously added and even chained.This allows people to insert the keyword even in explicit comptime contexts, for example the length of an array type or a type expression.
While this is not necessarily bad, in my opinion it can only reinforce the confusion about which blocks/expressions are comptime by default and which are not.
Furthermore, with the introduction of #1717, the following will be allowed:
This is especially bad since it is easily confusable with functions of .Comptime calling convention.
The text was updated successfully, but these errors were encountered: