Wiktor
July 25, 2024, 3:05pm
1
NonNull::align_offset
ptr::align_offset
It looks like NonNull::align_offset
contains outdated ptr::align_offset
description. I may be wrong though, so I rather ask before polluting repo's issues page
eggyal
July 26, 2024, 12:23am
2
I presume you're referring to the below PR? No discussion in there of NonNull
, which suggests to me it may just have been an oversight—especially since it just delegates to the method on ptr
.
rust-lang:master
← RalfJung:align_offset_contract
opened 08:35PM - 16 Feb 24 UTC
For a long time, we have allowed `align_offset` to fail to compute a properly al… igned offset, and `align_to` to return a smaller-than-maximal "middle slice". This was done to cover the implementation of `align_offset` in const-eval and Miri. See https://github.com/rust-lang/rust/issues/62420 for more background. For about the same amount of time, this has caused confusion and surprise, where people didn't realize they have to write their code to be defensive against `align_offset` failures.
Another way to put this is: the specification is effectively non-deterministic, and non-determinism is hard to test for -- in particular if the implementation everyone uses to test always produces the same reliable result, and nobody expects it to be non-deterministic to begin with.
With https://github.com/rust-lang/rust/pull/117840, Miri has stopped making use of this liberty in the spec; it now always behaves like rustc. That only leaves const-eval as potential motivation for this behavior. I do not think this is sufficient motivation. Currently, none of the relevant functions are stably const: `align_offset` is unstably const, `align_to` is not const at all. I propose that if we ever want to make these const-stable, we just accept the fact that they can behave differently at compile-time vs at run-time. This is not the end of the world, and it seems to be much less surprising to programmers than unexpected non-determinism. (Related: https://github.com/rust-lang/rfcs/pull/3352.)
@thomcc has repeatedly made it clear that they strongly dislike the non-determinism in align_offset, so I expect they will support this. @oli-obk, what do you think? Also, whom else should we involve? The primary team responsible is clearly libs-api, so I will nominate this for them. However, allowing const-evaluated code to behave different from run-time code is t-lang territory. The thing is, this is not stabilizing anything t-lang-worthy immediately, but it still does make a decision we will be bound to: if we accept this change, then
- either `align_offset`/`align_to` can never be called in const fn,
- or we allow compile-time behavior to differ from run-time behavior.
So I will nominate for t-lang as well, with the question being: are you okay with accepting either of these outcomes (without committing to which one, just accepting that it has to be one of them)? This closes the door to "have `align_offset` and `align_to` at compile-time and also always have compile-time behavior match run-time behavior".
Closes https://github.com/rust-lang/rust/issues/62420
3 Likes
outdated documentation on NonNull
methods is not uncommon, i encountered something similar recently when deduplicating the documentation on all the as_ref methods
system
Closed
October 24, 2024, 2:20am
4
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.