diff options
| author | Ralf Jung <post@ralfj.de> | 2022-12-27 12:31:17 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-02-06 11:46:32 +0100 |
| commit | 201ae7387245caa4591d4c8db4c35c170c64faf0 (patch) | |
| tree | 011ec2bc77cfee914cfab9d89b61c40232046986 /compiler/rustc_ty_utils/src | |
| parent | 0c13c172507f01d921808107d2c4ec37b43b982d (diff) | |
| download | rust-201ae7387245caa4591d4c8db4c35c170c64faf0.tar.gz rust-201ae7387245caa4591d4c8db4c35c170c64faf0.zip | |
make PointerKind directly reflect pointer types
The code that consumes PointerKind (`adjust_for_rust_scalar` in rustc_ty_utils) ended up using PointerKind variants to talk about Rust reference types (& and &mut) anyway, making the old code structure quite confusing: one always had to keep in mind which PointerKind corresponds to which type. So this changes PointerKind to directly reflect the type. This does not change behavior.
Diffstat (limited to 'compiler/rustc_ty_utils/src')
| -rw-r--r-- | compiler/rustc_ty_utils/src/abi.rs | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 1c74aeca5ab..884087987ce 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -254,15 +254,15 @@ fn adjust_for_rust_scalar<'tcx>( if let Some(kind) = pointee.safe { attrs.pointee_align = Some(pointee.align); - // `Box` (`UniqueBorrowed`) are not necessarily dereferenceable - // for the entire duration of the function as they can be deallocated - // at any time. Same for shared mutable references. If LLVM had a - // way to say "dereferenceable on entry" we could use it here. + // `Box` are not necessarily dereferenceable for the entire duration of the function as + // they can be deallocated at any time. Same for non-frozen shared references (see + // <https://github.com/rust-lang/rust/pull/98017>). If LLVM had a way to say + // "dereferenceable on entry" we could use it here. attrs.pointee_size = match kind { - PointerKind::UniqueBorrowed - | PointerKind::UniqueBorrowedPinned - | PointerKind::Frozen => pointee.size, - PointerKind::SharedMutable | PointerKind::UniqueOwned => Size::ZERO, + PointerKind::Box | PointerKind::SharedRef { frozen: false } => Size::ZERO, + PointerKind::SharedRef { frozen: true } | PointerKind::MutableRef { .. } => { + pointee.size + } }; // The aliasing rules for `Box<T>` are still not decided, but currently we emit @@ -278,15 +278,14 @@ fn adjust_for_rust_scalar<'tcx>( // `&mut` pointer parameters never alias other parameters, // or mutable global data // - // `&T` where `T` contains no `UnsafeCell<U>` is immutable, - // and can be marked as both `readonly` and `noalias`, as - // LLVM's definition of `noalias` is based solely on memory - // dependencies rather than pointer equality + // `&T` where `T` contains no `UnsafeCell<U>` is immutable, and can be marked as both + // `readonly` and `noalias`, as LLVM's definition of `noalias` is based solely on memory + // dependencies rather than pointer equality. However this only applies to arguments, + // not return values. let no_alias = match kind { - PointerKind::SharedMutable | PointerKind::UniqueBorrowedPinned => false, - PointerKind::UniqueBorrowed => noalias_mut_ref, - PointerKind::UniqueOwned => noalias_for_box, - PointerKind::Frozen => true, + PointerKind::SharedRef { frozen } => frozen, + PointerKind::MutableRef { unpin } => unpin && noalias_mut_ref, + PointerKind::Box => noalias_for_box, }; // We can never add `noalias` in return position; that LLVM attribute has some very surprising semantics // (see <https://github.com/rust-lang/unsafe-code-guidelines/issues/385#issuecomment-1368055745>). @@ -294,7 +293,7 @@ fn adjust_for_rust_scalar<'tcx>( attrs.set(ArgAttribute::NoAlias); } - if kind == PointerKind::Frozen && !is_return { + if matches!(kind, PointerKind::SharedRef { frozen: true }) && !is_return { attrs.set(ArgAttribute::ReadOnly); } } |
