-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Use NonNull in the allocator API #49608
Conversation
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Your PR failed on Travis. Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
src/liballoc/boxed.rs
Outdated
unsafe { | ||
let p = unsafe { | ||
if layout.size() == 0 { | ||
NonNull::new_unchecked(mem::align_of::<T>() as *mut u8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe NonNull::<T>::dangling().cast()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that #48333 removes this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But there's another in raw_vec.rs.
src/liballoc/heap.rs
Outdated
use core::heap; | ||
pub use core::heap::{AllocErr, CannotReallocInPlace, CollectionAllocErr, Layout}; | ||
#[cfg(not(stage0))] | ||
pub use core::heap::{Alloc, Excess}; | ||
#[doc(hidden)] | ||
pub mod __core { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can #[cfg(stage0)]
be added to this __core
module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh right, because the only use of that __core
was the #[global_allocator]
expansion. Neat!
The change looks good to me. As you said, since we have more breaking changes upcoming it might be better to batch them so that Nightly users only need to do one migration. I’m working on |
☔ The latest upstream changes (presumably #48333) made this pull request unmergeable. Please resolve the merge conflicts. |
As discussed in rust-lang#32838 (comment) and following, instead of *mut pointers, use NonNull for the allocator API. One issue is that older rustc versions, used to bootstrap the compiler, expands #[global_allocator], used in various places including libstd or librustc_[almt]san, to code that uses the Alloc trait, so changes to that trait make bootstrapping fail. Thankfully, it does so through the location of the Alloc trait before 94d1970 so we can use at our advantage by making stage0 expose the old API as alloc::heap::Alloc. At the same time, we change the expansion for #[global_allocator] to use the new trait location under core, which will allow newer versions of rustc to bootstrap stage0 as well, despite the workaround described above.
Rebased on top of #48333. |
Also, addressed review comments. |
#49669 includes this change (and more). |
As discussed in #32838 (comment)
and following, instead of *mut pointers, use NonNull for the allocator
API.
One issue is that older rustc versions, used to bootstrap the compiler,
expands #[global_allocator], used in various places including libstd or
librustc_[almt]san, to code that uses the Alloc trait, so changes to
that trait make bootstrapping fail. Thankfully, it does so through the
location of the Alloc trait before 94d1970
so we can use at our advantage by making stage0 expose the old API as
alloc::heap::Alloc.
At the same time, we change the expansion for #[global_allocator] to use
the new trait location under core, which will allow newer versions of
rustc to bootstrap stage0 as well, despite the workaround described above.
The downside is that this is a breaking change, albeit, for an unstable feature,
that will pile up with the upcoming GlobalAlloc change. It /might/ make sense to
wait for GlobalAlloc to go in first, so that
#[global_allocator]
only breaks once.But I still wanted to put this out there, get feedback on the change itself. It will be
trivial to rebase on top of GlobalAlloc if we decide to wait for that.
Cc @SimonSapin @alexcrichton