about summary refs log tree commit diff
path: root/src/libstd
AgeCommit message (Collapse)AuthorLines
2018-11-02Remove all jemalloc-related contentAlex Crichton-18/+4
This commit removes all jemalloc related submodules, configuration, etc, from the bootstrap, from the standard library, and from the compiler. This will be followed up with a change to use jemalloc specifically as part of rustc on blessed platforms.
2018-11-02Auto merge of #54043 - fintelia:raw_entry, r=alexcrichtonbors-6/+673
Add raw_entry API to HashMap This is a continuation of #50821.
2018-11-02Auto merge of #55359 - alex:command-exec-uaf, r=alexcrichtonbors-8/+99
Fixes #46775 -- don't mutate the process's environment in Command::exec Instead, pass the environment to execvpe, so the kernel can apply it directly to the new process. This avoids a use-after-free in the case where exec'ing the new process fails for any reason, as well as a race condition if there are other threads alive during the exec. Fixes #46775
2018-11-01std: Enable usage of `thread_local!` through importsAlex Crichton-4/+4
The `thread_local!` macro delegated to an internal macro but it didn't do so in a macros-and-the-module-system compatible fashion, meaning if a `#![no_std]` crate imported `std` and tried to use `thread_local!` it would fail due to missing a lookup of an internal macro. This commit switches the macro to instead use `$crate` to invoke other macros, ensuring that it'll work when `thread_local!` is imported alone.
2018-11-01std: Improve codegen size of accessing TLSAlex Crichton-1/+10
Some code in the TLS implementation in libstd stores `Some(val)` into an `&mut Option<T>` (effectively) and then pulls out `&T`, but it currently uses `.unwrap()` which can codegen into a panic even though it can never panic. With sufficient optimizations enabled (like LTO) the compiler can see through this but this commit helps it along in normal mode (`--release` with Cargo by default) to avoid codegen'ing the panic path. This ends up improving the optimized codegen on wasm by ensuring that a call to panic pulling in more file size doesn't stick around.
2018-11-01Fixes #46775 -- don't mutate the process's environment in Command::execAlex Gaynor-8/+99
Instead, pass the environment to execvpe, so the kernel can apply it directly to the new process. This avoids a use-after-free in the case where exec'ing the new process fails for any reason, as well as a race condition if there are other threads alive during the exec.
2018-10-31A couple suggested editsJonathan Behrens-7/+3
2018-10-31Bump nightly to 1.32.0Alex Crichton-1/+0
* Also update the bootstrap compiler * Update cargo to 1.32.0 * Clean out stage0 annotations
2018-10-30thread::unpark: Avoid notifying with mutex locked.James Duley-2/+12
This means when the other thread wakes it can continue right away instead of having to wait for the mutex. Also add some comments explaining why the mutex needs to be locked in the first place.
2018-10-30Add example of using the indexing operator to HashMap docsFlorian Hartwig-0/+3
2018-10-28Auto merge of #55043 - oliver-giersch:unchecked_thread_spawning, r=alexcrichtonbors-13/+78
Unchecked thread spawning # Summary Add an unsafe interface for spawning lifetime-unrestricted threads for library authors to build less-contrived, less-hacky safe abstractions on. # Motivation So a few years back scoped threads were entirely removed from the Rust stdlib, the reason being that it was possible to leak the scoped thread's join guards without resorting to unsafe code, which meant the concept was not completely safe, either. Only a maximally-restrictive safe API for thread spawning was kept in the stdlib, that requires `'static` lifetime bounds on both the thread closure and its return type. A number of 3rd party libraries sprung up to offer their implementations for safe scoped threads implementations. These work by essentially hiding the join guards from the user, thus forcing them to join at the end of an (internal) function scope. However, since these libraries have to use the maximally restrictive thread spawning API, they have to resort to some very contrived manipulations and subversions of Rust's type system to basically achieve what this commit does with some minimal restructuring of the current code and exposing a new unsafe function signature for spawning threads without lifetime restrictions. Obviously this is unsafe, but its main use would be to allow library authors to write safe abstractions with and around it. To further illustrate my point, here's a quick summary of the hoops that, for instance `crossbeam`, has to jump through to spawn a lifetime unrestricted thread, all of which would not be necessary if an unsafe API existed as part of the stdlib: 1. Allocate an `Arc<Option<T>>` on the heap where the result with type `T: 'a` will go (in practice requires `Mutex` or `UnsafeCell` as well). 2. Wrap the desired thread closure with lifetime bound `'a` into another closure (also `..: 'a`) that returns `()`, executes the inner closure and writes its result into the pre-allocated `Option<T>`. 3. Box the wrapping closure, cast it to a trait object (`FnBox`) and (unsafely) transmute its lifetime bound from `'a` to `'static`. So while this new `spawn_unchecked` function is certainly not very relevant for general use, since scoped threads are so common I think it makes sense to expose an interface for libraries implementing these to build on. The changes implemented are also very minimal: The current `spawn` function (which internally contains unsafe code) is moved into an unsafe `spawn_unchecked` function, which the safe function then wraps around. # Issues - ~~so far, no documentation for the new function (yet)~~ - the name of the function might be controversial, as `*_unchecked` more commonly indicates that some sort of runtime check is omitted (`unrestricted` may be more fitting) - if accepted, it might make sense to add a freestanding `thread::spawn_unchecked` function similar to the current `thread::spawn` for convenience.
2018-10-28Rollup merge of #55148 - SimonSapin:path-fromstr, r=oli-obkkennytm-0/+11
Implement FromStr for PathBuf Initially landed in https://github.com/rust-lang/rust/pull/48292 and reverted in https://github.com/rust-lang/rust/pull/50401. This time, use `std::string::ParseError` as suggested in https://github.com/rust-lang/rust/issues/44431#issuecomment-428112632
2018-10-27Correct alignment of atomic types and (re)add Atomic{I,U}128Oliver Middleton-0/+6
LLVM requires that atomic loads and stores be aligned to at least the size of the type.
2018-10-25Rollup merge of #55328 - raphlinus:copysign_typo, r=joshtriplettPietro Albini-8/+8
Fix doc for new copysign functions Thanks to @LukasKalbertodt for catching this. Addresses a comment raised in #55169 after it was merged.
2018-10-25Rollup merge of #55269 - matthiaskrgr:typos_oct, r=zackmdavisPietro Albini-3/+3
fix typos in various places
2018-10-25Rollup merge of #55247 - peterjoel:peterjoel-prim-char-doc-example, ↵Pietro Albini-2/+2
r=joshtriplett Clarified code example in char primitive doc The example was not as clear as it could be because it was making an assumption about the structure of the data in order to multiply the number of elements in the slice by the item size. This change demonstrates the idea more straightforwardly, without needing a calculation, by just comparing the size of the slices.
2018-10-25Rollup merge of #55200 - octronics:gh51430, r=kennytmPietro Albini-0/+88
Documents `From` implementations for `Stdio` This PR solves part of #51430 by adding a basic summary and an example to each `impl From` inside `process` module (`ChildStdin`, `ChildStdout`, `ChildStderr`, `File`). It does not document if the conversions allocate memory and how expensive they are.
2018-10-25Rollup merge of #54965 - chathaway-codes:update-tcp-stream-docs, ↵Pietro Albini-5/+5
r=GuillaumeGomez update tcp stream documentation A small styling issue that seemed inconsistent here when compared to other places (such as https://doc.rust-lang.org/beta/std/net/struct.TcpListener.html).
2018-10-25Rollup merge of #53931 - iirelu:keyword-docs, r=steveklabnikPietro Albini-28/+669
Gradually expanding libstd's keyword documentation I'm working on adding new keywords to the documentation and refreshing the incomplete older ones, and I'm hoping that I can eventually add all the standalone-usable keywords after a bunch of incremental work. It would be cool to see the keywords section of std's docs be a definitive reference as to what each keyword means when you see it, and that's what I'm aiming towards with this work. I'm far from a Rust expert so there will inevitably be things to fix in this, also I'm not sure if this should be a bunch of quickly-merged PRs or one gradually-updated PR that gets merged once it's done.
2018-10-24Fix doc for new copysign functionsRaph Levien-8/+8
Thanks to @LukasKalbertodt for catching this. Addresses a comment raised in #55169 after it was merged.
2018-10-24Documents `From` implementations for `Stdio`OCTronics-0/+88
Add a basic summary and an example to From `ChildStdin`, `ChildStdout`, `ChildStderr`, `File` implementations.
2018-10-23Hopefully fix compile erroriirelu-1/+0
This was added in the fortnight this PR spent stale. I'm hoping this one-liner fixes it.
2018-10-23fix typos in various placesMatthias Krüger-3/+3
2018-10-21Clarified code examplePeter Hall-2/+2
The example was not as clear as it could be because it was making an assumption about the structure of the data in order to multiply the number of collection elements by the item size. This change demonstrates the idea more straightforwardly, without the calculation.
2018-10-20Auto merge of #55014 - ljedrz:lazyboye_unwraps, r=matthewjasperbors-4/+4
Prefer unwrap_or_else to unwrap_or in case of function calls/allocations The contents of `unwrap_or` are evaluated eagerly, so it's not a good pick in case of function calls and allocations. This PR also changes a few `unwrap_or`s with `unwrap_or_default`. An added bonus is that in some cases this change also reveals if the object it's called on is an `Option` or a `Result` (based on whether the closure takes an argument).
2018-10-19Rollup merge of #55169 - raphlinus:copysign, r=joshtriplettkennytm-0/+58
Add a `copysign` function to f32 and f64 This patch adds a `copysign` function to the float primitive types. It is an exceptionally useful function for writing efficient numeric code, as it often avoids branches, is auto-vectorizable, and there are efficient intrinsics for most platforms. I think this might work as-is, as the relevant `copysign` intrinsic is already used internally for the implementation of `signum`. It's possible that an implementation might be needed in japaric/libm for portability across all platforms, in which case I'll do that also. Part of the work towards #55107
2018-10-19Prefer unwrap_or_else to unwrap_or in case of function calls/allocationsljedrz-4/+4
2018-10-18Add must_use on copysignRaph Levien-0/+2
Added a #[must_use] annotation on copysign, per review feedback.
2018-10-18Fix tidy checksjD91mZM2-1/+1
2018-10-18Revert liblibc submodule urljD91mZM2-7/+2
2018-10-18Interpret shebangs on redoxjD91mZM2-14/+80
This is no longer handled on the kernel side
2018-10-18Don't forget to close executable fileJeremy Soller-1/+2
2018-10-18Remove unused type parameterJeremy Soller-1/+1
2018-10-18Update to new system calls and enviromental variablesJeremy Soller-57/+167
2018-10-18Rollup merge of #54646 - vn971:fix_std_thread_sleep, r=frewsxcvkennytm-10/+14
improve documentation on std::thread::sleep
2018-10-17Fix inconsistent documentationRaph Levien-4/+5
I improved the f32 version and made a copy-paste error for f64.
2018-10-17Add a `copysign` function to f32 and f64Raph Levien-0/+55
This patch adds a `copysign` function to the float primitive types. It is an exceptionally useful function for writing efficient numeric code, as it often avoids branches, is auto-vectorizable, and there are efficient intrinsics for most platforms. I think this might work as-is, as the relevant `copysign` intrinsic is already used internally for the implementation of `signum`. It's possible that an implementation might be needed in japaric/libm for portability across all platforms, in which case I'll do that also. Part of the work towards #55107
2018-10-17Implement FromStr for PathBufSimon Sapin-0/+11
Initially landed in https://github.com/rust-lang/rust/pull/48292 and reverted in https://github.com/rust-lang/rust/pull/50401. This time, use `std::string::ParseError` as suggested in https://github.com/rust-lang/rust/issues/44431#issuecomment-428112632
2018-10-16adds tracking issue numberoliver-giersch-1/+1
2018-10-15Merge pull request #5 from oliver-giersch/masteroliver-giersch-25/+122
sync with upstream
2018-10-15adds feature gate to doc-test (example)oliver-giersch-0/+1
2018-10-15adds missing method call parenthesesoliver-giersch-1/+1
2018-10-15fixes misplaced semicolonoliver-giersch-2/+2
2018-10-15adds doc for `Builder::spawn_unchecked`oliver-giersch-1/+60
2018-10-14remove unnecessary lifetime boundsoliver-giersch-2/+2
generic lifetime bound `'a` can be inferred.
2018-10-14Fix incorrect link in println! documentationDiana-1/+1
The eprintln! link was incorrectly linking to eprint! instead
2018-10-13Update mod.rsoliver-giersch-3/+3
removes trailing whitespaces, replaces TODO with FIXME
2018-10-13Update mod.rsoliver-giersch-3/+2
removes unnecessary `unsafe`, adds `unstable` attribute
2018-10-13Auto merge of #54951 - alexcrichton:more-wasm-threads, r=sfacklerbors-25/+122
std: Implement TLS for wasm32-unknown-unknown This adds an implementation of thread local storage for the `wasm32-unknown-unknown` target when the `atomics` feature is implemented. This, however, comes with a notable caveat of that it requires a new feature of the standard library, `wasm-bindgen-threads`, to be enabled. Thread local storage for wasm (when `atomics` are enabled and there's actually more than one thread) is powered by the assumption that an external entity can fill in some information for us. It's not currently clear who will fill in this information nor whose responsibility it should be long-term. In the meantime there's a strategy being gamed out in the `wasm-bindgen` project specifically, and the hope is that we can continue to test and iterate on the standard library without committing to a particular strategy yet. As to the details of `wasm-bindgen`'s strategy, LLVM doesn't currently have the ability to emit custom `global` values (thread locals in a `WebAssembly.Module`) so we leverage the `wasm-bindgen` CLI tool to do it for us. To that end we have a few intrinsics, assuming two global values: * `__wbindgen_current_id` - gets the current thread id as a 32-bit integer. It's `wasm-bindgen`'s responsibility to initialize this per-thread and then inform libstd of the id. Currently `wasm-bindgen` performs this initialization as part of the `start` function. * `__wbindgen_tcb_{get,set}` - in addition to a thread id it's assumed that there's a global available for simply storing a pointer's worth of information (a thread control block, which currently only contains thread local storage). This would ideally be a native `global` injected by LLVM, but we don't have a great way to support that right now. To reiterate, this is all intended to be unstable and purely intended for testing out Rust on the web with threads. The story is very likely to change in the future and we want to make sure that we're able to do that!
2018-10-13adds unsafe `thread::Builder::spawn_unchecked` functionoliver-giersch-11/+17
moves code for `thread::Builder::spawn` into new public unsafe function `spawn_unchecked` and transforms `spawn` into a safe wrapper.