-
Notifications
You must be signed in to change notification settings - Fork 59
Initial Glossary entry for Aliasing #170
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
Conversation
Not precise, but something we can point beginners to for the moment while more is worked on.
Could you make that a separate PR, for ease of reviewing? |
other formatting cleanup will be other PRs
Alright
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks good to me!
Let's see if anyone else has an opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. @gnzlbg okay to merge?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-Authored-By: Ralf Jung <[email protected]>
I honestly don't know if this link will work because there isn't a layout.md in the repo, the SUMMARY has always been messed up and mdbook has just been generating a blank page because of it this whole time.
Ah whatever, I think I will just do an editing pass and also define "Tag" while I am at it. ;) Thanks a lot @Lokathor ! |
I think I'm a bit late to this party, but how does the definition here interact with slices of ZSTs (#168)?
According to these rules, slices of ZSTs always have a span byte length 0 and thus never alias. But I'd argue that let foo = [(); 1337];
let a = &foo[..];
let b = &foo[..7]; |
That is correct, and actually explicitly stated further down in this PR.
I'd argue you are wrong, then. ;) Also see rust-lang/rust-memory-model#44. |
I think my misunderstanding here is that mutable references are highly underdocumented. The only "real" documentation of them I know of is the following part of the nomicon:
Reading through the linked issue, I understand that those are only necessary and not sufficient definitions. I was under the impression that they are sufficient and thus interpreted the noaliasing rule of ZSTs such that you can have multiple mutable references to the same ZST at the same time, which obviously is just wrong. I think I just need to split the meanings of "aliasing" and "references" in my brain. |
You can think of there being arbitrarily many ZST "between" any two memory addresses, and references can point to those. So even if two ZST references point to the same location, they don't "overlap". That pragmatic response is that aliasing is about figuring out if memory operations through one reference can be observed through the other reference, or if they can be freely reordered. But no memory access actually ever happens with a ZST reference. |
This is basically the same definition as the Rustonomicon has, but now we're re-stating it here with (I hope) improved clarity.
Of note, it's now written down somewhere visible that ZSTs never alias.
Also I made the whole Glossary alphabetical.
Note: This is not intended to be new guarantees at all, I don't think I wrote anything that can be taken that way, it's just a definition so that people can speak with common terms.