-
Notifications
You must be signed in to change notification settings - Fork 1.6k
RFC: Generic const and static #1520
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
Conversation
I'm against generic |
I didn't think of that, but AFAIK C++ has always had that issue (it supports both static variables in generic functions and classes, and as of C++14, generic variables - plus I believe it guarantees uniqueness for pointers to specialized functions), and solves it by marking those symbols as weak, so the dynamic linker picks one for the whole program. Rust could do the same. Weak symbols have some performance impact, but as long as generic statics are uncommon it shouldn't matter. The number could be further whittled down by detecting truly immutable objects and going back to internal linkage for those - after all, if Rust doesn't guarantee uniqueness for |
IIRC we never considered associated statics because maintaining uniqueness was deemed unreasonably difficult/impossible (cc @alexcrichton) and plans for generic consts were supersceded by |
…features (which I hope will be filled in too eventually).
We discussed this in the @rust-lang/lang meeting recently. I think that, at least for constants, we are all generally sympathetic to this goal, but we feel it's a bit premature to dive into it right now. The story with constants -- and especially constants and generics! -- is quite up in the air. We have const fns, associated constants, and the MIR transition, all of which affect how constants are implemented in the compiler and handled in the type system. Moreover, there is an obvious demand for constant-parameterized items (think (That said, I think one of the biggest points of tension here is between |
Postponed under #1557 |
This commit introduces a trait `StableVtable`, which provides a canonicalized version of `TraitObject::vtable` that is suitable for representing a type identity, eliminating the need for storing `TypeId` in handle types and thus reducing the size of each of them by 8 bytes. In addition, this commit makes `SmallBox::vtable` non-null, which allows further space optimization when a handle is stored in `Option` or a similar enumerate type. This approach has the following shortcomings: - The runtime overhead of down-casting is slightly increased owing to an additional indirection required to access the canonicalized `vtable`. Still, it's supposedly faster than `std::any::Any`. - Storing a generic type in a handle is even harder due to the lack of generic static items (<rust-lang/rfcs#1520>). This approach requires a static variable where the canonical `vtable` for a specific type is stored. A potential work-around would be providing a slow path for types that can't generate a stable `vtable` pointers.
As it says on the tin.
Rendered