about summary refs log tree commit diff
path: root/src/libcore
AgeCommit message (Collapse)AuthorLines
2018-04-21Make the unstable StrExt and SliceExt traits private to libcore in not(stage0)Simon Sapin-24/+36
`Float` still needs to be public for libcore unit tests.
2018-04-21Move intrinsics-based float methods out of libcore into libstdSimon Sapin-72/+0
Affected methods are `abs`, `signum`, and `powi`. CC https://github.com/rust-lang/rust/issues/32110#issuecomment-379503183
2018-04-21Add some f32 and f64 inherent methods in libcoreSimon Sapin-1/+580
… previously in the unstable core::num::Float trait. Per https://github.com/rust-lang/rust/issues/32110#issuecomment-379503183, the `abs`, `signum`, and `powi` methods are *not* included for now since they rely on LLVM intrinsics and we haven’t determined yet whether those instrinsics lower to calls to libm functions on any platform.
2018-04-21Replace StrExt with inherent str methods in libcoreSimon Sapin-14/+1750
2018-04-21Replace SliceExt with inherent [T] methods in libcoreSimon Sapin-1/+1406
2018-04-21Move non-allocating [u8] inherent methods to libcoreSimon Sapin-0/+66
Fixes #45803
2018-04-20Revert "Stabilize the TryFrom and TryInto traits"Felix S. Klock II-21/+18
This reverts commit e53a2a72743810e05f58c61c9d8a4c89b712ad2e.
2018-04-20Revert stabilization of `feature(never_type)`.Felix S. Klock II-8/+9
This commit is just covering the feature gate itself and the tests that made direct use of `!` and thus need to opt back into the feature. A follow on commit brings back the other change that motivates the revert: Namely, going back to the old rules for falling back to `()`.
2018-04-20Implement Copy for std::alloc::LayoutSimon Sapin-1/+1
Fixes https://github.com/rust-lang/rust/issues/48458
2018-04-19Auto merge of #48553 - seanmonstar:atomic-debug, r=alexcrichtonbors-5/+3
atomic: remove 'Atomic*' from Debug output For the same reason that we don't show `Vec { data: [0, 1, 2, 3] }`, but just the array, the `AtomicUsize(1000)` is noisy, and seeing just `1000` is likely better.
2018-04-19Auto merge of #49630 - npmccallum:shl, r=alexcrichtonbors-3/+3
Update Rhs on ShlAssign to default to Self This matches the behavior on ShrAssign and all other *Assign operations.
2018-04-18Auto merge of #50017 - tinaun:stabilize-all-the-things, r=sfacklerbors-27/+21
stabilize a bunch of minor api additions besides `ptr::NonNull::cast` (which is 4 days away from end of FCP) all of these have been finished with FCP for a few weeks now with minimal issues raised * Closes #41020 * Closes #42818 * Closes #44030 * Closes #44400 * Closes #46507 * Closes #47653 * Closes #46344 the following functions will be stabilized in 1.27: * `[T]::rsplit` * `[T]::rsplit_mut` * `[T]::swap_with_slice` * `ptr::swap_nonoverlapping` * `NonNull::cast` * `Duration::from_micros` * `Duration::from_nanos` * `Duration::subsec_millis` * `Duration::subsec_micros` * `HashMap::remove_entry`
2018-04-17smaller PR just to fix #50002Michael Lamparski-7/+2
2018-04-17Auto merge of #49542 - GuillaumeGomez:intra-link-resolution-error, ↵bors-2/+2
r=GuillaumeGomez Add warning if a resolution failed r? @QuietMisdreavus
2018-04-17stabilize `nonnull_cast` featuretinaun-1/+1
2018-04-17stabilize `duration_extras` featuretinaun-6/+3
2018-04-17stabilize `duration_from_micros` featuretinaun-2/+1
2018-04-17stabilize `swap_with_slice` featuretinaun-1/+1
2018-04-17stabilize `swap_nonoverlapping` featuretinaun-3/+1
2018-04-17stabilize `slice_rsplit` featuretinaun-14/+14
2018-04-17Auto merge of #49664 - alexcrichton:stable-simd, r=BurntSushibors-3/+26
Stabilize x86/x86_64 SIMD This commit stabilizes the SIMD in Rust for the x86/x86_64 platforms. Notably this commit is stabilizing: * The `std::arch::{x86, x86_64}` modules and the intrinsics contained inside. * The `is_x86_feature_detected!` macro in the standard library * The `#[target_feature(enable = "...")]` attribute * The `#[cfg(target_feature = "...")]` matcher Stabilization of the module and intrinsics were primarily done in rust-lang-nursery/stdsimd#414 and the two attribute stabilizations are done in this commit. The standard library is also tweaked a bit with the new way that stdsimd is integrated. Note that other architectures like `std::arch::arm` are not stabilized as part of this commit, they will likely stabilize in the future after they've been implemented and fleshed out. Similarly the `std::simd` module is also not being stabilized in this commit, only `std::arch`. Finally, nothing related to `__m64` is stabilized in this commit either (MMX), only SSE and up types and intrinsics are stabilized. Closes #29717 Closes #44839 Closes #48556
2018-04-16Auto merge of #49488 - alexcrichton:small-wasm-panic, r=sfacklerbors-4/+24
std: Minimize size of panicking on wasm This commit applies a few code size optimizations for the wasm target to the standard library, namely around panics. We notably know that in most configurations it's impossible for us to print anything in wasm32-unknown-unknown so we can skip larger portions of panicking that are otherwise simply informative. This allows us to get quite a nice size reduction. Finally we can also tweak where the allocation happens for the `Box<Any>` that we panic with. By only allocating once unwinding starts we can reduce the size of a panicking wasm module from 44k to 350 bytes.
2018-04-16Remove unwanted auto-linking and updateGuillaume Gomez-2/+2
2018-04-16Separately gate each target_feature featureAlex Crichton-0/+8
Use an explicit whitelist for what features are actually stable and can be enabled.
2018-04-16Auto merge of #49130 - smmalis37:range, r=alexcrichtonbors-34/+123
Move Range*::contains to a single default impl on RangeBounds Per the ongoing discussion in #32311. This is my first PR to Rust (woo!), so I don't know if this requires an amendment to the original range_contains RFC, or not, or if we can just do a psuedo-RFC here. While this may no longer follow the explicit decision made in that RFC, I believe this better follows its spirit by adding the new contains method to all Ranges. It also allows users to be generic over all ranges and use this method without writing it themselves (my personal desired use case). This also somewhat answers the unanswered question about Wrapping ranges in the above issue by instead just punting it to the question of what those types should return for start() & end(), or if they should implement RangeArgument at all. Those types could also implement their own contains method without implementing this trait, in which case the question remains the same. This does add a new contains method to types that already implemented RangeArgument but not contains. These types are RangeFull, (Bound<T>, Bound<T>), (Bound<&'a T>, Bound<&'a T>). No tests have been added for these types yet. No inherent method has been added either. r? @alexcrichton
2018-04-16Stabilize x86/x86_64 SIMDAlex Crichton-3/+18
This commit stabilizes the SIMD in Rust for the x86/x86_64 platforms. Notably this commit is stabilizing: * The `std::arch::{x86, x86_64}` modules and the intrinsics contained inside. * The `is_x86_feature_detected!` macro in the standard library * The `#[target_feature(enable = "...")]` attribute * The `#[cfg(target_feature = "...")]` matcher Stabilization of the module and intrinsics were primarily done in rust-lang-nursery/stdsimd#414 and the two attribute stabilizations are done in this commit. The standard library is also tweaked a bit with the new way that stdsimd is integrated. Note that other architectures like `std::arch::arm` are not stabilized as part of this commit, they will likely stabilize in the future after they've been implemented and fleshed out. Similarly the `std::simd` module is also not being stabilized in this commit, only `std::arch`. Finally, nothing related to `__m64` is stabilized in this commit either (MMX), only SSE and up types and intrinsics are stabilized. Closes #29717 Closes #44839 Closes #48556
2018-04-16Stabilize core::hint::unreachable_unchecked.kennytm-16/+69
Closes #43751.
2018-04-16Auto merge of #49963 - llogiq:stabilize-13226, r=kennytmbors-13/+12
stabilize fetch_nand This closes #13226 and makes `Atomic*.fetch_nand` stable.
2018-04-15Auto merge of #49884 - alexcrichton:less-unwrap, r=Mark-Simulacrumbors-8/+14
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-15Deprecate Read::chars and char::decode_utf8Simon Sapin-0/+15
Per FCP: * https://github.com/rust-lang/rust/issues/27802#issuecomment-377537778 * https://github.com/rust-lang/rust/issues/33906#issuecomment-377534308
2018-04-14Auto merge of #49850 - alexcrichton:moreinline, r=sfacklerbors-0/+1
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-14stabilize fetch_nandAndre Bogus-13/+12
2018-04-14Rollup merge of #49871 - SimonSapin:int-bytes, r=sfacklerkennytm-0/+89
Add to_bytes and from_bytes to primitive integers Discussion issue turned tracking issue: https://github.com/rust-lang/rust/issues/49792
2018-04-14Add to_bytes and from_bytes to primitive integersSimon Sapin-0/+89
2018-04-14Rollup merge of #49916 - llogiq:doc-atomic-fetch-update, r=kennytmkennytm-2/+2
improve Atomic*::fetch_update docs This clarifies that fetch_update *always* returns the previous value, either as `Ok(_)` or `Err(_)`, depending on whether the supplied update function returned `Some(_)` or `None`.
2018-04-14Rollup merge of #49915 - llogiq:doc-shift-types, r=joshtriplettkennytm-2/+12
[doc] note the special type inference handling for shift ops This adds a note to the docs about the difference between the shift ops and the corresponding trait methods when it comes to type inference.
2018-04-13[doc] note the special type inference handling for shiftsAndre Bogus-2/+12
2018-04-13std: Avoid allocating panic message unless neededAlex Crichton-4/+10
This commit removes allocation of the panic message in instances like `panic!("foo: {}", "bar")` if we don't actually end up needing the message. We don't need it in the case of wasm32 right now, and in general it's not needed for panic=abort instances that use the default panic hook. For now this commit only solves the wasm use case where with LTO the allocation is entirely removed, but the panic=abort use case can be implemented at a later date if needed.
2018-04-13core: Remove an implicit panic from Formatter::padAlex Crichton-1/+5
The expression `&s[..i]` in general can panic if `i` is out of bounds or not on a character boundary for a string, and this caused the codegen for `Formatter::pad` to be a bit larger than it otherwise needed to be. This commit replaces this with `s.get(..i).unwrap_or(&s)` which while having different behavior if `i` is out of bounds has a much smaller code footprint and otherwise avoids the need for `unsafe` code.
2018-04-13std: Minimize size of panicking on wasmAlex Crichton-0/+10
This commit applies a few code size optimizations for the wasm target to the standard library, namely around panics. We notably know that in most configurations it's impossible for us to print anything in wasm32-unknown-unknown so we can skip larger portions of panicking that are otherwise simply informative. This allows us to get quite a nice size reduction. Finally we can also tweak where the allocation happens for the `Box<Any>` that we panic with. By only allocating once unwinding starts we can reduce the size of a panicking wasm module from 44k to 350 bytes.
2018-04-13core: Remove panics from some `Layout` methodsAlex Crichton-8/+14
`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-13core: Inline `From<AllocErr> for CollectionAllocErr`Alex Crichton-0/+1
This shows up in allocations of vectors and such, so no need for it to not be inlined!
2018-04-13Auto merge of #49669 - SimonSapin:global-alloc, r=alexcrichtonbors-149/+215
Add GlobalAlloc trait + tweaks for initial stabilization This is the outcome of discussion at the Rust All Hands in Berlin. The high-level goal is stabilizing sooner rather than later the ability to [change the global allocator](https://github.com/rust-lang/rust/issues/27389), as well as allocating memory without abusing `Vec::with_capacity` + `mem::forget`. Since we’re not ready to settle every detail of the `Alloc` trait for the purpose of collections that are generic over the allocator type (for example the possibility of a separate trait for deallocation only, and what that would look like exactly), we propose introducing separately **a new `GlobalAlloc` trait**, for use with the `#[global_allocator]` attribute. We also propose a number of changes to existing APIs. They are batched in this one PR in order to minimize disruption to Nightly users. The plan for initial stabilization is detailed in the tracking issue https://github.com/rust-lang/rust/issues/49668. CC @rust-lang/libs, @glandium ## Immediate breaking changes to unstable features * For pointers to allocated memory, change the pointed type from `u8` to `Opaque`, a new public [extern type](https://github.com/rust-lang/rust/issues/43467). Since extern types are not `Sized`, `<*mut _>::offset` cannot be used without first casting to another pointer type. (We hope that extern types can also be stabilized soon.) * In the `Alloc` trait, change these pointers to `ptr::NonNull` and change the `AllocErr` type to a zero-size struct. This makes return types `Result<ptr::NonNull<Opaque>, AllocErr>` be pointer-sized. * Instead of a new `Layout`, `realloc` takes only a new size (in addition to the pointer and old `Layout`). Changing the alignment is not supported with `realloc`. * Change the return type of `Layout::from_size_align` from `Option<Self>` to `Result<Self, LayoutErr>`, with `LayoutErr` a new opaque struct. * A `static` item registered as the global allocator with the `#[global_allocator]` **must now implement the new `GlobalAlloc` trait** instead of `Alloc`. ## Eventually-breaking changes to unstable features, with a deprecation period * Rename the respective `heap` modules to `alloc` in the `core`, `alloc`, and `std` crates. (Yes, this does mean that `::alloc::alloc::Alloc::alloc` is a valid path to a trait method if you have `exetrn crate alloc;`) * Rename the the `Heap` type to `Global`, since it is the entry point for what’s registered with `#[global_allocator]`. Old names remain available for now, as deprecated `pub use` reexports. ## Backward-compatible changes * Add a new [extern type](https://github.com/rust-lang/rust/issues/43467) `Opaque`, for use in pointers to allocated memory. * Add a new `GlobalAlloc` trait shown below. Unlike `Alloc`, it uses bare `*mut Opaque` without `NonNull` or `Result`. NULL in return values indicates an error (of unspecified nature). This is easier to implement on top of `malloc`-like APIs. * Add impls of `GlobalAlloc` for both the `Global` and `System` types, in addition to existing impls of `Alloc`. This enables calling `GlobalAlloc` methods on the stable channel before `Alloc` is stable. Implementing two traits with identical method names can make some calls ambiguous, but most code is expected to have no more than one of the two traits in scope. Erroneous code like `use std::alloc::Global; #[global_allocator] static A: Global = Global;` (where `Global` is defined to call itself, causing infinite recursion) is not statically prevented by the type system, but we count on it being hard enough to do accidentally and easy enough to diagnose. ```rust extern { pub type Opaque; } pub unsafe trait GlobalAlloc { unsafe fn alloc(&self, layout: Layout) -> *mut Opaque; unsafe fn dealloc(&self, ptr: *mut Opaque, layout: Layout); unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut Opaque { // Default impl: self.alloc() and ptr::write_bytes() } unsafe fn realloc(&self, ptr: *mut Opaque, old_layout: Layout, new_size: usize) -> *mut Opaque { // Default impl: self.alloc() and ptr::copy_nonoverlapping() and self.dealloc() } fn oom(&self) -> ! { // intrinsics::abort } // More methods with default impls may be added in the future } ``` ## Bikeshed The tracking issue https://github.com/rust-lang/rust/issues/49668 lists some open questions. If consensus is reached before this PR is merged, changes can be integrated.
2018-04-13Auto merge of #49389 - fanzier:euclidean-division, r=KodrAusbors-0/+440
Implement RFC #2169 (Euclidean modulo). Tracking issue: #49048
2018-04-12Address more nits.Fabian Zaiser-7/+6
2018-04-12Initial docs for the GlobalAlloc traitSimon Sapin-5/+39
2018-04-12Rename alloc::Void to alloc::OpaqueSimon Sapin-21/+21
2018-04-12Remove conversions for allocated pointersSimon Sapin-17/+0
One was now unused, and `NonNull::new(…).ok_or(AllocErr)` feels short enough for the few cases that need the other conversion.
2018-04-12Use NonNull<Void> instead of *mut u8 in the Alloc traitMike Hommey-33/+33
Fixes #49608
2018-04-12Restore Global.oom() functionalitySimon Sapin-0/+4
… now that #[global_allocator] does not define a symbol for it