-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
No aliasable, non-nullable, mutable pointers #13194
Comments
cc @nikomatsakis @thestinger @Aatch @glaebhoerl @pnkfelix (vocal participants in #10571) |
(In fact, ideally, that conditionally could just be written |
If we expose something like #9546 as an annotation, we can write this in a library (presumably). |
This can't really use a non-raw pointer though because of the aliasing and mutability guarantees we have. The only type that semantically works here is |
And specifically adt needs to care about this (it's the Option optimization), not just LLVM. |
cc @flaper87 |
This is a general issue with smart pointers. Both |
If there's no opposition to a |
I'm not against a |
Maybe |
Sure, I don't really care about the name. On Sat, Mar 29, 2014 at 7:26 PM, Steven Fackler notifications@gh.neting.ccwrote:
|
(I feel like this issue is very similar to #7576, at least in its consequences.) |
I think this is #7576, isn't it? |
Well I don't specifically care about library smart pointers, but it's On Mon, Mar 31, 2014 at 10:55 AM, Niko Matsakis notifications@gh.neting.ccwrote:
|
This extends the nullable enum opt to traverse beyond just the first level to find possible fields to use as the discriminant. So now, it'll work through structs, tuples, and fixed sized arrays. This also introduces a new lang item, NonZero, that you can use to wrap raw pointers or integral types to indicate to rustc that the underlying value is known to never be 0/NULL. We then use this in Vec, Rc and Arc to have them also benefit from the nullable enum opt. As per rust-lang/rfcs#499 NonZero is not exposed via the `libstd` facade. ``` x86_64 Linux: T Option<T> (Before) Option<T> (After) ---------------------------------------------------------------------------------- Vec<int> 24 32 24 String 24 32 24 Rc<int> 8 16 8 Arc<int> 8 16 8 [Box<int>, ..2] 16 24 16 (String, uint) 32 40 32 ``` Fixes #19419. Fixes #13194. Fixes #9378. Fixes #7576.
fix-typos fixes some typos in lintcheck changelog: None
In this situation:
Ideally I'd be storing
jcx
as some non-nullable pointer, such thatOption<Context>
could be a single word. Unfortunately there is no type usable today.Option<*mut T>
is 16 bytes on x86_64, and will always be at least one byte more than just the pointer.Option<~T>
will be 8 bytes, but needs handling about the destructor and also has aliasability guarantees, which will be invalidated by the underlying libjit code.Option<&'static mut T>
also has aliasing concerns, on top of nasty lifetime hack.There is no pointer type usable to get zero overhead in this. Given the decision on #10571 (which I agree with!) it would be nice to have something usable here. Perhaps even a
#[not_null]
attribute, per-field, could be usable?The text was updated successfully, but these errors were encountered: