about summary refs log tree commit diff
path: root/src/libstd
AgeCommit message (Collapse)AuthorLines
2019-04-05Future-proof the Futures APITaylor Cramer-29/+40
2019-04-05Use for_each to extend collectionsJosh Stone-6/+2
This updates the `Extend` implementations to use `for_each` for many collections: `BinaryHeap`, `BTreeMap`, `BTreeSet`, `LinkedList`, `Path`, `TokenStream`, `VecDeque`, and `Wtf8Buf`. Folding with `for_each` enables better performance than a `for`-loop for some iterators, especially if they can just forward to internal iterators, like `Chain` and `FlatMap` do.
2019-04-05wasi: Use shared API for preopened fdsAlex Crichton-87/+86
This commit updates the wasi target with supported added in CraneStation/wasi-sysroot#10. That function allows both C and Rust to cooperate in how preopened files are managed, enabling us to learn about propened files through the same interface. The `open_parent` function in the wasi `fs` module was updated to avoid its own initialization of a global preopened map and instead delegate to libc to perform this functionality. This should both be more robust into the future in terms of handling path logic as well as ensuring the propened map is correctly set up at process boot time. This does currently require some unfortunate allocations on our side, but if that becomes an issue we can always paper over those in time!
2019-04-05Rollup merge of #59690 - xfix:patch-17, r=cramertjMazdak Farrokhzad-0/+3
Mark unix::ffi::OsStrExt methods as inline This is a small change, but I found it surprising it's not inlined looking at the assembly.
2019-04-05Rollup merge of #59665 - ssomers:hashset_revisited, r=KodrAusMazdak Farrokhzad-1/+5
improve worst-case performance of HashSet.is_subset One more simple optimization opportunity for HashSet that was applied in BTreeSet in #59186 (and wasn't in #57043). Already covered by the existing unit test. r? @KodrAus
2019-04-05Auto merge of #59643 - alexcrichton:wasi-symbols, r=sanxiynbors-1/+1
std: Upgrade `compiler_builtins` to fix wasi linkage Turns out we needed to exclude a number of math functions on the `wasm32-unknown-wasi` target, and this was fixed in 0.1.9 of compiler-builtins and this is pulling in the fix to libstd's own build.
2019-04-04std: Upgrade `compiler_builtins` to fix wasi linkageAlex Crichton-1/+1
Turns out we needed to exclude a number of math functions on the `wasm32-unknown-wasi` target, and this was fixed in 0.1.9 of compiler-builtins and this is pulling in the fix to libstd's own build.
2019-04-04Auto merge of #59676 - alexcrichton:osx-deadlock, r=sfacklerbors-13/+38
std: Avoid usage of `Once` in `Instant` This commit removes usage of `Once` from the internal implementation of time utilities on OSX and Windows. It turns out that we accidentally hit a deadlock today (#59020) via events that look like: * A thread invokes `park_timeout` * Internally, only on OSX, `park_timeout` calls `Instant::elapsed` * Inside of `Instant::elapsed` on OSX we enter a `Once` to initialize global timer data * Inside of `Once`, it attempts to `park` This means on the same stack frame, when there's contention, we're calling `park` from inside `park_timeout`, causing a deadlock! The solution implemented in this commit was to remove usage of `Once` and instead just do a small dance with atomics. There's no real need we need to guarantee that the global information is only learned once, only that it's only *stored* once. This implementation may have multiple threads invoke `mach_timebase_info`, but only one will store the global information which will amortize the cost for all other threads. A similar fix has been applied to windows to be uniform across our implementations, but looking at the code on Windows no deadlock was possible. This is purely just a consistency update for Windows and in theory a slightly leaner implementation. Closes #59020
2019-04-04Auto merge of #59695 - Centril:rollup-88qffc2, r=Centrilbors-2/+9
Rollup of 8 pull requests Successful merges: - #59470 (Document std::fs::File close behavior ignoring errors) - #59555 (update miri) - #59556 (update stdsimd) - #59596 (Forward formatter settings to bounds of `Range<T>` in `fmt::Debug` impl) - #59639 (Never return uninhabited values at all) - #59671 (Make some of lexer's API private) - #59685 (Add description for -Os and -Oz in rustc.1) - #59686 (Temporarily disable stack probing for gnux32.) Failed merges: r? @ghost
2019-04-04std: Avoid usage of `Once` in `Instant`Alex Crichton-13/+38
This commit removes usage of `Once` from the internal implementation of time utilities on OSX and Windows. It turns out that we accidentally hit a deadlock today (#59020) via events that look like: * A thread invokes `park_timeout` * Internally, only on OSX, `park_timeout` calls `Instant::elapsed` * Inside of `Instant::elapsed` on OSX we enter a `Once` to initialize global timer data * Inside of `Once`, it attempts to `park` This means on the same stack frame, when there's contention, we're calling `park` from inside `park_timeout`, causing a deadlock! The solution implemented in this commit was to remove usage of `Once` and instead just do a small dance with atomics. There's no real need we need to guarantee that the global information is only learned once, only that it's only *stored* once. This implementation may have multiple threads invoke `mach_timebase_info`, but only one will store the global information which will amortize the cost for all other threads. A similar fix has been applied to windows to be uniform across our implementations, but looking at the code on Windows no deadlock was possible. This is purely just a consistency update for Windows and in theory a slightly leaner implementation. Closes #59020
2019-04-04Rollup merge of #59470 - czipperz:document-fs-file-close, r=dtolnayMazdak Farrokhzad-2/+9
Document std::fs::File close behavior ignoring errors Resolves #52685
2019-04-04Auto merge of #59619 - alexcrichton:wasi-fs, r=fitzgenbors-304/+1189
wasi: Implement more of the standard library This commit fills out more of the `wasm32-unknown-wasi` target's standard library, notably the `std::fs` module and all of its internals. A few tweaks were made along the way to non-`fs` modules, but the last commit contains the bulk of the work which is to wire up all APIs to their equivalent on WASI targets instead of unconditionally returning "unsupported". After this some basic filesystem operations and such should all be working in WASI!
2019-04-04Mark unix::ffi::OsStrExt methods as inlineKonrad Borowski-0/+3
2019-04-03File: Add documentation about dropping to sync_allChris Gregory-1/+5
2019-04-03Support using LLVM's libunwind as the unwinder implementationPetr Hosek-0/+1
This avoids the dependency on host libraries such as libgcc_s which may be undesirable in some deployment environments where these aren't available.
2019-04-03wasi: Fill out `std::fs` module for WASIAlex Crichton-262/+1141
This commit fills out the `std::fs` module and implementation for WASI. Not all APIs are implemented, such as permissions-related ones and `canonicalize`, but all others APIs have been implemented and very lightly tested so far. We'll eventually want to run a more exhaustive test suite! For now the highlights of this commit are: * The `std::fs::File` type is now backed by `WasiFd`, a raw WASI file descriptor. * All APIs in `std::fs` (except permissions/canonicalize) have implementations for the WASI target. * A suite of unstable extension traits were added to `std::os::wasi::fs`. These traits expose the raw filesystem functionality of WASI, namely `*at` syscalls (opening a file relative to an already opened one, for example). Additionally metadata only available on wasi is exposed through these traits. Perhaps one of the most notable parts is the implementation of path-taking APIs. WASI actually has no fundamental API that just takes a path, but rather everything is relative to a previously opened file descriptor. To allow existing APIs to work (that only take a path) WASI has a few syscalls to learn about "pre opened" file descriptors by the runtime. We use these to build a map of existing directory names to file descriptors, and then when using a path we try to anchor it at an already-opened file. This support is very rudimentary though and is intended to be shared with C since it's likely to be so tricky. For now though the C library doesn't expose quite an API for us to use, so we implement it for now and will swap it out as soon as one is available.
2019-04-03improve worst-case performance of HashSet.is_subsetStein Somers-1/+5
2019-04-02Link to sync_allChris Gregory-1/+2
2019-04-01Document using `sync_all`Chris Gregory-4/+3
2019-04-01SGX target: Use linker option to avoid code CGU assignment kludgeJethro Beekman-41/+44
2019-04-01wasi: Implement `error_string` to get readable errorsAlex Crichton-2/+15
This routes the `error_string` API to `strerror` in libc which should have more human readable descriptions.
2019-04-01SGX target: convert a bunch of panics to abortsJethro Beekman-48/+61
2019-04-01wasi: Use raw syscalls for stdioAlex Crichton-14/+9
I've since learned that the mapping between libc fds and wasi fds are expected to be one-to-one, so we can use the raw syscalls for writing to stdout/stderr and reading from stdin! This should help ensure that we don't depend on a C library too unnecessarily.
2019-04-01wasi: Load arguments via syscallsAlex Crichton-26/+24
This commit switches the wasi target to loading CLI arguments via the syscalls provided by wasi rather than through the argc/argv passed to the main function. While serving the same purpose it's hoped that using syscalls will make us a bit more portable (less reliance from libstd on an external C library) as well as avoiding the need for a lock!
2019-03-31Rollup merge of #59587 - XAMPPRocky:master, r=CentrilMazdak Farrokhzad-1/+0
Remove #[doc(hidden)] from Error::type_id Nominating this for beta so that `Error::type_id` has documentation in time for release. cc @rust-lang/release @rust-lang/docs
2019-03-31Remove #[doc(hidden)] from Error::type_idAaron Power-1/+0
2019-03-31libstd: deny(elided_lifetimes_in_paths), fixes in redoxMazdak Farrokhzad-1/+1
2019-03-31libstd: deny(elided_lifetimes_in_paths), fixes in sgxMazdak Farrokhzad-19/+20
2019-03-31libstd: deny(elided_lifetimes_in_paths), fixes in wasiMazdak Farrokhzad-25/+25
2019-03-31libstd: deny(elided_lifetimes_in_paths), fixes in cloudabiMazdak Farrokhzad-3/+4
2019-03-31libstd: deny(elided_lifetimes_in_paths)Mazdak Farrokhzad-367/+372
2019-03-30Added a missing !.Christian-1/+1
2019-03-30Added an example that shows how the remainder function on floating point ↵Christian-3/+3
values is computed internally.
2019-03-30Rollup merge of #59532 - mbrubeck:docs, r=CentrilMazdak Farrokhzad-6/+19
In doc examples, don't ignore read/write results Calling `Read::read` or `Write::write` without checking the returned `usize` value is almost always an error. Example code in the documentation should demonstrate how to use the return value correctly. Otherwise, people might copy the example code thinking that it is okay to "fire and forget" these methods.
2019-03-30Rollup merge of #59528 - DevQps:improve-dbg-macro-docs, r=CentrilMazdak Farrokhzad-1/+7
Improve the dbg! macro docs # Description As stated has been discussed in #58383 the docs do not clearly state why it is useful to have the option to use `dbg!` in release builds as well. This PR should change that. closes #58383
2019-03-30Rollup merge of #59512 - euclio:stdio-locks, r=sfacklerMazdak Farrokhzad-0/+51
implement `AsRawFd` for stdio locks cc https://github.com/rust-lang/rfcs/issues/2074.
2019-03-29Add a new wasm32-unknown-wasi targetAlex Crichton-2/+1974
This commit adds a new wasm32-based target distributed through rustup, supported in the standard library, and implemented in the compiler. The `wasm32-unknown-wasi` target is intended to be a WebAssembly target which matches the [WASI proposal recently announced.][LINK]. In summary the WASI target is an effort to define a standard set of syscalls for WebAssembly modules, allowing WebAssembly modules to not only be portable across architectures but also be portable across environments implementing this standard set of system calls. The wasi target in libstd is still somewhat bare bones. This PR does not fill out the filesystem, networking, threads, etc. Instead it only provides the most basic of integration with the wasi syscalls, enabling features like: * `Instant::now` and `SystemTime::now` work * `env::args` is hooked up * `env::vars` will look up environment variables * `println!` will print to standard out * `process::{exit, abort}` should be hooked up appropriately None of these APIs can work natively on the `wasm32-unknown-unknown` target, but with the assumption of the WASI set of syscalls we're able to provide implementations of these syscalls that engines can implement. Currently the primary engine implementing wasi is [wasmtime], but more will surely emerge! In terms of future development of libstd, I think this is something we'll probably want to discuss. The purpose of the WASI target is to provide a standardized set of syscalls, but it's *also* to provide a standard C sysroot for compiling C/C++ programs. This means it's intended that functions like `read` and `write` are implemented for this target with a relatively standard definition and implementation. It's unclear, therefore, how we want to expose file descriptors and how we'll want to implement system primitives. For example should `std::fs::File` have a libc-based file descriptor underneath it? The raw wasi file descriptor? We'll see! Currently these details are all intentionally hidden and things we can change over time. A `WasiFd` sample struct was added to the standard library as part of this commit, but it's not currently used. It shows how all the wasi syscalls could be ergonomically bound in Rust, and they offer a possible implementation of primitives like `std::fs::File` if we bind wasi file descriptors exactly. Apart from the standard library, there's also the matter of how this target is integrated with respect to its C standard library. The reference sysroot, for example, provides managment of standard unix file descriptors and also standard APIs like `open` (as opposed to the relative `openat` inspiration for the wasi ssycalls). Currently the standard library relies on the C sysroot symbols for operations such as environment management, process exit, and `read`/`write` of stdio fds. We want these operations in Rust to be interoperable with C if they're used in the same process. Put another way, if Rust and C are linked into the same WebAssembly binary they should work together, but that requires that the same C standard library is used. We also, however, want the `wasm32-unknown-wasi` target to be usable-by-default with the Rust compiler without requiring a separate toolchain to get downloaded and configured. With that in mind, there's two modes of operation for the `wasm32-unknown-wasi` target: 1. By default the C standard library is statically provided inside of `liblibc.rlib` distributed as part of the sysroot. This means that you can `rustc foo.wasm --target wasm32-unknown-unknown` and you're good to go, a fully workable wasi binary pops out. This is incompatible with linking in C code, however, which may be compiled against a different sysroot than the Rust code was previously compiled against. In this mode the default of `rust-lld` is used to link binaries. 2. For linking with C code, the `-C target-feature=-crt-static` flag needs to be passed. This takes inspiration from the musl target for this flag, but the idea is that you're no longer using the provided static C runtime, but rather one will be provided externally. This flag is intended to also get coupled with an external `clang` compiler configured with its own sysroot. Therefore you'll typically use this flag with `-C linker=/path/to/clang-script-wrapper`. Using this mode the Rust code will continue to reference standard C symbols, but the definition will be pulled in by the linker configured. Alright so that's all the current state of this PR. I suspect we'll definitely want to discuss this before landing of course! This PR is coupled with libc changes as well which I'll be posting shortly. [LINK]: [wasmtime]:
2019-03-29In doc examples, don't ignore read/write resultsMatt Brubeck-6/+19
Calling `Read::read` or `Write::write` without checking the returned `usize` value is almost always an error. Example code in the documentation should demonstrate how to use the return value correctly. Otherwise, people might copy the example code thinking that it is okay to "fire and forget" these methods.
2019-03-29Update src/libstd/macros.rs Mazdak Farrokhzad-1/+0
Removed duplicate line. Co-Authored-By: DevQps <46896178+DevQps@users.noreply.github.com>
2019-03-29Update src/libstd/macros.rs Mazdak Farrokhzad-1/+2
Wrapped lines earlier such that it is more coherent with the rest of the text. Co-Authored-By: DevQps <46896178+DevQps@users.noreply.github.com>
2019-03-29Adjusted the indentation.Christian-2/+3
2019-03-29Edited the dbg! docs stating that dbg! works the same way in release builds.Christian-1/+6
2019-03-29implement `AsRawFd` for stdio locksAndy Russell-0/+51
2019-03-29Rollup merge of #59511 - jethrogb:jb/maybeinit-deprecated, r=CentrilMazdak Farrokhzad-1/+1
Fix missed fn rename in #59284 See https://github.com/rust-lang/rust/pull/59284#issuecomment-477822797
2019-03-29Rollup merge of #59503 - crlf0710:stablize_copysign, r=SimonSapinMazdak Farrokhzad-4/+2
Stablize {f32,f64}::copysign(). Stablization PR for #55169/#58046. Please check if i'm doing it correctly. Is 1.35.0 good to go?
2019-03-28Fix missed fn rename in #59284Jethro Beekman-1/+1
2019-03-29Stablize {f32,f64}::copysign().CrLF0710-4/+2
2019-03-28Use write_all instead of write in example codeMatt Brubeck-7/+7
2019-03-28Rollup merge of #59474 - czipperz:bufwriter-fix-link-capitalization, r=CentrilMazdak Farrokhzad-2/+2
Fix link capitalization in documentation of std::io::BufWriter.
2019-03-28Rollup merge of #59472 - czipperz:bufreader-document-drop-discards, r=CentrilMazdak Farrokhzad-0/+4
Document that `std::io::BufReader` discards contents on drop Resolves #55546