-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Rust's system for globals / constants is not ideal #398
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
Being able to take the address of a |
I don't see how it's crazy. You're using circular reasoning to justify the distinction. Treating constants as rvalues is bloated and inefficient. There is no justification for not permitting the address to be taken for types without internal mutability. It's a job for the borrow checker, not a hack involving duplication of the value as an expression everywhere. |
All globals should have insignificant addresses whether they have inherited mutability, internal mutability or are truly constant. It opens up many opportunities for reducing code size / improving performance via merging - sometimes after proving that a mutable global is only read from. There isn't a valid use case for significant addresses because the same thing can be accomplished with types / type ids and zero-size types never have a meaningful address anyway. |
Might make sense to clearly separate the semantics from the implementation. |
If they're semantically an rvalue, then you can't get an |
Of course, non-zero-sized internal mutability ensures some kind of address significance. |
In some cases, a mutable global will only be read from so LLVM can convert it to a constant. It can then merge these globals together if they are marked |
Closing in favor of #1056, which describes a specific, backwards compatible change that would (I believe) achieve the aims described here. |
RouteInfo Metadata
It has pointless restrictions that are forever going to hurt code generation and expressiveness like
const
being an rvalue andstatic
having a significant address. There were better ways of accomplishing the goal of allowing internal mutability instatic
and initialization of types with internal mutability withconst
without it being broken. The only restriction really needed forconst
was forbidden the definition of external ones. Whether or not the underlying variable is marked asconstant
in LLVM is an implementation detail. Taking an address of aconst
containingUnsafeCell
could have been forbidden but it is not strictly necessary -const
could allow internal mutability just likeconst
variables in C++.The text was updated successfully, but these errors were encountered: