-
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 invariant for types #8
Comments
Noting it here so we don't forget about it:
|
As but two of many examples for people using
(Collecting this here so I will find the links when the discussion starts.) |
An example of uninitialized raw pointers and integers: https://github.com/carllerche/bytes/blob/456221d16521cf54cea0e6569669e47120a1b738/src/bytes.rs#L1810 |
Related discussion about which invariants we require to hold on |
Maybe the UTF-8 thing is just a safety invariant, never a validity invariant? |
@RalfJung I think that, ideally, for DSTs, validity should just be specified for custom DSTs. That is, the validity of trait objects, slices, and We don't have custom DSTs yet, so I think it is ok to also consider validity of trait objects and slices, and in the future, when custom DSTs are available, try to reconcile those into a more general framework. Currently, Thinking more into the future, if So I like to think that the UTF8 requirement on |
Sure, custom DSTs come with custom invariants that rustc and miri do not know. These are safety invariants, not validity invariants. What you are saying is that we could make UTF-8 a mere safety invariant for |
|
This might be a dumb question, but why can’t ManuallyDrop<T> be a wrapper
over MaybeUninit<T> ? I mean, the responsibility of not dropping an object
twice for ManuallyDrop it to not reuse the object storage unless the object
was properly dropped first both look like “safety” issues to me.
|
We want (and have) |
Basically, |
If the problem is that MaybeUninit<T> only works for T: Sized , maybe
that’s a problem worth solving?
“uninitialized” has been a a pain for T: Sized , feels like it’s not an
issue that we might want to leave unresolved otherwise. “unsized unions” do
sound scary though.
|
Closing. There are lots of open questions here, almost all of which are in other issues. This one doesn't seem useful |
@RalfJung introduced the idea of validity invariants in their blog post "Two kinds of invariants". Presuming we agree with this framing (I do), we need to define these validity invariants.
These invariants need to justify the various sorts of optimizations that we currently do:
Option<&T>
layout optimizationWe need to discuss also the role of uninitialized memory and how it fits in. For example, when are invariants required to hold? Only when "compiler thinks memory is initialized" -- can/should we make that more precise? Also, what about loads of uninitialized integral values (a sometimes useful hack) -- are those valid? What is the effect?
The text was updated successfully, but these errors were encountered: