rust/library
Matthias Krüger 948d32d94f
Rollup merge of #121201 - RalfJung:align_offset_contract, r=cuviper
align_offset, align_to: no longer allow implementations to spuriously fail to align

For a long time, we have allowed `align_offset` to fail to compute a properly aligned 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
2024-03-08 21:01:59 +01:00
..
alloc Rollup merge of #122099 - Urgau:btreemap-inline-new, r=Amanieu 2024-03-08 08:19:19 +01:00
backtrace@6145fe6bac Update backtrace submodule 2023-11-21 16:33:42 +01:00
core Rollup merge of #121201 - RalfJung:align_offset_contract, r=cuviper 2024-03-08 21:01:59 +01:00
panic_abort Cleanup windows abort_internal 2024-03-02 18:22:15 +00:00
panic_unwind miri: rename miri_start_panic → miri_start_unwind 2024-02-26 11:10:18 +01:00
portable-simd Merge commit '649110751ef4f27440d7cc711b3e07d11bf02d4a' into sync-portable-simd-2024-02-18 2024-02-18 10:14:03 -05:00
proc_macro Rollup merge of #120976 - matthiaskrgr:constify_TL_statics, r=lcnr 2024-03-04 22:16:30 +01:00
profiler_builtins Add profiling support to AIX 2024-02-28 17:41:12 +08:00
rtstartup library: Fix warnings in rtstartup 2024-01-06 01:32:03 +03:00
rustc-std-workspace-alloc
rustc-std-workspace-core
rustc-std-workspace-std
std Rollup merge of #121938 - blyxxyz:quadratic-vectored-write, r=Amanieu 2024-03-08 08:19:19 +01:00
stdarch@56087ea170 Rename wasm32-wasi-preview2 to wasm32-wasip2 2024-02-27 10:14:45 -05:00
sysroot Expose compiler-builtins-weak-intrinsics feature for -Zbuild-std 2023-06-23 11:15:34 +01:00
test Rust is a proper name: rust → Rust 2024-03-07 07:49:22 +01:00
unwind Rollup merge of #119590 - ChrisDenton:cfg-target-abi, r=Nilstrieb 2024-02-25 17:05:19 +01:00