Skip to content
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

fix(util): make intrusive list links never Unpin #97

Merged
merged 1 commit into from
Mar 28, 2021
Merged
Changes from all commits
Commits
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
12 changes: 8 additions & 4 deletions util/src/intrusive/list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use core::fmt;
use core::mem::ManuallyDrop;
use core::ptr::NonNull;
use core::{fmt, marker::PhantomPinned, mem::ManuallyDrop, ptr::NonNull};

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

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

if let Some(prev) = prev {
T::links(prev).as_mut().next = next;
Expand Down Expand Up @@ -193,13 +195,15 @@ impl<T: ?Sized> Links<T> {
Self {
next: None,
prev: None,
_unpin: PhantomPinned,
}
}

fn take(&mut self) -> Self {
Self {
next: self.next.take(),
prev: self.next.take(),
_unpin: PhantomPinned,
}
}

Expand Down