about summary refs log tree commit diff
path: root/src/liballoc/allocator.rs
AgeCommit message (Collapse)AuthorLines
2018-01-20Replace Unique<T> with NonZero<T> in Alloc traitSimon Sapin-10/+10
2017-12-09Use Try syntax for Option in place of macros or matchMatt Brubeck-37/+9
2017-10-20Fix most rendering warnings from switching to CommonMarksteveklabnik-3/+3
2017-08-29Auto merge of #44049 - alexcrichton:nounwind-allocators, r=BurntSushibors-0/+23
std: Mark allocation functions as nounwind This commit flags all allocation-related functions in liballoc as "this can't unwind" which should largely resolve the size-related issues found on #42808. The documentation on the trait was updated with such a restriction (they can't panic) as well as some other words about the relative instability about implementing a bullet-proof allocator. Closes #42808
2017-08-28std: Mark allocation functions as nounwindAlex Crichton-0/+23
This commit flags all allocation-related functions in liballoc as "this can't unwind" which should largely resolve the size-related issues found on #42808. The documentation on the trait was updated with such a restriction (they can't panic) as well as some other words about the relative instability about implementing a bullet-proof allocator. Closes #42808
2017-08-24Fix inconsistent doc headingslukaramu-12/+12
This fixes headings reading "Unsafety" and "Example", they should be "Safety" and "Examples" according to RFC 1574.
2017-08-15Fix typos & us spellingsFourchaux-3/+3
2017-08-13Auto merge of #43815 - alexcrichton:optimize-alloc, r=sfacklerbors-0/+4
Optimize allocation paths in RawVec Since the `Alloc` trait was introduced (https://github.com/rust-lang/rust/pull/42313) and it was integrated everywhere (https://github.com/rust-lang/rust/pull/42727) there's been some slowdowns and regressions that have slipped through. The intention of this PR is to try to tackle at least some of them, but they've been very difficult to quantify up to this point so it probably doesn't solve everything. This PR primarily targets the `RawVec` type, specifically the `double` function. The codegen for this function is now much closer to what it was before #42313 landed as many runtime checks have been elided.
2017-08-12Fix some typosBastien Orivel-3/+3
2017-08-11std: Tag `AllocErr` functions as `#[inline]`Alex Crichton-0/+4
None of these require a significant amount of code and using `#[inline]` will allow constructors to get inlined, improving codegen at allocation callsites.
2017-08-11Fix some typosBastien Orivel-1/+1
2017-07-29Rollup merge of #43513 - alexcrichton:inline-repeat, r=BurntSushiMark Simulacrum-0/+1
std: Mark `Layout::repeat` as `#[inline]` This fixes an optimization regression by allowing LLVM to see through more functions. Closes #43272
2017-07-29std: Mark `Layout::repeat` as `#[inline]`Alex Crichton-0/+1
This fixes an optimization regression by allowing LLVM to see through more functions. Closes #43272
2017-07-28Auto merge of #43217 - pnkfelix:alloc-requires-align-it-in-u32, r=alexcrichtonbors-7/+15
Add precondition to `Layout` that the `align` fit in a u32. Add precondition to `Layout` that the `align` not exceed 2^31. This precondition takes the form of a behavorial change in `Layout::from_size_align` (so it returns `None` if the input `align` is too large) and a new requirement for safe usage of `Layout::from_size_align_unchecked`. Fix #30170.
2017-07-22Rename {NonZero,Shared,Unique}::new to new_uncheckedSimon Sapin-3/+3
2017-07-13Add precondition to `Layout` that the `align` fit in a u32.Felix S. Klock II-7/+15
This precondition takes the form of a behavorial change in `Layout::from_size_align` (so it returns `None` if the `align` is too large) and a new requirement for safe usage of `Layout::from_size_align_unchecked`. Fix #30170.
2017-07-05rustc: Implement the #[global_allocator] attributeAlex Crichton-2/+21
This PR is an implementation of [RFC 1974] which specifies a new method of defining a global allocator for a program. This obsoletes the old `#![allocator]` attribute and also removes support for it. [RFC 1974]: https://github.com/rust-lang/rfcs/pull/197 The new `#[global_allocator]` attribute solves many issues encountered with the `#![allocator]` attribute such as composition and restrictions on the crate graph itself. The compiler now has much more control over the ABI of the allocator and how it's implemented, allowing much more freedom in terms of how this feature is implemented. cc #27389
2017-06-25std: Fix implementation of `Alloc::alloc_one`Alex Crichton-1/+1
This had an accidental `u8 as *mut T` where it was intended to have just a normal pointer-to-pointer cast. Closes #42827
2017-06-19Minor Allocator doc fixAlex Crichton-1/+0
2017-06-15implement Error trait for error structs added in allocator API.Felix S. Klock II-0/+28
2017-06-15Changed `Layout::from_size_align` to return `Option`.Felix S. Klock II-19/+43
Added `unwrap` calls in all the places where I can infer that the conditions are met to avoid panic (or when the calling method itself says it will panic in such a case).
2017-06-15Add API for `Alloc` trait.Felix S. Klock II-0/+986
Includes `alloc_zeroed` method that `RawVec` has come to depend on. Exposed private `Layout::from_size_align` ctor to be `pub`, and added explicit conditions for when it will panic (namely, when `align` is not power-of-two, or if rounding up `size` to a multiple of `align` overflows). Normalized all `Layout` construction to go through `Layout::from_size_align`. Addressed review feedback regarding `struct Layout` and zero-sized layouts. Restrict specification for `dealloc`, adding additional constraint that the given alignment has to match that used to allocate the block. (This is a maximally conservative constraint on the alignment. An open question to resolve (before stabilization) is whether we can return to a looser constraint such as the one previously specified.) Split `fn realloc_in_place` into separate `fn grow_in_place` and `fn shrink_in_place` methods, which have default impls that check against usable_size for reuse. Make `realloc` default impl try `grow_in_place` or `shrink_in_place` as appropriate before fallback on alloc+copy+dealloc. Drive-by: When reviewing calls to `padding_needed_for`, discovered what I think was an over-conservative choice for its argument alignment. Namely, in `fn extend`, we automatically realign the whole resulting layout to satisfy both old (self) and new alignments. When the old alignment exceeds the new, this means we would insert unnecessary padding. So I changed the code to pass in `next.align` instead of `new_align` to `padding_needed_for`. Replaced ref to `realloc_in_place` with `grow_in_place`/`shrink_in_place`. Revised docs replacing my idiosyncratic style of `fn foo` with just `foo` when referring to the function or method `foo`. (Alpha-renamed `Allocator` to `Alloc`.) Post-rebased, added `Debug` derive for `allocator::Excess` to satisfy `missing_debug_implementations`.