rust/compiler/rustc_ty_utils/src
bors dffea43fc1 Auto merge of #106180 - RalfJung:dereferenceable-generators, r=nbdd0121
make &mut !Unpin not dereferenceable, and Box<!Unpin> not noalias

See https://github.com/rust-lang/unsafe-code-guidelines/issues/381 and [this LLVM discussion](https://discourse.llvm.org/t/interaction-of-noalias-and-dereferenceable/66979). The exact semantics of how `noalias` and `dereferenceable` interact are unclear, and `@comex` found a case of LLVM actually exploiting that ambiguity for optimizations. I think for now we should treat LLVM `dereferenceable` as implying a "fake read" to happen immediately at the top of the function (standing in for the spurious reads that LLVM might introduce), and that fake read is subject to all the usual `noalias` restrictions. This means we cannot put `dereferenceable` on `&mut !Unpin` references as those references can alias with other references that are being read and written inside the function (e.g. for self-referential generators), meaning the fake read introduces aliasing conflicts with those other accesses.

For `&` this is already not a problem due to https://github.com/rust-lang/rust/pull/98017 which removed the `dereferenceable` attribute for other reasons.

Regular `&mut Unpin` references are unaffected, so I hope the impact of this is going to be tiny.

The first commit does some refactoring of the `PointerKind` enum since I found the old code very confusing each time I had to touch it. It doesn't change behavior.

Fixes https://github.com/rust-lang/miri/issues/2714

EDIT: Turns out our `Box<!Unpin>` treatment was incorrect, too, so the PR also fixes that now (in codegen and Miri): we do not put `noalias` on these boxes any more.
2023-02-07 03:35:10 +00:00
..
abi.rs also do not add noalias on not-Unpin Box 2023-02-06 12:17:41 +01:00
assoc.rs rustc_metadata: Encode/decode some LazyArrays without an Option 2023-02-05 18:19:52 +04:00
common_traits.rs Change InferCtxtBuilder from enter to build 2022-10-07 07:10:40 -05:00
consts.rs ConstBlocks are poly if their substs are poly 2023-01-16 20:09:31 +00:00
errors.rs Migrate all diagnostics 2022-10-23 10:09:44 +02:00
implied_bounds.rs fix up subst_identity vs skip_binder; add some FIXMEs as identified in review 2023-01-26 20:28:31 -07:00
instance.rs Rename some compare_method functions 2022-12-24 21:36:58 +00:00
layout_sanity_check.rs stricter alignment enforcement for ScalarPair and Vector 2022-11-28 15:09:56 +01:00
layout.rs Sort Generator print-type-sizes according to their yield points 2023-02-05 17:34:33 +01:00
lib.rs Also remove #![feature(control_flow_enum)] where possible 2023-01-18 10:22:21 -08:00
needs_drop.rs Pacify tidy. 2023-01-27 22:01:25 +00:00
representability.rs Rewrite representability 2022-10-07 09:33:46 -05:00
structural_match.rs Move has_structural_eq_impls provider to rustc_ty_utils 2022-12-08 05:16:48 +00:00
ty.rs nits 2023-01-30 19:19:07 +00:00