Skip to content

Tagged pointers, now with strict provenance! #110243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c738dcc
Add `bits_for` helper for tagged pointers & fixup docs
WaffleLapkin Apr 11, 2023
f028636
Sprinkle some whitespace & uses
WaffleLapkin Apr 11, 2023
3c6f4c1
Bless tagged pointers (comply to strict provenance)
WaffleLapkin Apr 11, 2023
12fd610
Refactor tagged ptr packing into a function
WaffleLapkin Apr 11, 2023
ad92677
Fix doc test
WaffleLapkin Apr 11, 2023
26232f1
Remove useless parameter from ghost
WaffleLapkin Apr 12, 2023
9051331
Lift `Pointer`'s requirement for the pointer to be thin
WaffleLapkin Apr 12, 2023
c6acd5c
Remove `Pointer::with_ref` in favour implementing it on tagged pointe…
WaffleLapkin Apr 12, 2023
c7c0b85
Make tagged pointers debug impls print the pointer
WaffleLapkin Apr 12, 2023
8f40820
Remove `pointer_{ref,mut}` from tagged pointers
WaffleLapkin Apr 12, 2023
3df9a7b
Shorten `COMPARE_PACKED` => `CP` where it is not important
WaffleLapkin Apr 12, 2023
6f64ae3
Move code around
WaffleLapkin Apr 12, 2023
5e4577e
Add `TaggedPtr::set_tag`
WaffleLapkin Apr 12, 2023
6f9b15c
Add tests for tagged pointers
WaffleLapkin Apr 12, 2023
838c549
Document tagged pointers better
WaffleLapkin Apr 12, 2023
dc19dc2
doc fixes
WaffleLapkin Apr 12, 2023
c155d51
Implement `Send`/`Sync` for `CopyTaggedPtr`
WaffleLapkin Apr 13, 2023
8d49e94
Doc fixes from review
WaffleLapkin Apr 14, 2023
251f662
Share `Tag2` impl between `CopyTaggedPtr` and `TaggedPtr` tests
WaffleLapkin Apr 14, 2023
36f5918
Test `CopyTaggedPtr`'s `HashStable` impl
WaffleLapkin Apr 14, 2023
014c6f2
Use `ptr::Alignment` for extra coolness points
WaffleLapkin Apr 14, 2023
5571dd0
fix broken intradoclinks
WaffleLapkin Apr 14, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions compiler/rustc_data_structures/src/aligned.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::ptr::Alignment;

/// Returns the ABI-required minimum alignment of a type in bytes.
///
/// This is equivalent to [`mem::align_of`], but also works for some unsized
/// types (e.g. slices or rustc's `List`s).
///
/// [`mem::align_of`]: std::mem::align_of
pub const fn align_of<T: ?Sized + Aligned>() -> Alignment {
T::ALIGN
}

/// A type with a statically known alignment.
///
/// # Safety
///
/// `Self::ALIGN` must be equal to the alignment of `Self`. For sized types it
/// is [`mem::align_of<Self>()`], for unsized types it depends on the type, for
/// example `[T]` has alignment of `T`.
///
/// [`mem::align_of<Self>()`]: std::mem::align_of
pub unsafe trait Aligned {
/// Alignment of `Self`.
const ALIGN: Alignment;
}

unsafe impl<T> Aligned for T {
const ALIGN: Alignment = Alignment::of::<Self>();
}

unsafe impl<T> Aligned for [T] {
const ALIGN: Alignment = Alignment::of::<T>();
}
3 changes: 3 additions & 0 deletions compiler/rustc_data_structures/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#![feature(get_mut_unchecked)]
#![feature(lint_reasons)]
#![feature(unwrap_infallible)]
#![feature(strict_provenance)]
#![feature(ptr_alignment_type)]
#![allow(rustc::default_hash_types)]
#![allow(rustc::potential_query_instability)]
#![deny(rustc::untranslatable_diagnostic)]
Expand Down Expand Up @@ -82,6 +84,7 @@ pub mod transitive_relation;
pub mod vec_linked_list;
pub mod work_queue;
pub use atomic_ref::AtomicRef;
pub mod aligned;
pub mod frozen;
pub mod owned_slice;
pub mod sso;
Expand Down
Loading