Commit Graph

45 Commits

Author SHA1 Message Date
Mazdak Farrokhzad e15c62d61f revert making internal APIs const fn. 2018-11-10 01:10:07 +01:00
Mazdak Farrokhzad d1d2aa22c0 reduce list to functions callable in const ctx. 2018-11-10 01:10:07 +01:00
Mazdak Farrokhzad 5b89877dda constify parts of libcore. 2018-11-10 01:07:32 +01:00
Amanieu d'Antras 02d50de63e Add a tracking issue for extra Layout methods 2018-11-06 20:36:43 +00:00
Amanieu d'Antras de027b64f1 API changes as discussed in the comments 2018-11-06 17:21:13 +00:00
Amanieu d'Antras 94f3ce9def Add a comment about how Layout::extend matches the C struct layout 2018-11-06 17:21:13 +00:00
Matthias Krüger 4972beaf65 fix typos in various places 2018-10-23 15:56:25 +02:00
ljedrz 1667950d73 Remove explicit returns where unnecessary 2018-08-04 14:31:03 +02:00
Mark Rousskov 683a3db01f Switch to bootstrapping from 1.29 beta 2018-08-01 11:59:08 -06:00
Simon Sapin 239ec7d2dc Implement #[alloc_error_handler]
This to-be-stable attribute is equivalent to `#[lang = "oom"]`.
It is required when using the alloc crate without the std crate.
It is called by `handle_alloc_error`, which is in turned called
by "infallible" allocations APIs such as `Vec::push`.
2018-07-09 23:13:24 +02:00
Simon Sapin b0547cea0a Move core::alloc::CollectionAllocErr to alloc::collections 2018-06-29 14:01:33 +02:00
Simon Sapin 1565fc2120 Document that Layout::from_size_align does not allow align=0
This was already implied since zero is not a power of two, but maybe
worth pointing out.
2018-06-27 15:07:42 +02:00
Simon Sapin 2b789bd057 Rename OOM to allocation error
The acronym is not descriptive unless one has seen it before.

* Rename the `oom` function to `handle_alloc_error`. It was **stabilized in 1.28**, so if we do this at all we need to land it this cycle.
* Rename `set_oom_hook` to `set_alloc_error_hook`
* Rename `take_oom_hook` to `take_alloc_error_hook`

Bikeshed: `alloc` v.s. `allocator`, `error` v.s. `failure`
2018-06-18 21:41:24 +02:00
Simon Sapin 7f0d54d988 More alloc docs tweaks 2018-06-11 13:48:57 -07:00
Simon Sapin 9dcb64f346 Alloc docs teaks 2018-06-11 13:48:57 -07:00
Simon Sapin bbaff036e7 Stablize the GlobalAlloc trait
Fixes https://github.com/rust-lang/rust/issues/49668
2018-06-11 13:48:39 -07:00
Simon Sapin 77606f20c9 Stabilize alloc::Layout (with only some of its methods) 2018-06-11 13:48:33 -07:00
Simon Sapin 75e17da873 Mark as permanently-unstable some implementation details 2018-06-11 13:48:27 -07:00
Simon Sapin 951bc28fd0 Stablize the alloc module without changing stability of its contents. 2018-06-11 13:48:25 -07:00
Simon Sapin e9fd063edb Document memory allocation APIs
Add some docs where they were missing,
attempt to fix them where they were out of date.
2018-06-11 13:47:28 -07:00
Mike Hommey f6ab74b8e7 Remove alloc::Opaque and use *mut u8 as pointer type for GlobalAlloc 2018-06-11 13:47:23 -07:00
Mark Simulacrum 4ce7ef5f59 Rollup merge of #51226 - gnzlbg:nonzero_align, r=SimonSapin
Make Layout's align a NonZeroUsize

This PR makes the `Layout`'s align field a `NonZeroUsize` since it cannot ever be zero, not even while building a `Layout`. It also contains some drive-by minor cleanups over the docs and the code, like updating the documented error types, or using the `size()` and `align()` methods instead of accessing the fields directly (the latter was required for the `NonZeroUsize` change anyways).

r? @SimonSapin

cc @Amanieu
2018-06-02 19:55:06 -06:00
gnzlbg 2d7cd70b1a add missing inline's and optimizations 2018-06-02 16:46:25 +02:00
gnzlbg 6ff67ee0d7 remove debug_assert in padding_needed_for 2018-06-02 16:03:33 +02:00
Amanieu d'Antras c6bebf4554 Simplify HashMap layout calculation by using Layout 2018-06-01 17:24:03 +01:00
gnzlbg 6c3ebcd223 make Layout's align a NonZeroUsize 2018-05-30 21:00:37 +02:00
Steven Fackler 9e8f683476 Remove Alloc::oom 2018-04-22 10:08:49 -07:00
Steven Fackler e513c1bd31 Replace GlobalAlloc::oom with a lang item 2018-04-22 10:08:17 -07:00
Simon Sapin 1caaafdce7 Implement Copy for std::alloc::Layout
Fixes https://github.com/rust-lang/rust/issues/48458
2018-04-20 13:56:07 +02:00
bors 56109dbf70 Auto merge of #49884 - alexcrichton:less-unwrap, r=Mark-Simulacrum
core: Remove panics from some `Layout` methods

`Layout` is often used at the core of allocation APIs and is as a result pretty
sensitive to codegen in various circumstances. I was profiling `-C opt-level=z`
with a wasm project recently and noticed that the `unwrap()` wasn't removed
inside of `Layout`, causing the program to be much larger than it otherwise
would be. If inlining were more aggressive LLVM would have figured out that the
panic could be eliminated, but in general the methods here can't panic in the
first place!

As a result this commit makes the following tweaks:

* Removes `unwrap()` and replaces it with `unsafe` in `Layout::new` and
  `Layout::for_value`. For posterity though a debug assertion was left behind.
* Removes an `unwrap()` in favor of `?` in the `repeat` method. The comment
  indicating that the function call couldn't panic wasn't quite right in that if
  `alloc_size` becomes too large and if `align` is high enough it could indeed
  cause a panic.

This'll hopefully mean that panics never get introduced into code in the first
place, ensuring that `opt-level=z` is closer to `opt-level=s` in this regard.
2018-04-15 06:33:48 +00:00
Alex Crichton 68e555b7d0 core: Remove panics from some Layout methods
`Layout` is often used at the core of allocation APIs and is as a result pretty
sensitive to codegen in various circumstances. I was profiling `-C opt-level=z`
with a wasm project recently and noticed that the `unwrap()` wasn't removed
inside of `Layout`, causing the program to be much larger than it otherwise
would be. If inlining were more aggressive LLVM would have figured out that the
panic could be eliminated, but in general the methods here can't panic in the
first place!

As a result this commit makes the following tweaks:

* Removes `unwrap()` and replaces it with `unsafe` in `Layout::new` and
  `Layout::for_value`. For posterity though a debug assertion was left behind.
* Removes an `unwrap()` in favor of `?` in the `repeat` method. The comment
  indicating that the function call couldn't panic wasn't quite right in that if
  `alloc_size` becomes too large and if `align` is high enough it could indeed
  cause a panic.

This'll hopefully mean that panics never get introduced into code in the first
place, ensuring that `opt-level=z` is closer to `opt-level=s` in this regard.
2018-04-13 07:02:10 -07:00
Alex Crichton 2e73e76e73 core: Inline From<AllocErr> for CollectionAllocErr
This shows up in allocations of vectors and such, so no need for it to not be
inlined!
2018-04-13 07:00:03 -07:00
Simon Sapin c5ffdd787d Initial docs for the GlobalAlloc trait 2018-04-12 22:53:22 +02:00
Simon Sapin f607a3872a Rename alloc::Void to alloc::Opaque 2018-04-12 22:53:22 +02:00
Simon Sapin ed29777759 Remove conversions for allocated pointers
One was now unused, and `NonNull::new(…).ok_or(AllocErr)` feels short enough
for the few cases that need the other conversion.
2018-04-12 22:53:22 +02:00
Mike Hommey fddf51ee0b Use NonNull<Void> instead of *mut u8 in the Alloc trait
Fixes #49608
2018-04-12 22:53:22 +02:00
Simon Sapin eae0d46893 Restore Global.oom() functionality
… now that #[global_allocator] does not define a symbol for it
2018-04-12 22:53:21 +02:00
Simon Sapin 747cc74943 Conversions between Result<*mut u8, AllocErr>> and *mut Void 2018-04-12 22:53:14 +02:00
Simon Sapin c957e99b30 realloc with a new size only, not a full new layout.
Changing the alignment with realloc is not supported.
2018-04-12 22:53:13 +02:00
Simon Sapin b017742136 Return Result instead of Option in alloc::Layout constructors 2018-04-12 22:53:13 +02:00
Simon Sapin 93a9ad4897 Remove the now-unit-struct AllocErr field inside CollectionAllocErr 2018-04-12 22:53:13 +02:00
Simon Sapin 157ff8cd05 Remove the now-unit-struct AllocErr parameter of oom() 2018-04-12 22:53:13 +02:00
Simon Sapin eb69593f73 Implement GlobalAlloc for System 2018-04-12 22:53:03 +02:00
Simon Sapin ba7081a033 Make AllocErr a zero-size unit struct 2018-04-12 22:53:03 +02:00
Simon Sapin 09e8db1e4f Rename heap modules in the core, alloc, and std crates to alloc 2018-04-12 22:52:47 +02:00