-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Proposal: ++=
and **=
operators
#5804
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
Comments
Mind explaining what this means in a bit more detail? |
Just a shorthand for Another potential one: |
Upon further consideration, we don't have a viable mechanism for how this would need to interact with the type system. Closing until we do. |
What do you mean? How would this be any different than using |
The result of |
It is possible with slices. |
It is also possible with |
This use case can be accomplished much more cleanly and without AMM with #5873 and an ArrayList. |
Lots of things do hidden dynamic allocation at comptime. Like this: const x = 4;
const y: [x]u32 = ...; Here the length of y is not known until the compiler is running, hence this is a dynamic allocation. Even the declaration of x is a dynamic allocation, because
None of these apply at comptime. Comptime code cannot fail in production because it doesn't run in production, it only runs when compiling. All allocations are inherently dynamic in the compiler because it doesn't know the size of anything until it starts reading the code, so there is no meaningful difference in performance cost between a comptime stack allocation, a comptime global declaration, and a comptime dynamic allocation. Comptime allocations do not need to be cleaned up because they are garbage collected. This also makes use-after-free impossible at comptime, which is massive.
This is probably because your mental model is trained on function parameters, which are const. I think the current comptime differs significantly from what you want it to be. Making lots of small tickets like 5873 and 5718 will not inspire that change, because each does not make sense on its own. There may be some merit to your alternate design of comptime, with no global lifetimes, but it will require many language changes to happen simultaneously. At an abstract level, unifying comptime and runtime semantics seems like it would be a major boon. On the other hand, the more flexible scripting-language-like semantics of comptime are very nice and useful. I think what's needed is a thorough and complete description of your ideal comptime semantics, including comptime scoping rules, behavior of constants, interactions with comptime-only types, and a strong case that your design is at least as powerful as the current definition and makes the language simpler. This would allow people to compare the two ideas, suggest feedback, and properly discuss the tradeoffs involved. Without that, I think the individual smaller changes you are recommending will be shot down because they don't fit with the rest of comptime semantics. |
Will do. Mind reminding me tomorrow? I need to distance myself for now. |
#5895 is up. Feedback welcome. |
For concatenate-assign and repeat-assign, respectively. Honestly surprised we don't already have these. Would make it simpler to, for instance, assemble a formatted string at comptime for printing in one go rather than making separate calls for each component.
The text was updated successfully, but these errors were encountered: