-
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
Should validity of a reference depend on the *contents* of memory in any way? #414
Comments
My own opinion is that no, validity should not depend on the contents of memory in any way. It might (at least effectively) depend on whether there is dereferenceable memory at a given location at all (see the issues tagged My main argument is that I want to keep reasoning about whether code has UB as local as possible, so other threads changing the contents of memory shouldn't make a reference suddenly be invalid. Deallocation being able to invalidate references is bad enough, but that falls out of the aliasing model fairly naturally. (I view dangling references as causing UB on the next retag, not the next typed copy.) I don't see a strong enough reason to also let any write possibly invalidate references, and I don't see an elegant way that this requirement would even arise (considering a MiniRust-like framework). (Some of) the arguments in #346 also apply. In particular, even 1-level validity behind |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Anyway this issue is not about retags! This issue is about whether we want to require any kind of validity of in-memory data beyond what is imposed by retags (which is just dereferencability). |
I'd argue that the only place it makes sense to assert validity is on retags and activation (except maybe #84 stuff at invalidation of certain references), so that would make retags relevant to the discussion. |
Are you saying that retagging should do more than what is necessary for the alias model (which amounts to checking dereferencability)? |
I'm saying that if we are requiring the validty of referents, then retags are the most logical place for them. Otherwise, if you project: |
(In general this is wildly unsafe because
I have no idea what you mean by "actively requiring validity" here or how there is UB here. Again, this issue is about contents being valid, so the aliasing state shouldn't even come in. Is it insta-UB to have a I guess we could have retagging create such a high-level value representation of the pointee. Is that what you mean? With interior mutability however we'd have to "leave a hole" in that representation at any place where there is an UnsafeCell, so it'd not be a proper value either. |
I would say yes because my definition of the validity requirement of a shared reference is that, at any point while the reference is live:
This definition would require |
Something I have not seen mentioned: any kind of recursive validity implies that a self-referential struct would have a coinductive validity invariant. That sounds unpleasant to model. |
Yeah, one could use interior mutability to set up a cycle of shared references and then transmute the |
This discussion presupposes that "Do we have full recursive validity for references" (#412) is answered "no".
As @digama0 points out, lots of weaker variants of "validity depending on memory contents" are conceivable. Probably the most strict one is "full recursive validity except inside shared
UnsafeCell
". We could also imagine "only follow one indirection" and all sorts of other variants.The text was updated successfully, but these errors were encountered: