Commit graph

585 commits

Author SHA1 Message Date
Dan Gohman
8d2c622d48 Implement AsRawFd for StdinLock etc. on WASI.
WASI implements `AsRawFd` for `Stdin`, `Stdout`, and `Stderr`, so
implement it for `StdinLock`, `StdoutLock`, and `StderrLock` as well.
2020-10-08 14:34:54 -07:00
Thom Chiovoloni
f30cc74fb4 Avoid SeqCst or static mut in mach_timebase_info cache 2020-10-08 14:34:11 -07:00
Jonas Schievink
7edb7e7ec0
Rollup merge of #77660 - nilslice:patch-1, r=jyn514
(docs): make mutex error comment consistent with codebase

Although exceptionally minor, I found this stands out from other error reporting language used in doc comments. With the existence of the `failure` crate, I suppose this could be slightly ambiguous. In any case, this change brings the particular comment into a consistent state with other mentions of returning errors.
2020-10-08 23:23:10 +02:00
Mara Bos
3d192ace34 Remove unsafety from unsupported/rwlosck.rs by using a Cell.
Replacing the UnsafeCell by a Cell makes it all safe.
2020-10-08 23:08:31 +02:00
Mara Bos
c25f69a1e3 Remove unsafety from unsupported/mutex.rs by using a Cell.
Replacing the UnsafeCell by a Cell simplifies things and makes it all
safe.
2020-10-08 23:08:31 +02:00
Mara Bos
e55d27fbce Remove unnecessary rustc_const_stable attributes. 2020-10-08 22:29:13 +02:00
bors
6b8d7911a1 Auto merge of #77346 - Caduser2020:master, r=Mark-Simulacrum
`#[deny(unsafe_op_in_unsafe_fn)]` in sys/sgx

This is part of #73904.

Enclose unsafe operations in unsafe blocks in `libstd/sys/sgx`.
2020-10-08 17:36:25 +00:00
Caduser2020
1fb0a1d501 #[deny(unsafe_op_in_unsafe_fn)] in sys/sgx
Run `./x.py` fmt

Add reference link

Fix reference link

Apply review suggestions.
2020-10-08 10:09:18 -05:00
Mark Rousskov
d8c035abbf Bump to 1.48 bootstrap compiler 2020-10-07 19:51:36 -04:00
Steve Manuel
56b51a9751
(docs): make mutex error comment consistent with codebase 2020-10-07 11:48:26 -06:00
Mara Bos
b3be11efbd Formatting. 2020-10-07 18:20:56 +02:00
Mara Bos
060e8cbaf1 Get rid of raw pointers and UnsafeCell in cloudabi condvar. 2020-10-07 18:20:07 +02:00
Mara Bos
41066beb4d Get rid of UnsafeCell in cloudabi rwlock. 2020-10-07 18:20:07 +02:00
Mara Bos
0f26578f2e Get rid of UnsafeCell<MaybeUninit>s in cloudabi mutex. 2020-10-07 18:20:07 +02:00
Mara Bos
e6d61ade9c Use slice_as_mut_ptr instead of first_ptr_mut.
This function was renamed.
2020-10-07 18:20:07 +02:00
Mara Bos
54a71e8954 For backtrace, use StaticMutex instead of a raw sys Mutex. 2020-10-07 13:59:03 +02:00
bors
c9ced8523b Auto merge of #77626 - tamird:parse-scope-id, r=dtolnay
Parse SocketAddrV6::scope_id

r? `@dtolnay`
2020-10-07 03:11:06 +00:00
Tamir Duberstein
49ade22bd9
Parse SocketAddrV6::scope_id 2020-10-06 22:13:15 +00:00
Tamir Duberstein
a093957f43
Avoid unused return 2020-10-06 22:12:16 +00:00
bors
98edd1fbf8 Auto merge of #77386 - joshtriplett:static-glibc, r=petrochenkov
Support static linking with glibc and target-feature=+crt-static

With this change, it's possible to build on a linux-gnu target and pass
RUSTFLAGS='-C target-feature=+crt-static' or the equivalent via a
`.cargo/config.toml` file, and get a statically linked executable.

Update to libc 0.2.78, which adds support for static linking with glibc.

Add `crt_static_respected` to the `linux_base` target spec.

Update `android_base` and `linux_musl_base` accordingly. Avoid enabling
crt_static_respected on Android platforms, since that hasn't been
tested.

Closes https://github.com/rust-lang/rust/issues/65447.
2020-10-06 21:11:04 +00:00
Mara Bos
f84f01c014 Use futex-based thread-parker for Wasm32. 2020-10-06 20:02:02 +02:00
Yuki Okushi
eac25fefaf
Rollup merge of #77528 - tamird:avoid-cast-net-parser, r=dtolnay
Avoid unchecked casts in net parser

Once this and #77426 are in, I'll send another PR adding scope id parsing.

r? @dtolnay
2020-10-06 16:26:02 +09:00
Yuki Okushi
59476e9e57
Rollup merge of #76388 - poliorcetics:system-time-document-panic, r=KodrAus
Add a note about the panic behavior of math operations on time objects

Fixes #71226.
2020-10-06 16:25:53 +09:00
Josh Triplett
16ebf750cf Update libc to 0.2.79
This also fixes issues with inconsistent `unsafe` on functions.
2020-10-04 22:12:07 -07:00
Dylan DPC
f1afed541e
Rollup merge of #77426 - tamird:sockaddr-scope-id, r=dtolnay
Include scope id in SocketAddrV6::Display

r? @tmandry

I couldn't find any unit tests for these functions.

cc @ghanan94 @brunowonka
2020-10-05 02:29:35 +02:00
Tamir Duberstein
f78a7ade61
Inline "eof" methods 2020-10-04 17:07:30 +00:00
Tamir Duberstein
9601724b11
Avoid unchecked casts in net parser 2020-10-04 16:57:54 +00:00
Jonas Schievink
4ae7710e1d
Rollup merge of #77072 - sharnoff:hash-docs, r=LukasKalbertodt
Minor `hash_map` doc adjustments + item attribute orderings

This PR is really a couple visual changes glued together:
1. Some of the doc comments for items in `std::collections::hash_map` referenced the names of types without escaping their formatting (e.g. using "VacantEntry" instead of "`VacantEntry`") - the ones I could find were changed to the latter
2. The vast majority of pre-item attributes seem to place doc comments as the first attribute (instead of things like `#[feature(...)]`), so the few that had the other order were changed.
3. Also ordering related: the general trend seems to be that `#[feature]` attributes follow `#[inline]`, so I swapped the two lines in places where that ordering was reversed. This is primarily a change based on stylistic continuity and aesthetics - I'm not sure how important that actually is / should be.

I figured this would be pretty uncontroversial, but some of these might have been intentional for reasons I don't know about - if so, I'd be happy to remove the relevant changes. Of these, the final set of changes is probably the most unnecessary, so it also might be better to leave those out (in favor of reducing code churn).
2020-10-04 15:45:33 +02:00
Tamir Duberstein
4585c22818
Include scope id in SocketAddrV6::Display 2020-10-04 12:18:12 +00:00
bors
32cbc65e6b Auto merge of #77380 - fusion-engineering-forks:unbox-the-mutex, r=dtolnay
Unbox mutexes and condvars on some platforms

Both mutexes and condition variables contained a Box containing the actual os-specific object. This was done because moving these objects may cause undefined behaviour on some platforms.

However, this is not needed on Windows[1], Wasm[2], cloudabi[2], and 'unsupported'[3], were the box was only needlessly making them less efficient.

This change gets rid of the box on those platforms.

On those platforms, `Condvar` can no longer verify it is only used with one `Mutex`, as mutexes no longer have a stable address. This was addressed and considered acceptable in #76932.

[1]\: https://docs.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-initializesrwlock
[2]\: These are just a single atomic integer together with futex wait/wake calls/instructions.
[3]\: The `unsupported` platform doesn't support multiple threads at all.
2020-10-04 06:48:17 +00:00
Jonas Schievink
01ca8299d4
Rollup merge of #77264 - fusion-engineering-forks:skip-local-stdio, r=dtolnay
Only use LOCAL_{STDOUT,STDERR} when set_{print/panic} is used.

The thread local `LOCAL_STDOUT` and `LOCAL_STDERR` are only used by the `test` crate to capture output from tests when running them in the same process in differen threads. However, every program will check these variables on every print, even outside of testing.

This involves allocating a thread local key, and registering a thread local destructor. This can be somewhat expensive.

This change keeps a global flag (`LOCAL_STREAMS`) which will be set to `true` when either of these local streams is used. (So, effectively only in test and benchmark runs.) When this flag is off, these thread locals are not even looked at and therefore will not be initialized on the first output on every thread, which also means no thread local destructors will be registered.

---

Together with https://github.com/rust-lang/rust/pull/77154, this should make output a little bit more efficient.
2020-10-03 00:31:14 +02:00
Jonas Schievink
ccc020ab42
Rollup merge of #77182 - GuillaumeGomez:missing-examples-fd-traits, r=pickfire
Add missing examples for Fd traits

Not sure what happened here... This is a reopening of #77142

r? @Dylan-DPC
2020-10-03 00:31:10 +02:00
Jonas Schievink
1118ab9930
Rollup merge of #75377 - canova:map_debug_impl, r=dtolnay
Fix Debug implementations of some of the HashMap and BTreeMap iterator types

HashMap's `ValuesMut`, BTreeMaps `ValuesMut`, IntoValues and `IntoKeys` structs were printing both keys and values on their Debug implementations. But they are iterators over either keys or values. Irrelevant values should not be visible. With this PR, they only show relevant fields.
This fixes #75297.

[Here's an example code.](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=0c79356ed860e347a0c1a205616f93b7) This prints this on nightly:
```
ValuesMut { inner: IterMut { range: [(1, "hello"), (2, "goodbye")], length: 2 } }
IntoKeys { inner: [(1, "hello"), (2, "goodbye")] }
IntoValues { inner: [(1, "hello"), (2, "goodbye")] }
[(2, "goodbye"), (1, "hello")]
```

After the patch this example prints these instead:
```
["hello", "goodbye"]
["hello", "goodbye"]
[1, 2]
["hello", "goodbye"]
```

I didn't add test cases for them, since I couldn't see any tests for Debug implementations anywhere. But please let me know if I should add it to a specific place.

r? @dtolnay
2020-10-03 00:31:04 +02:00
Jonas Schievink
72d275d844
Rollup merge of #77432 - tmiasko:posix-spawn-musl, r=cuviper
Use posix_spawn on musl targets

The posix_spawn had been available in a form suitable for use in a
Command implementation since musl 0.9.12. Use it in a preference to a
fork when possible, to benefit from CLONE_VM|CLONE_VFORK used there.
2020-10-02 20:27:11 +02:00
Guillaume Gomez
d6b838b93a Simplify fd examples 2020-10-02 16:38:15 +02:00
bors
154f1f544d Auto merge of #77029 - ehuss:command-access, r=dtolnay
Add accessors to Command.

This adds some accessor methods to `Command` to provide a way to access the values set when building the `Command`. An example where this can be useful is to display the command to be executed. This is roughly based on the [`ProcessBuilder`](13b73cdaf7/src/cargo/util/process_builder.rs (L105-L134)) in Cargo.

Possible concerns about the API:
- Values with NULs on Unix will be returned as `"<string-with-nul>"`. I don't think it is practical to avoid this, since otherwise a whole separate copy of all the values would need to be kept in `Command`.
- Does not handle `arg0` on Unix. This can be awkward to support in `get_args` and is rarely used. I figure if someone really wants it, it can be added to `CommandExt` as a separate method.
- Does not offer a way to detect `env_clear`. I'm uncertain if it would be useful for anyone.
- Does not offer a way to get an environment variable by name (`get_env`). I figure this can be added later if anyone really wants it. I think the motivation for this is weak, though. Also, the API could be a little awkward (return a `Option<Option<&OsStr>>`?).
- `get_envs` could skip "cleared" entries and just return `&OsStr` values instead of `Option<&OsStr>`. I'm on the fence here. My use case is to display a shell command, and I only intend it to be roughly equivalent to the actual execution, and I probably won't display `None` entries. I erred on the side of providing extra information, but I suspect many situations will just filter out the `None`s.
- Could implement more iterator stuff (like `DoubleEndedIterator`).

I have not implemented new std items before, so I'm uncertain if the existing issue should be reused, or if a new tracking issue is needed.

cc #44434
2020-10-02 07:51:24 +00:00
Mara Bos
b1ce7a38a6 Disable condvar::two_mutexes test on non-unix platforms.
Condvars are no longer guaranteed to panic in this case on all
platforms. At least the unix implementation still does.
2020-10-02 09:47:08 +02:00
Mara Bos
f3837e788b No longer put windows condvars in a box.
Windows condition variables are movable (while not borrowed) according
to their documentation.
2020-10-02 09:47:08 +02:00
Mara Bos
ec69a858e4 No longer put wasm condvars in a box.
These condvars are just an AtomicUsize, so can be moved without
problems.
2020-10-02 09:47:08 +02:00
Mara Bos
7f56a35411 No longer put condvars on the 'unsupported' platform in a box.
These condvars are unsupported and implemented as a ZST, so can be moved
without problems.
2020-10-02 09:47:08 +02:00
Mara Bos
5769a46788 No longer put cloudabi condvars in a box.
Cloudabi condvars may be moved safely.
2020-10-02 09:47:08 +02:00
Mara Bos
b181f5a923 Make it possible to have unboxed condvars on specific platforms.
This commit keeps all condvars boxed on all platforms, but makes it
trivial to remove the box on some platforms later.
2020-10-02 09:47:08 +02:00
Mara Bos
dc81cbdcb1 No longer put windows mutexes in a box.
Windows SRW locks are movable (while not borrowed) according to their
documentation.
2020-10-02 09:47:08 +02:00
Mara Bos
4f1353e54f No longer put wasm mutexes in a box.
These mutexes are just an AtomicUsize, so can be moved without
problems.
2020-10-02 09:47:08 +02:00
Mara Bos
2f0386771d No longer put mutexes on the 'unsupported' platform in a box.
These mutexes are just a bool (in a cell), so can be moved without
problems.
2020-10-02 09:47:08 +02:00
Mara Bos
def5188ca8 No longer put cloudabi mutexes in a box.
Cloudabi mutexes may be moved safely.
2020-10-02 09:47:08 +02:00
Mara Bos
58deb7001d Make it possible to have unboxed mutexes on specific platforms.
This commit keeps all mutexes boxed on all platforms, but makes it
trivial to remove the box on some platforms later.
2020-10-02 09:47:08 +02:00
Mara Bos
a8c2d4fc3d Move boxing and mutex checking logic of condvar into sys_common. 2020-10-02 09:47:08 +02:00
Yuki Okushi
5a7218009e
Rollup merge of #77429 - WaffleLapkin:doc_link_default_hasher_new, r=jyn514
Link `new` method in `DefautHasher`s doc

FIXME referenced #56922 which was resolved

r? @jyn514
2020-10-02 08:25:27 +09:00
Yuki Okushi
55d0959328
Rollup merge of #77362 - RReverser:patch-1, r=dtolnay
Fix is_absolute on WASI

WASI does not match `cfg(unix)`, but its paths are Unix-like (`/some/path`) and don't have Windows-like prefixes.

Without this change, `is_absolute` for any paths, including `/some/path`, was returning `false`on a WASI target, which is obviously not true and undesirable.
2020-10-02 08:25:19 +09:00
Yuki Okushi
1c4a5f8d1e
Rollup merge of #77147 - fusion-engineering-forks:static-mutex, r=dtolnay
Split sys_common::Mutex in StaticMutex and MovableMutex.

The (unsafe) `Mutex` from `sys_common` had a rather complicated interface. You were supposed to call `init()` manually, unless you could guarantee it was neither moved nor used reentrantly.

Calling `destroy()` was also optional, although it was unclear if 1) resources might be leaked or not, and 2) if `destroy()` should only be called when `init()` was called.

This allowed for a number of interesting (confusing?) different ways to use this `Mutex`, all captured in a single type.

In practice, this type was only ever used in two ways:

1. As a static variable. In this case, neither `init()` nor `destroy()` are called. The variable is never moved, and it is never used reentrantly. It is only ever locked using the `LockGuard`, never with `raw_lock`.

2. As a `Box`ed variable. In this case, both `init()` and `destroy()` are called, it will be moved and possibly used reentrantly.

No other combinations are used anywhere in `std`.

This change simplifies things by splitting this `Mutex` type into two types matching the two use cases: `StaticMutex` and `MovableMutex`.

The interface of both new types is now both safer and simpler. The first one does not call nor expose `init`/`destroy`, and the second one calls those automatically in its `new()` and `Drop` functions. Also, the locking functions of `MovableMutex` are no longer unsafe.

---

This will also make it easier to conditionally box mutexes later, by moving that decision into sys/sys_common. Some of the mutex implementations (at least those of Wasm and 'sys/unsupported') are safe to move, so wouldn't need a box. ~~(But that's blocked on  #76932 for now.)~~ (See #77380.)
2020-10-02 08:25:15 +09:00
Yuki Okushi
00b3450bbc
Rollup merge of #76979 - fusion-engineering-forks:windows-fallback-check, r=dtolnay
Improve std::sys::windows::compat

Improves the compat_fn macro in sys::windows, which is used for conditionally loading APIs that might not be available.

- The module (dll) name can now be any string, not just an ident. (Not all Windows api modules are valid Rust identifiers. E.g. `WaitOnAddress` comes from `API-MS-Win-Core-Synch-l1-2-0.dll`.)
- Adds `FuncName::is_available()` for checking if a function is really available without having to do a duplicate lookup.
- Add comment explaining the lack of locking.
- Use `$_:block` to simplify the macro_rules.
- Apply `allow(unused_variables)` only to the fallback instead of everything.

---

The second point (`is_available()`) simplifies code that needs to pick an implementation depening on what is available, like `sys/windows/mutex.rs`. Before this change, it'd do its own lookup and keep its own `AtomicUsize` to track the result. Now it can just use `c::AcquireSRWLockExclusive::is_available()` directly.

This will also be useful when park/unpark/CondVar/etc. get improved implementations (e.g. from parking_lot or something else), as the best APIs for those are not available before Windows 8.
2020-10-02 08:25:11 +09:00
Waffle
1c2c336dbc Link new method in DefautHashers doc 2020-10-02 00:30:19 +03:00
bors
2ad6187ce5 Auto merge of #76969 - withoutboats:rawfd-refexive-traits, r=dtolnay
Make RawFd implement the RawFd traits

This PR makes `RawFd` implement `AsRawFd`, `IntoRawFd` and `FromRawFd`, so it can be passed to interfaces that use one of those traits as a bound.
2020-10-01 15:39:33 +00:00
Mara Bos
63b6007d5b Work around potential merging/duplication issues in sys/windows/compat. 2020-10-01 16:52:11 +02:00
Mara Bos
09cbaf4367 Formatting. 2020-10-01 16:08:58 +02:00
Mara Bos
93310efdbe Use AcquireSRWLockExclusive::is_available() instead of an extra lookup. 2020-10-01 16:08:58 +02:00
Mara Bos
8b2bdfd453 Improve std::sys::windows::compat.
- Module name can now be any string, not just an ident.
  (Not all Windows api modules are valid Rust identifiers.)
- Adds c::FuncName::is_available() for checking if a function is really
  available without having to do a duplicate lookup.
- Add comment explaining the lack of locking.
- Use `$_:block` to simplify the macro_rules.
- Apply allow(unused_variables) only to the fallback instead of
  everything.
2020-10-01 16:08:57 +02:00
bors
782013564e Auto merge of #76919 - fusion-engineering-forks:thread-parker, r=dtolnay
Use futex-based thread::park/unpark on Linux.

This moves the parking/unparking logic out of `thread/mod.rs` into a module named `thread_parker` in `sys_common`. The current implementation is moved to `sys_common/thread_parker/generic.rs` and the new implementation using futexes is added in `sys_common/thread_parker/futex.rs`.
2020-10-01 13:21:34 +00:00
Dylan DPC
70740b1b82
Rollup merge of #77315 - exrook:rename-allocerror, r=joshtriplett
Rename AllocErr to AllocError

Implements rust-lang/wg-allocators#57
2020-10-01 02:13:39 +02:00
Tomasz Miąsko
9845e7d5fb Use posix_spawn on musl targets
The posix_spawn had been available in a form suitable for use in a
Command implementation since musl 0.9.12. Use it in a preference to a
fork when possible, to benefit from CLONE_VM|CLONE_VFORK used there.
2020-10-01 00:00:00 +00:00
Jonas Schievink
c46f5784a6
Rollup merge of #77328 - hyd-dev:assert-to-rtassert, r=Amanieu
Use `rtassert!` instead of `assert!` from the child process after fork() in std::sys::unix::process::Command::spawn()

As discussed in #73894, `assert!` panics on failure, which is not signal-safe, and `rtassert!` is a suitable replacement.

Fixes #73894.

r? @Amanieu @cuviper @joshtriplett
2020-09-30 20:56:15 +02:00
Jonas Schievink
87387fd23e
Rollup merge of #77284 - josephlr:mem, r=Mark-Simulacrum
library: Forward compiler-builtins "mem" feature

This fixes https://github.com/rust-lang/wg-cargo-std-aware/issues/53

Now users will be able to do:
```
cargo build -Zbuild-std=core -Zbuild-std-features=compiler-builtins-mem
```
and correctly get the Rust implemenations for `memcpy` and friends.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-09-30 20:56:10 +02:00
Ingvar Stepanyan
494d6e514b
Fix is_absolute on WASI
WASI does not match `cfg(unix)`, but its paths are Unix-like (`/some/path`) and don't have Windows-like prefixes.

Without this change, `is_absolute` for paths like `/some/path` was returning `false`on a WASI target, which is obviously not true and undesirable.
2020-09-30 13:12:25 +01:00
bors
c0127e4dbf Auto merge of #77292 - lzutao:std_asm, r=Amanieu
Prefer asm! in std - all in sgx module

Similar to the change in #76669 but all `llvm_asm!` is gate in x86/x86_64 target.
Godbolt:
- https://rust.godbolt.org/z/h7nG1h
- https://rust.godbolt.org/z/xx39hW
2020-09-30 05:27:16 +00:00
hyd-dev
a2526b416f
Use rtassert! instead of assert! from the child process after fork() in std::sys::unix::process::Command::spawn()
`assert!` panics on failure, which is not signal-safe.
2020-09-29 15:16:46 +08:00
Jacob Hughes
5829560a68 Rename AllocErr to AllocError 2020-09-28 14:51:03 -04:00
Ralf Jung
a966f54bbb
Rollup merge of #77288 - RalfJung:miri-macos, r=Amanieu
fix building libstd for Miri on macOS

Fixes a Miri regression introduced by https://github.com/rust-lang/rust/pull/75295
Cc @tmiasko @Amanieu
2020-09-28 18:39:47 +02:00
Ralf Jung
85a59d40f1
Rollup merge of #77170 - ecstatic-morse:const-fn-ptr, r=oli-obk
Remove `#[rustc_allow_const_fn_ptr]` and add `#![feature(const_fn_fn_ptr_basics)]`

`rustc_allow_const_fn_ptr` was a hack to work around the lack of an escape hatch for the "min `const fn`" checks in const-stable functions. Now that we have co-opted `allow_internal_unstable` for this purpose, we no longer need a bespoke attribute.

Now this functionality is gated under `const_fn_fn_ptr_basics` (how concise!), and `#[allow_internal_unstable(const_fn_fn_ptr_basics)]` replaces `#[rustc_allow_const_fn_ptr]`. `const_fn_fn_ptr_basics` allows function pointer types to appear in the arguments and locals of a `const fn` as well as function pointer casts to be performed inside a `const fn`. Both of these were allowed in constants and statics already. Notably, this does **not** allow users to invoke function pointers in a const context. Presumably, we will use a nicer name for that (`const_fn_ptr`?).

r? @oli-obk
2020-09-28 18:39:44 +02:00
Ralf Jung
734c57d45c
Rollup merge of #76454 - poliorcetics:ui-to-unit-test-1, r=matklad
UI to unit test for those using Cell/RefCell/UnsafeCell

Helps with #76268.

I'm working on all files using `Cell` and moving them to unit tests when possible.

r? @matklad
2020-09-28 18:39:39 +02:00
Lzu Tao
d4772014d9 Prefer asm! in std - all in sgx module 2020-09-28 13:08:34 +00:00
bors
1d5a865b2f Auto merge of #77282 - glaubitz:sparc-linux, r=nagisa
Add missing definitions required by the sparc-unknown-linux-gnu target

This PR adds a few missing definitions required by sparc-unknown-linux-target which were discovered during build tests.
2020-09-28 10:37:41 +00:00
Ralf Jung
dc8414b607 fix building libstd for Miri on macOS 2020-09-28 10:32:05 +02:00
Joe Richey
37f795697c
libary: Forward compiler-builtins "mem" feature
This fixes https://github.com/rust-lang/wg-cargo-std-aware/issues/53

Now users will be able to do:
```
cargo build -Zbuild-std=core -Zbuild-std-features=compiler-builtins-mem
```
and correctly get the Rust implemenations for `memcpy` and friends.

Signed-off-by: Joe Richey <joerichey@google.com>
2020-09-27 20:31:06 -07:00
John Paul Adrian Glaubitz
d25b0364e1 library/std: Set OS raw type definitions for sparc-unknown-linux-gnu 2020-09-28 00:39:57 +02:00
John Paul Adrian Glaubitz
d9de08d65c library/std/sys_common: Define MIN_ALIGN for sparc-unknown-linux-gnu 2020-09-28 00:39:57 +02:00
Tomasz Miąsko
7d98d2207a Reopen standard streams when they are closed on Unix
The syscalls returning a new file descriptors generally use
lowest-numbered file descriptor not currently opened, without any
exceptions for those corresponding to the standard streams.

Previously when any of standard streams has been closed before starting
the application, operations on std::io::{stderr,stdin,stdout} objects
were likely to operate on other logically unrelated file resources
opened afterwards.

Avoid the issue by reopening the standard streams when they are closed.
2020-09-27 22:55:43 +02:00
Dylan MacKenzie
1ff143191c Add a feature gate for basic function pointer use in const fn 2020-09-27 10:46:41 -07:00
Mara Bos
de597fca40 Optimize set_{panic,print}(None). 2020-09-27 16:04:25 +02:00
Mara Bos
ed3ead013f Relax memory ordering of LOCAL_STREAMS and document it. 2020-09-27 16:04:25 +02:00
Mara Bos
07fd17f701 Only use LOCAL_{STDOUT,STDERR} when set_{print/panic} is used.
The thread local LOCAL_STDOUT and LOCAL_STDERR are only used by the test
crate to capture output from tests when running them in the same process
in differen threads. However, every program will check these variables
on every print, even outside of testing.

This involves allocating a thread local key, and registering a thread
local destructor. This can be somewhat expensive.

This change keeps a global flag (LOCAL_STREAMS) which will be set to
true when either of these local streams is used. (So, effectively only
in test and benchmark runs.) When this flag is off, these thread locals
are not even looked at and therefore will not be initialized on the
first output on every thread, which also means no thread local
destructors will be registered.
2020-09-27 16:04:25 +02:00
Mara Bos
0b73fd7105 Move thread parker to sys_common. 2020-09-27 12:28:58 +02:00
Mara Bos
4301b5c1cc Add notes about memory ordering to futex parker implementation. 2020-09-27 11:56:43 +02:00
Mara Bos
485f882d77 Check conversion from Duration to timespec in futex_wait. 2020-09-27 11:56:43 +02:00
Mara Bos
2cf0f64722 Move linux-specific futex code into sys module. 2020-09-27 11:56:43 +02:00
Mara Bos
568d9696e9 Fix warning. 2020-09-27 11:56:43 +02:00
Mara Bos
f18f93d44c Mark unpark() as #[inline]. 2020-09-27 11:56:43 +02:00
Mara Bos
ec13df4ec4 Add fast futex-based thread parker for Linux. 2020-09-27 11:56:42 +02:00
Mara Bos
1464fc3a0c Move thread parker to a separate module. 2020-09-27 11:56:42 +02:00
Mara Bos
6f6336b4a1 Split sys_common::Mutex in StaticMutex and MovableMutex.
The (unsafe) Mutex from sys_common had a rather complicated interface.
You were supposed to call init() manually, unless you could guarantee it
was neither moved nor used reentrantly.

Calling `destroy()` was also optional, although it was unclear if 1)
resources might be leaked or not, and 2) if destroy() should only be
called when `init()` was called.

This allowed for a number of interesting (confusing?) different ways to
use this Mutex, all captured in a single type.

In practice, this type was only ever used in two ways:

1. As a static variable. In this case, neither init() nor destroy() are
   called. The variable is never moved, and it is never used
   reentrantly. It is only ever locked using the LockGuard, never with
   raw_lock.

2. As a Boxed variable. In this case, both init() and destroy() are
   called, it will be moved and possibly used reentrantly.

No other combinations are used anywhere in `std`.

This change simplifies things by splitting this Mutex type into
two types matching the two use cases: StaticMutex and MovableMutex.

The interface of both new types is now both safer and simpler. The first
one does not call nor expose init/destroy, and the second one calls
those automatically in its new() and Drop functions. Also, the locking
functions of MovableMutex are no longer unsafe.
2020-09-27 10:05:56 +02:00
bors
c9e5e6a53a Auto merge of #77154 - fusion-engineering-forks:lazy-stdio, r=dtolnay
Remove std::io::lazy::Lazy in favour of SyncOnceCell

The (internal) std::io::lazy::Lazy was used to lazily initialize the stdout and stdin buffers (and mutexes). It uses atexit() to register a destructor to flush the streams on exit, and mark the streams as 'closed'. Using the stream afterwards would result in a panic.

Stdout uses a LineWriter which contains a BufWriter that will flush the buffer on drop. This one is important to be executed during shutdown, to make sure no buffered output is lost. It also forbids access to stdout afterwards, since the buffer is already flushed and gone.

Stdin uses a BufReader, which does not implement Drop. It simply forgets any previously read data that was not read from the buffer yet. This means that in the case of stdin, the atexit() function's only effect is making stdin inaccessible to the program, such that later accesses result in a panic. This is uncessary, as it'd have been safe to access stdin during shutdown of the program.

---

This change removes the entire io::lazy module in favour of SyncOnceCell. SyncOnceCell's fast path is much faster (a single atomic operation) than locking a sys_common::Mutex on every access like Lazy did.

However, SyncOnceCell does not use atexit() to drop the contained object during shutdown.

As noted above, this is not a problem for stdin. It simply means stdin is now usable during shutdown.

The atexit() call for stdout is moved to the stdio module. Unlike the now-removed Lazy struct, SyncOnceCell does not have a 'gone and unusable' state that panics. Instead of adding this again, this simply replaces the buffer with one with zero capacity. This effectively flushes the old buffer *and* makes any writes afterwards pass through directly without touching a buffer, making print!() available during shutdown without panicking.

---

In addition, because the contents of the SyncOnceCell are no longer dropped, we can now use `&'static` instead of `Arc` in `Stdout` and `Stdin`. This also saves two levels of indirection in `stdin()` and `stdout()`, since Lazy effectively stored a `Box<Arc<T>>`, and SyncOnceCell stores the `T` directly.
2020-09-27 04:50:46 +00:00
Eric Huss
c297e20e03 Add accessors to Command. 2020-09-26 18:58:38 -07:00
Jonas Schievink
9ab95c36e2
Rollup merge of #76917 - GuillaumeGomez:map-missing-code-examples, r=Dylan-DPC
Add missing code examples on HashMap types

r? @Dylan-DPC
2020-09-27 01:53:13 +02:00
Ralf Jung
0a19836a81
Rollup merge of #77181 - GuillaumeGomez:add-pointer-alias, r=jyn514,pickfire
Add doc alias for pointer primitive
2020-09-26 12:58:28 +02:00
Ralf Jung
3b544e73ae
Rollup merge of #77122 - ecstatic-morse:const-fn-arithmetic, r=RalfJung,oli-obk
Add `#![feature(const_fn_floating_point_arithmetic)]`

cc #76618

This is a template for splitting up `const_fn` into granular feature gates. I think this will make it easier, both for us and for users, to track stabilization of each individual feature. We don't *have* to do this, however. We could also keep stabilizing things out from under `const_fn`.

cc @rust-lang/wg-const-eval
r? @oli-obk
2020-09-26 12:58:20 +02:00
Guillaume Gomez
21ee1716ee Add doc alias for pointer primitive 2020-09-26 11:21:24 +02:00
bors
fd15e6180d Auto merge of #70743 - oli-obk:eager_const_to_pat_conversion, r=eddyb
Fully destructure constants into patterns

r? `@varkor`

as discussed in https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/constants.20in.20patterns/near/192789924

we should probably crater it once reviewed
2020-09-26 06:44:28 +00:00
bors
9e1c436178 Auto merge of #74225 - poliorcetics:std-thread-unsafe-op-in-unsafe-fn, r=joshtriplett
Std/thread: deny unsafe op in unsafe fn

Partial fix of #73904.

This encloses `unsafe` operations in `unsafe fn` in `libstd/thread`.
`@rustbot` modify labels: F-unsafe-block-in-unsafe-fn
2020-09-26 03:54:00 +00:00
Alexis Bourget
a61b9638bb review: fix nits and move panic safety tests to the correct place 2020-09-25 23:10:24 +02:00
Guillaume Gomez
980e1ff40f Add missing examples for Fd traits 2020-09-25 21:20:42 +02:00