Conversation
|
rustbot has assigned @Mark-Simulacrum. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This was noted off-handedly in the PR discussion where this section was reworked. It seems worthwhile to note explicitly that an allocation's base and size are not "usize" or "isize" but infinitely-wide types where `<= usize::MAX` cannot be trivially assumed.
0179fce to
61da6d3
Compare
|
thank u rustbot |
|
I don't know what you mean by infinite-precision. I'm not sure we've ever used that terminology with regard to provenance, is there another way to express what you mean? If someone does call |
|
this is more about "can an allocation wrap across the end of the address space" than anything about provenance; I only mention infinite-precision refers to
couldn't there be a ZST there? (though also since |
|
I see. I think it would be less confusing to add a note that none of the arithmetic wraps. At least it would have been easier for my brain because that's a term we already use in this space. |
|
I've adjusted the wording a bit differently, any time I tried to describe it as non-wrapping arithmetic it felt a bit hamfisted.. but in the "As a consequence ..." section we've already described the idea that sums do not wrap the address space. so I think it reads better to pull that up to talk about does this read better to you as well? |
|
r? @saethlin but I think I'm happy with the in-PR wording (but don't feel strongly that this needs mentioning here) |
|
@iximeow Well, this reads better to me than your initial proposal, but I also don't see how this is an improvement over what's already in the repo. But if you think it is an improvement, I'm happy to merge it. |
| //! - `base` is not equal to [`null()`] (i.e., the address with the numerical | ||
| //! value 0) | ||
| //! - `base + size <= usize::MAX` | ||
| //! - `base + size <= usize::MAX`; `base + size` will not wrap around the |
There was a problem hiding this comment.
The meaning of the semicolon here is unclear to me -- is this meant to clarify the first part, or to impose further restrictions?
There was a problem hiding this comment.
admittedly I've struggled with how to phrase this. when I read https://doc.rust-lang.org/core/ptr/index.html in April I did not immediately realize that + means "under arbitrary-precision" or "bignum" or "infinite-precision" or term-of-choice. instead, I'd understood it as "base and size are usize" since that is the representation of an address and return value of std::mem::size_of().
if you read these as arbitrary-precision, then this just clarifies the first part. if you read these as usize, as I would suggest most readers probably will without explicit guidance, this section is correct except for needing this further restriction that base + size does not wrap.
I would rather address it by expressing specifically that the arithmetic here is arbitrary-precision (as I tried in the first diff, but the phrasing reads poorly and I couldn't figure out how to resolve it directly. several functions in the module (repeatedly) say computed on mathematical integers, so it feels like there should be a stanza for the module about how math on pointers and offsets is described wit large that the module generally agrees on. or at least we should introduce that phrase earlier than in the docs of eight functions that give you a pointer with a different address.
more than you asked for, sorry - hopefully that makes sense?
There was a problem hiding this comment.
We did indeed mean a mathematical + here. I don't agree with your assessment that most readers will assume a wrapping +, but I admit that some readers could interpret the text like that. That does make the entire condition completely pointless so I assume most people would notice, but maybe we can find a way to be more explicit.
| //! - `base + size <= usize::MAX`; `base + size` will not wrap around the | ||
| //! address space (in other words, will not overflow) |
There was a problem hiding this comment.
| //! - `base + size <= usize::MAX`; `base + size` will not wrap around the | |
| //! address space (in other words, will not overflow) | |
| //! - `base + size <= usize::MAX` (computed on mathematical integers) |
This follows the precedent in https://doc.rust-lang.org/nightly/std/primitive.pointer.html#method.offset
This was noted off-handedly in #116675 where this section was reworked. It seems worthwhile to note explicitly that an allocation's base and size are not "usize" or "isize" but infinitely-wide types where
<= usize::MAXcannot be trivially assumed.I got here trying to figure out if/why
with_exposed_provenance::<(u8, u8)>(usize::MAX)returns an invalid*const T. eitherbase + size <= usize::MAXis trivially true, or there's an assumption of wider-than-usize arithmetic and the answer is "it's invalid". seems like the latter, thank goodness! this was discussed in a few places in #116675 (this other comment for example) but ended up left to a careful reader in the landed docs.