-
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
Stabilize GlobalAlloc and #[global_allocator] #51241
Conversation
r? @aidanhs (rust_highfive has picked a reviewer for you, use r? to override) |
Cc: @SimonSapin |
Oh, I have pretty much the same branch and was only waiting to add docs before I submit it… :) |
I wanted to see how that would impact me, so I went ahead but didn't bother with the doc. :) |
The job 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 |
56439b4
to
dccf003
Compare
The job 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 |
I’ve pushed additional commits to this PR. @glandium’s commits look good to me, mine still need review. In particular for the new docs and the API contracts they describe. Both tracking issues for features being stabilized have already finished FCP, but since we’re making last minute changes let’s have a final Final Comment Perdiod: @rfcbot fcp merge |
Team member @SimonSapin has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
src/libcore/alloc.rs
Outdated
@@ -357,23 +360,28 @@ impl fmt::Display for AllocErr { | |||
/// The `CannotReallocInPlace` error is used when `grow_in_place` or | |||
/// `shrink_in_place` were unable to reuse the given memory block for | |||
/// a requested layout. | |||
// FIXME: should this be in libcore or liballoc? |
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.
This is used in the Alloc
trait and therefore needs to be in libcore.
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. Removed that comment.
impl fmt::Display for CannotReallocInPlace { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "{}", self.description()) | ||
} | ||
} | ||
|
||
/// Augments `AllocErr` with a CapacityOverflow variant. | ||
// FIXME: should this be in libcore or liballoc? |
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.
This could probably be moved to liballoc since it is only used by collections.
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.
I moved it when I created the core::alloc
module because it doesn’t depend on anything else, but with "collections" in the name maybe it belongs more where collections are define. I’ll leave this to whenever those APIs are stabilized.
src/libcore/alloc.rs
Outdated
/// | ||
/// * Pointers returned from allocation functions must point to valid memory and | ||
/// retain their validity until at least the instance of `GlobalAlloc` is dropped | ||
/// itself. |
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.
Does the concept of dropping an instance of GlobalAlloc
really make sense? Should we just require pointers to be valid forever until explicitly freed?
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.
Good point, a static
is never dropped. I copied this from Alloc
docs but it doesn’t make sense here, removed.
The job 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 |
/// library that aborts on memory exhaustion.) | ||
/// | ||
/// Clients wishing to abort computation in response to an | ||
/// allocation error are encouraged to call the [`oom`] function, |
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.
Will this link work?
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.
I hoped it would, but it doesn’t when the target is not in the source crate (or its dependencies?). Will fix.
/// or NULL to indicate reallocation failure. | ||
/// If this returns a non-null pointer, then ownership of the memory block | ||
/// referenced by `ptr` has been transferred to this alloctor. | ||
/// The memory may or may not have been deallocated, |
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.
In what situation would the memory not be deallocated?
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.
I’m not sure, I copied this form Alloc::realloc
docs. Maybe when realloc succeeds in place and returns the same pointer? Would you rather I remove that sentence?
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.
ownership of the memory block referenced by
ptr
has been transferred to this alloctor.
There's a typo on allocator. I'd add a "back" after transferred, too, to make it subtly clearer that ownership of the memory block started from this allocator.
@bors r=sfackler,SimonSapin |
📌 Commit 7f0d54d has been approved by |
Stabilize GlobalAlloc and #[global_allocator] This PR implements the changes discussed in #49668 (comment) Fixes #49668 Fixes #27389 This does not change the default global allocator: #36963
☀️ Test successful - status-appveyor, status-travis |
Now that docs are up-to-date on https://doc.rust-lang.org/nightly/std/alloc/index.html, it feels like the docs for the reexports should be "inlined" (e.g. |
Bug 1458161 added a rust OOM handler based on an unstable API that was removed in 1.27, replaced with something that didn't allow to get the failed allocation size. Latest 1.28 nightly (2018-06-13) has rust-lang/rust#50880, rust-lang/rust#51264 and rust-lang/rust#51241 merged, which allow to hook the OOM handler and get the failed allocation size again. Because this is still an unstable API, we explicitly depend on strict versions of rustc. We also explicitly error out if automation builds end up using a rustc version that doesn't allow us to get the allocation size for rust OOM, because we don't want that to happen without knowing. --HG-- extra : rebase_source : 6c097151046d088cf51f4755dd69bde97bb8bd8b
Prohibit `global_allocator` in submodules Background: #44113 is caused by weird interactions with hygiene. Hygiene is hard. After a lot of playing around, we decided that the best path forward would be to prohibit `global_allocator`s from being in submodules for now. When somebody gets it working, we can re-enable it. This PR contains the following - Some hygiene "fixes" -- things I suspect are the correct thing to do that will make life easier in the future. This includes using call_site hygiene for the generated module and passing the correct crate name to the expansion config. - Comments and minor formatting fixes - Some debugging code - Code to prohibit `global_allocator` in submodules - Test checking that the proper error occurs. cc #44113 #49320 #51241 r? @alexcrichton
Add tracking issue for Layout methods (and some API changes) These methods are already useful when used with the stable global allocator API (stabilized in #51241). ```rust pub fn align_to(&self, align: usize) -> Result<Layout, LayoutErr>; pub fn padding_needed_for(&self, align: usize) -> usize; pub fn repeat(&self, n: usize) -> Result<(Layout, usize), LayoutErr>; pub fn extend(&self, next: Layout) -> Result<(Layout, usize), LayoutErr>; pub fn repeat_packed(&self, n: usize) -> Result<Layout, LayoutErr>; pub fn extend_packed(&self, next: Layout) -> Result<Layout, LayoutErr>; pub fn array<T>(n: usize) -> Result<Layout, LayoutErr>; ``` cc #32838 r? @SimonSapin
Bug 1458161 added a rust OOM handler based on an unstable API that was removed in 1.27, replaced with something that didn't allow to get the failed allocation size. Latest 1.28 nightly (2018-06-13) has rust-lang/rust#50880, rust-lang/rust#51264 and rust-lang/rust#51241 merged, which allow to hook the OOM handler and get the failed allocation size again. Because this is still an unstable API, we explicitly depend on strict versions of rustc. We also explicitly error out if automation builds end up using a rustc version that doesn't allow us to get the allocation size for rust OOM, because we don't want that to happen without knowing. UltraBlame original commit: 5182bca90d0609f182d5a7b6b48ed2ffbbce32c2
Bug 1458161 added a rust OOM handler based on an unstable API that was removed in 1.27, replaced with something that didn't allow to get the failed allocation size. Latest 1.28 nightly (2018-06-13) has rust-lang/rust#50880, rust-lang/rust#51264 and rust-lang/rust#51241 merged, which allow to hook the OOM handler and get the failed allocation size again. Because this is still an unstable API, we explicitly depend on strict versions of rustc. We also explicitly error out if automation builds end up using a rustc version that doesn't allow us to get the allocation size for rust OOM, because we don't want that to happen without knowing. UltraBlame original commit: 5182bca90d0609f182d5a7b6b48ed2ffbbce32c2
Bug 1458161 added a rust OOM handler based on an unstable API that was removed in 1.27, replaced with something that didn't allow to get the failed allocation size. Latest 1.28 nightly (2018-06-13) has rust-lang/rust#50880, rust-lang/rust#51264 and rust-lang/rust#51241 merged, which allow to hook the OOM handler and get the failed allocation size again. Because this is still an unstable API, we explicitly depend on strict versions of rustc. We also explicitly error out if automation builds end up using a rustc version that doesn't allow us to get the allocation size for rust OOM, because we don't want that to happen without knowing. UltraBlame original commit: 5182bca90d0609f182d5a7b6b48ed2ffbbce32c2
This PR implements the changes discussed in #49668 (comment)
Fixes #49668
Fixes #27389
This does not change the default global allocator: #36963