Skip to content

Commit 7df5ced

Browse files
committed
fix(util): make intrusive list links never Unpin
In light of rust-lang/rust#82834, we must ensure that the intrusive linked list pointers never get mutable-noalias optimizations (see also rust-lang/rust#63818). Adding a `PhantomPinned` to the `Links` struct ensures it will always be `!Unpin`, disabling mutable-noalias. Signed-off-by: Eliza Weisman <[email protected]>
1 parent 20aec76 commit 7df5ced

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

util/src/intrusive/list.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
use core::fmt;
2-
use core::mem::ManuallyDrop;
3-
use core::ptr::NonNull;
1+
use core::{fmt, marker::PhantomPinned, mem::ManuallyDrop, ptr::NonNull};
42

53
pub unsafe trait Linked {
64
type Handle;
@@ -38,6 +36,10 @@ pub struct List<T: ?Sized> {
3836
pub struct Links<T: ?Sized> {
3937
next: Option<NonNull<T>>,
4038
prev: Option<NonNull<T>>,
39+
/// Linked list links must always be `!Unpin`, in order to ensure that they
40+
/// never recieve LLVM `noalias` annotations; see also
41+
/// https://github.com/rust-lang/rust/issues/63818.
42+
_unpin: PhantomPinned,
4143
}
4244

4345
pub struct Cursor<'a, T: ?Sized + Linked> {
@@ -142,7 +144,7 @@ impl<T: ?Sized + Linked> List<T> {
142144
pub unsafe fn remove(&mut self, item: NonNull<T>) -> Option<T::Handle> {
143145
let links = T::links(item).as_mut().take();
144146
tracing::trace!(?self, item.addr = ?item, item.links = ?links, "remove");
145-
let Links { next, prev } = links;
147+
let Links { next, prev, .. } = links;
146148

147149
if let Some(prev) = prev {
148150
T::links(prev).as_mut().next = next;
@@ -193,13 +195,15 @@ impl<T: ?Sized> Links<T> {
193195
Self {
194196
next: None,
195197
prev: None,
198+
_unpin: PhantomPinned,
196199
}
197200
}
198201

199202
fn take(&mut self) -> Self {
200203
Self {
201204
next: self.next.take(),
202205
prev: self.next.take(),
206+
_unpin: PhantomPinned,
203207
}
204208
}
205209

0 commit comments

Comments
 (0)