-
Notifications
You must be signed in to change notification settings - Fork 59
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
Validity of raw pointers #75
Comments
Agreed, I think a cast from raw pointer to
This is worth drilling a bit more into. I know I've had conversations with @eddyb, @Manishearth, @withoutboats, and a few others about this, and I'd love to hear more from them. I believe that @Manishearth's argument boiled down to "it's really useful to be able to create the equivalent of a NULL pointer: a kind of 'universally valid' value that you know will be overwritten before the reference is ultimately used". I find this a compelling argument: we should make sure we can support that. I suppose the answer is that you can use I think it's certainly an option to say that the "metadata must always be valid". It'd be good to drill into the reasons we might want this to be true. Perhaps it's helpful to list out the times we need metadata to be valid? Some examples I can think of:
Mostly these do seem to be tied to discrete actions in the code, though, and hence point to an invariant that could be enforced at the point of use. |
I would argue that since all of these examples require references, valid metadata should only be needed for references while raw pointers (as long as they are not dereferenced) would be allowed to have invalid/null metadata. Are there any cases where we need to access the metadata of a raw pointer without first turning it into a reference? |
I think @RalfJung mentioned before we could/should have variants of |
If we accept uninitialized bits as being a valid representation for |
It makes sense if you consider that we are only keeping |
I assume if we allow uninitialized integers, we will also allow uninitialized data in the metadata of a raw pointer. I see no harm in that. |
Closing, partially answered partially in favor of #166 |
Discussing the validity invariant of raw pointers.
For pointers to sized types, this should probably be the same as the invariant for
usize
-- see the integer topic for discussing whether uninitialized bits are allowed or not.For pointers to unsized types, there is an additional question: to what extent does the metadata have to be initialized/valid? Do we require it to be "valid" enough to determine size and alignment, e.g. do we require that the vtable pointer actually point to allocated memory?
The text was updated successfully, but these errors were encountered: