Commit Graph

16 Commits

Author SHA1 Message Date
Fourchaux
c7104be1a3 Fix typos & us spellings 2017-08-15 21:56:30 +02:00
bors
ab40a7cb0e Auto merge of #43815 - alexcrichton:optimize-alloc, r=sfackler
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-13 19:28:57 +00:00
Bastien Orivel
3ab86fbab2 Fix some typos 2017-08-12 14:01:11 +02:00
Alex Crichton
a83d2afbba std: Tag AllocErr functions as #[inline]
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-11 15:58:26 -07:00
Bastien Orivel
47cb3c5bc2 Fix some typos 2017-08-11 00:16:18 +02:00
Mark Simulacrum
a3eadd767e Rollup merge of #43513 - alexcrichton:inline-repeat, r=BurntSushi
std: Mark `Layout::repeat` as `#[inline]`

This fixes an optimization regression by allowing LLVM to see through more
functions.

Closes #43272
2017-07-29 18:03:55 -06:00
Alex Crichton
54b6b23fc0 std: Mark Layout::repeat as #[inline]
This fixes an optimization regression by allowing LLVM to see through more
functions.

Closes #43272
2017-07-29 09:03:06 -07:00
bors
63b3a03dc8 Auto merge of #43217 - pnkfelix:alloc-requires-align-it-in-u32, r=alexcrichton
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-28 00:49:39 +00:00
Simon Sapin
0a08ad0443 Rename {NonZero,Shared,Unique}::new to new_unchecked 2017-07-22 20:38:16 +02:00
Felix S. Klock II
ef8804ba27 Add precondition to Layout that the align fit in a u32.
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-13 17:17:08 +02:00
Alex Crichton
695dee063b rustc: Implement the #[global_allocator] attribute
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-07-05 14:37:01 -07:00
Alex Crichton
d24d408af3 std: Fix implementation of Alloc::alloc_one
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-25 11:35:05 -07:00
Alex Crichton
609d43a15a Minor Allocator doc fix 2017-06-19 07:51:00 -07:00
Felix S. Klock II
12d4d12fef implement Error trait for error structs added in allocator API. 2017-06-15 23:48:31 +02:00
Felix S. Klock II
1d3bc4e90f Changed Layout::from_size_align to return Option.
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-15 23:48:30 +02:00
Felix S. Klock II
066fafe206 Add API for Alloc trait.
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`.
2017-06-15 23:48:12 +02:00