-
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
Do we have full recursive validity for references? #412
Comments
I think point 4 means that "full recursive validity" is not actually well-defined. A reference does not necessarily give access to the full pointed-to allocation, if parts of that allocation are currently loaned out, and I think one aspect of the memory model that we should all be able to agree on is that a evaluating a validity assertion should not require "reads" which are not legal by the memory model itself, because this leads to data-race-like issues which I'm not sure can be resolved in the presence of weak memory. However, not all validity properties are incompatible with concurrent reads, because not everything is under an TL;DR: The answer to the title question should be "no", but the follow up questions might not be so simple. |
Yes. The idea was to have this issue for documenting that consensus, so that we can have separate issues for the follow-up questions. That is my attempt to disentangle the various follow-up questions that arise here. Let's collect follow-up questions we have issues for:
Please open a new issue if you think there is a separate proposal/discussion to be had. |
Is this issue proposing to change the UB defined in the reference?
|
It would still be an unsafe value (unsound to yield to arbitrary safe code), but yes, it would not be undefined behaviour to produce the reference. |
Yes, many of the issues in this repo are about finding out what UB we really want. The reference list is preliminary, as indicated by the big warning there. |
I added a flag to Miri that lets us experiment with recursive validity checking. Turns out at least recursive validity of For non- And then, the first issue that's not just in a test: this code here is unsound with recursive reference validity. |
…r=saethlin Miri: add a flag to do recursive validity checking The point of this flag is to allow gathering experimental data for rust-lang/unsafe-code-guidelines#412.
…r=saethlin Miri: add a flag to do recursive validity checking The point of this flag is to allow gathering experimental data for rust-lang/unsafe-code-guidelines#412.
…r=saethlin Miri: add a flag to do recursive validity checking The point of this flag is to allow gathering experimental data for rust-lang/unsafe-code-guidelines#412.
Rollup merge of rust-lang#128531 - RalfJung:miri-recursive-validity, r=saethlin Miri: add a flag to do recursive validity checking The point of this flag is to allow gathering experimental data for rust-lang/unsafe-code-guidelines#412.
Miri: add a flag to do recursive validity checking The point of this flag is to allow gathering experimental data for rust-lang/unsafe-code-guidelines#412.
Full recursive validity is also fundamentally at odds with #![feature(dropck_eyepatch)]
struct Foo<'a>(&'a u8);
unsafe impl<#[may_dangle] 'a> Drop for Foo<'a> {
fn drop(&mut self) { }
}
fn main() {
let foo;
{
let x = 0;
foo = Foo(&x);
}
} (Example due to @JakobDegen, from a different discussion ) The
|
That part seems speculative. I have absolutely seen code that looks like let iter = vec.iter().filter(pred);
call();
for item in iter.filter(overlapping_pred) {
// code
} in the wild... usually because the first part looks like calling this: impl SomeType<T> {
fn iter(&self) -> impl Iterator<Item = &T> {
self.inner_slice.filter(valid_elements)
}
} And wouldn't that benefit from the optimization that's currently invalid in rust-lang/rust#130853 of a simple let val = **x;
call();
**x == val // optimize to true Obviously this may not hold for all types. |
Aliasing for nested references and recursive validity do not have to be entangled, so please keep the former to #532. |
squints Huuuh, I'm surprised by that, but okay! |
This is one of the successors to #77. The question is: for a reference to be valid, do we require that all the data it points to is equally valid, fully recursively?
I think the answer is "no", and my impression is most people agree, so let me collect some arguments here (and I will open some other issues that only make sense discussing after the answer here is "no"):
io::Read
trait often works, and while better solutions are being developed, there's a long tail of copies of this API and a lot of old code to port, that we should have good reasons to consider UB.&Mutex<bool>
is valid would cause a conceptual data race with another thread holding the lock and mutating thatbool
.&mut uninit
not being immediate UB) #346 also apply, though some are more specific and a lot of the discussion focuses not on "full recursive validity: yes or know" but various weaker validity variants.Note that the Rust reference currently answers this question with "yes", but in my view this is mostly because we haven't yet figured out what exactly the weaker requirement is that we actually want to impose.
The text was updated successfully, but these errors were encountered: