Skip to content

Commit 7908a1d

Browse files
committed
Auto merge of rust-lang#110243 - WaffleLapkin:bless_tagged_pointers🙏, r=Nilstrieb
Tagged pointers, now with strict provenance! This is a big refactor of tagged pointers in rustc, with three main goals: 1. Porting the code to the strict provenance 2. Cleanup the code 3. Document the code (and safety invariants) better This PR has grown quite a bit (almost a complete rewrite at this point...), so I'm not sure what's the best way to review this, but reviewing commit-by-commit should be fine. r? `@Nilstrieb`
2 parents 56e28e9 + 5571dd0 commit 7908a1d

File tree

10 files changed

+657
-233
lines changed

10 files changed

+657
-233
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
use std::ptr::Alignment;
2+
3+
/// Returns the ABI-required minimum alignment of a type in bytes.
4+
///
5+
/// This is equivalent to [`mem::align_of`], but also works for some unsized
6+
/// types (e.g. slices or rustc's `List`s).
7+
///
8+
/// [`mem::align_of`]: std::mem::align_of
9+
pub const fn align_of<T: ?Sized + Aligned>() -> Alignment {
10+
T::ALIGN
11+
}
12+
13+
/// A type with a statically known alignment.
14+
///
15+
/// # Safety
16+
///
17+
/// `Self::ALIGN` must be equal to the alignment of `Self`. For sized types it
18+
/// is [`mem::align_of<Self>()`], for unsized types it depends on the type, for
19+
/// example `[T]` has alignment of `T`.
20+
///
21+
/// [`mem::align_of<Self>()`]: std::mem::align_of
22+
pub unsafe trait Aligned {
23+
/// Alignment of `Self`.
24+
const ALIGN: Alignment;
25+
}
26+
27+
unsafe impl<T> Aligned for T {
28+
const ALIGN: Alignment = Alignment::of::<Self>();
29+
}
30+
31+
unsafe impl<T> Aligned for [T] {
32+
const ALIGN: Alignment = Alignment::of::<T>();
33+
}

compiler/rustc_data_structures/src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#![feature(get_mut_unchecked)]
3030
#![feature(lint_reasons)]
3131
#![feature(unwrap_infallible)]
32+
#![feature(strict_provenance)]
33+
#![feature(ptr_alignment_type)]
3234
#![allow(rustc::default_hash_types)]
3335
#![allow(rustc::potential_query_instability)]
3436
#![deny(rustc::untranslatable_diagnostic)]
@@ -82,6 +84,7 @@ pub mod transitive_relation;
8284
pub mod vec_linked_list;
8385
pub mod work_queue;
8486
pub use atomic_ref::AtomicRef;
87+
pub mod aligned;
8588
pub mod frozen;
8689
pub mod owned_slice;
8790
pub mod sso;

0 commit comments

Comments
 (0)