Commit graph

591 commits

Author SHA1 Message Date
Yuki Okushi
050eb4d7e4
Rollup merge of #77971 - jyn514:broken-intra-doc-links, r=mark-simulacrum
Deny broken intra-doc links in linkchecker

Since rustdoc isn't warning about these links, check for them manually.

This also fixes the broken links that popped up from the lint.
2020-10-17 05:36:49 +09:00
Yuki Okushi
9abf81afa8
Rollup merge of #77900 - Thomasdezeeuw:fdatasync, r=dtolnay
Use fdatasync for File::sync_data on more OSes

Add support for the following OSes:
 * Android
 * FreeBSD: https://www.freebsd.org/cgi/man.cgi?query=fdatasync&sektion=2
 * OpenBSD: https://man.openbsd.org/OpenBSD-5.8/fsync.2
 * NetBSD: https://man.netbsd.org/fdatasync.2
 * illumos: https://illumos.org/man/3c/fdatasync
2020-10-17 05:36:45 +09:00
Yuki Okushi
3356ad7c26
Rollup merge of #77547 - RalfJung:stable-union-drop, r=matthewjasper
stabilize union with 'ManuallyDrop' fields and 'impl Drop for Union'

As [discussed by @SimonSapin and @withoutboats](https://github.com/rust-lang/rust/issues/55149#issuecomment-634692020), this PR proposes to stabilize parts of the `untagged_union` feature gate:

* It will be possible to have a union with field type `ManuallyDrop<T>` for any `T`.
* While at it I propose we also stabilize `impl Drop for Union`; to my knowledge, there are no open concerns around this feature.

In the RFC discussion, we also talked about allowing `&mut T` as another non-`Copy` non-dropping type, but that felt to me like an overly specific exception so I figured we'd wait if there is actually any use for such a special case.

Some things remain unstable and still require the `untagged_union` feature gate:
* Union with fields that do not drop, are not `Copy`, and are not `ManuallyDrop<_>`. The reason to not stabilize this is to avoid semver concerns around libraries adding `Drop` implementations later. (This is already not fully semver compatible as, to my knowledge, the borrow checker will exploit the non-dropping nature of any type, but it seems prudent to avoid further increasing the amount of trouble adding an `impl Drop` can cause.)

Due to this, quite a few tests still need the `untagged_union` feature, but I think the ones where I could remove the feature flag provide good test coverage for the stable part.

Cc @rust-lang/lang
2020-10-17 05:36:38 +09:00
Ralf Jung
defcd7ff47 stop relying on feature(untagged_unions) in stdlib 2020-10-16 11:33:35 +02:00
Mara Bos
0f0257be10 Take some of sys/vxworks/process/* from sys/unix instead. 2020-10-16 06:22:05 +02:00
Mara Bos
408db0da85 Take sys/vxworks/{os,path,pipe} from sys/unix instead. 2020-10-16 06:22:00 +02:00
Mara Bos
71bb1dc2a0 Take sys/vxworks/{fd,fs,io} from sys/unix instead. 2020-10-16 06:19:00 +02:00
Mara Bos
3f196dc137 Take sys/vxworks/cmath from sys/unix instead. 2020-10-16 06:19:00 +02:00
Mara Bos
ba483c51df Take sys/vxworks/args from sys/unix instead. 2020-10-16 06:19:00 +02:00
Mara Bos
08bcaac091 Take sys/vxworks/memchar from sys/unix instead. 2020-10-16 06:19:00 +02:00
Mara Bos
dce405ae3d Take sys/vxworks/net from sys/unix instead. 2020-10-16 06:19:00 +02:00
Mara Bos
a489c33beb Take sys/vxworks/ext/* from sys/unix instead. 2020-10-16 06:19:00 +02:00
Mara Bos
c909ff9577 Add weak macro to vxworks. 2020-10-16 06:19:00 +02:00
Mara Bos
66c9b04e94 Take sys/vxworks/alloc from sys/unix instead. 2020-10-16 06:19:00 +02:00
Mara Bos
678d078950 Take sys/vxworks/thread_local_key from sys/unix instead. 2020-10-16 06:19:00 +02:00
Mara Bos
4853a6e78e Take sys/vxworks/stdio from sys/unix instead. 2020-10-16 06:19:00 +02:00
Mara Bos
5d526f6eee Take sys/vxworks/thread from sys/unix instead. 2020-10-16 06:19:00 +02:00
Mara Bos
c8628f43bf Take sys/vxworks/stack_overflow from sys/unix instead. 2020-10-16 06:18:59 +02:00
Mara Bos
d1947628b5 Take sys/vxworks/time from sys/unix instead. 2020-10-16 06:18:59 +02:00
Mara Bos
f875c8be5d Take sys/vxworks/rwlock from sys/unix instead. 2020-10-16 06:18:59 +02:00
Mara Bos
f3f30c7132 Take sys/vxworks/condvar from sys/unix instead. 2020-10-16 06:18:59 +02:00
Mara Bos
b8dcd2fbce Take sys/vxworks/mutex from sys/unix instead. 2020-10-16 06:18:59 +02:00
Joshua Nelson
65835d1059 Deny broken intra-doc links in linkchecker
Since rustdoc isn't warning about these links, check for them manually.
2020-10-15 20:22:16 -04:00
Dylan DPC
9b8c0eb107
Rollup merge of #77657 - fusion-engineering-forks:cleanup-cloudabi-sync, r=dtolnay
Cleanup cloudabi mutexes and condvars

This gets rid of lots of unnecessary unsafety.

All the AtomicU32s were wrapped in UnsafeCell or UnsafeCell<MaybeUninit>, and raw pointers were used to get to the AtomicU32 inside. This change cleans that up by using AtomicU32 directly.

Also replaces a UnsafeCell<u32> by a safer Cell<u32>.

@rustbot modify labels: +C-cleanup
2020-10-16 02:10:17 +02:00
Dylan DPC
b183ef2068
Rollup merge of #77648 - fusion-engineering-forks:static-mutex, r=dtolnay
Static mutex is static

StaticMutex is only ever used with as a static (as the name already suggests). So it doesn't have to be generic over a lifetime, but can simply assume 'static.

This 'static lifetime guarantees the object is never moved, so this is no longer a manually checked requirement for unsafe calls to lock().

@rustbot modify labels: +T-libs +A-concurrency +C-cleanup
2020-10-16 02:10:15 +02:00
Dylan DPC
085399f481
Rollup merge of #77646 - fusion-engineering-forks:use-static-mutex, r=dtolnay
For backtrace, use StaticMutex instead of a raw sys Mutex.

The code used the very unsafe `sys::mutex::Mutex` directly, and built its own unlock-on-drop wrapper around it. The StaticMutex wrapper already provides that and is easier to use safely.

@rustbot modify labels: +T-libs +C-cleanup
2020-10-16 02:10:13 +02:00
Dylan DPC
dcf972a2be
Rollup merge of #77619 - fusion-engineering-forks:wasm-parker, r=dtolnay
Use futex-based thread-parker for Wasm32.

This uses the existing `sys_common/thread_parker/futex.rs` futex-based thread parker (that was already used for Linux) for wasm32 as well (if the wasm32 atomics target feature is enabled, which is not the case by default).

Wasm32 provides the basic futex operations as instructions: https://webassembly.github.io/threads/syntax/instructions.html

These are now exposed from `sys::futex::{futex_wait, futex_wake}`, just like on Linux. So, `thread_parker/futex.rs` stays completely unmodified.
2020-10-16 02:10:11 +02:00
Dylan DPC
5acb7f198f
Rollup merge of #76084 - Lucretiel:split-buffered, r=dtolnay
Refactor io/buffered.rs into submodules

This pull request splits `BufWriter`, `BufReader`, `LineWriter`, and `LineWriterShim` (along with their associated tests) into separate submodules. It contains no functional changes. This change is being made in anticipation of adding another type of buffered writer which can be switched between line- and block-buffering mode.

Part of a series of pull requests resolving #60673.
2020-10-16 02:10:04 +02:00
Matthew Kraai
f2a237a935 Fix link to foreign calling conventions 2020-10-15 00:57:22 -07:00
Mara Bos
44a2af32cc Remove lifetime from StaticMutex and assume 'static.
StaticMutex is only ever used with as a static (as the name already
suggests). So it doesn't have to be generic over a lifetime, but can
simply assume 'static.

This 'static lifetime guarantees the object is never moved, so this is
no longer a manually checked requirement for unsafe calls to lock().
2020-10-14 09:52:03 +02:00
Mara Bos
58756573fc Fix comment about non-reentrant StaticMutex::lock().
The comment said it's UB to call lock() while it is locked. That'd be
quite a useless Mutex. :) It was supposed to say 'locked by the same
thread', not just 'locked'.
2020-10-14 09:50:47 +02:00
Dylan DPC
ed34f82cbc
Rollup merge of #77870 - camelid:intra-doc-super, r=jyn514
Use intra-doc links for links to module-level docs

r? @jyn514
2020-10-14 02:30:46 +02:00
Yuki Okushi
cc5a1aad4e
Rollup merge of #77722 - fusion-engineering-forks:safe-unsupported-locks, r=Mark-Simulacrum
Remove unsafety from sys/unsupported and add deny(unsafe_op_in_unsafe_fn).

Replacing `UnsafeCell`s by a `Cell`s simplifies things and makes the mutex and rwlock implementations safe. Other than that, only unsafety in strlen() contained unsafe code.

@rustbot modify labels: +F-unsafe-block-in-unsafe-fn +C-cleanup
2020-10-14 06:02:21 +09:00
Yuki Okushi
7de5fe76f2
Rollup merge of #77719 - fusion-engineering-forks:const-new-mutex-attr-cleanup, r=Mark-Simulacrum
Remove unnecessary rustc_const_stable attributes.

These attributes were added in https://github.com/rust-lang/rust/pull/74033#discussion_r450593156 because of [std::io::lazy::Lazy::new](0c03aee8b8/src/libstd/io/lazy.rs (L21-L23)). But [std::io::lazy::Lazy is gone now](https://github.com/rust-lang/rust/pull/77154), so this can be cleaned up.

@rustbot modify labels: +T-libs +C-cleanup
2020-10-14 06:02:19 +09:00
Mara Bos
af414dc274 Deny unsafe_op_in_unsafe_fn for unsupported/common.rs through sys/wasm too. 2020-10-13 18:56:27 +02:00
Thomas de Zeeuw
8c0c7ec4ec Use fdatasync for File::sync_data on more OSes
Add support for the following OSes:
 * Android
 * FreeBSD: https://www.freebsd.org/cgi/man.cgi?query=fdatasync&sektion=2
 * OpenBSD: https://man.openbsd.org/OpenBSD-5.8/fsync.2
 * NetBSD: https://man.netbsd.org/fdatasync.2
 * illumos: https://illumos.org/man/3c/fdatasync
2020-10-13 15:57:31 +02:00
Mara Bos
b26aa5d973 Add note about using cells in the locks on the 'unsupported' platform. 2020-10-13 15:29:38 +02:00
Camelid
95221b4eb5 Use intra-doc links for links to module-level docs 2020-10-12 19:22:47 -07:00
Yuki Okushi
ad6e179060
Rollup merge of #77724 - sunfishcode:stdinlock-asrawfd, r=alexcrichton
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.

r? @alexcrichton
2020-10-13 04:07:54 +09:00
bors
bc74dd711f Auto merge of #77727 - thomcc:mach-info-order, r=Amanieu
Avoid SeqCst or static mut in mach_timebase_info and QueryPerformanceFrequency caches

This patch went through a couple iterations but the end result is replacing a pattern where an `AtomicUsize` (updated with many SeqCst ops) guards a `static mut` with a single `AtomicU64` that is known to use 0 as a value indicating that it is not initialized.

The code in both places exists to cache values used in the conversion of Instants to Durations on macOS, iOS, and Windows.

I have no numbers to prove that this improves performance (It seems a little futile to benchmark something like this), but it's much simpler, safer, and in practice we'd expect it to be faster everywhere where Relaxed operations on AtomicU64 are cheaper than SeqCst operations on AtomicUsize, which is a lot of places.

Anyway, it also removes a bunch of unsafe code and greatly simplifies the logic, so IMO that alone would be worth it unless it was a regression.

If you want to take a look at the assembly output though, see https://godbolt.org/z/rbr6vn for x86_64, https://godbolt.org/z/cqcbqv for aarch64 (Note that this just the output of the mac side, but i'd expect the windows part to be the same and don't feel like doing another godbolt for it). There are several versions of this function in the godbolt:

- `info_new`: version in the current patch
- `info_less_new`: version in initial PR
- `info_original`: version currently in the tree
- `info_orig_but_better_orderings`: a version that just tries to change the original code's orderings from SeqCst to the (probably) minimal orderings required for soundness/correctness.

The biggest concern I have here is if we can use AtomicU64, or if there are targets that dont have it that this code supports. AFAICT: no. (If that changes in the future, it's easy enough to do something different for them)

r? `@Amanieu` because he caught a couple issues last time I tried to do a patch reducing orderings 😅

---

<details>
<summary>I rewrote this whole message so the original is inside here</summary>

I happened to notice the code we use for caching the result of mach_timebase_info uses SeqCst exclusively.

However, thinking a little more, it's actually pretty easy to avoid the static mut by packing the timebase info into an AtomicU64.

This entirely avoids needing to do the compare_exchange. The AtomicU64 can be read/written using Relaxed ops, which on current macos/ios platforms (x86_64/aarch64) have no overhead compared to direct loads/stores. This simplifies the code and makes it a lot safer too.

I have no numbers to prove that this improves performance (It seems a little futile to benchmark something like this), although it should do that on both targets it applies to.

That said, it also removes a bunch of unsafe code and simplifies the logic (arguably at least — there are only two states now, initialized or not), so I think it's a net win even without concrete numbers.

If you want to take a look at the assembly output though, see below. It has the new version, the original, and a version of the original with lower Orderings (which is still worse than the version in this PR)

- godbolt.org/z/obfqf9 x86_64-apple-darwin

- godbolt.org/z/Wz5cWc aarch64-unknown-linux-gnu (godbolt can't do aarch64-apple-ios but that doesn't matter here)

A different (and more efficient) option than this would be to just use the AtomicU64 and use the knowledge that after initialization the denominator should be nonzero... That felt like it's relying on too many things I'm not confident in, so I didn't want to do that.
</details>
2020-10-11 14:06:04 +00:00
Yuki Okushi
82c538c619
Rollup merge of #77777 - cuviper:doc-stat, r=jonas-schievink
doc: disambiguate stat in MetadataExt::as_raw_stat

A few architectures in `os::linux::raw` import `libc::stat`, rather than
defining that type directly. However, that also imports the _function_
called `stat`, which makes this doc link ambiguous:

    error: `crate::os::linux::raw::stat` is both a struct and a function
      --> library/std/src/os/linux/fs.rs:21:19
       |
    21 |     /// [`stat`]: crate::os::linux::raw::stat
       |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ambiguous link
       |
       = note: `-D broken-intra-doc-links` implied by `-D warnings`
    help: to link to the struct, prefix with the item type
       |
    21 |     /// [`stat`]: struct@crate::os::linux::raw::stat
       |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    help: to link to the function, add parentheses
       |
    21 |     /// [`stat`]: crate::os::linux::raw::stat()
       |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We want the `struct`, so it's now prefixed accordingly.
2020-10-11 03:19:18 +09:00
Yuki Okushi
83685880b6
Rollup merge of #77748 - mati865:dead-code-cleanup, r=petrochenkov
Dead code cleanup in windows-gnu std

Closes https://github.com/rust-lang/rust/issues/77622

This is the only leftover I could find.
2020-10-11 03:19:12 +09:00
Yuki Okushi
1b134430ef
Rollup merge of #77195 - follower:patch-2, r=jyn514
Link to documentation-specific guidelines.

Changed contribution information URL because it's not obvious how to get from the current URL to the documentation-specific content.

The current URL points to this "Getting Started" page, which contains nothing specific about documentation[*] and instead launches into how to *build* `rustc` which is not a strict prerequisite for contributing documentation fixes:

 * https://rustc-dev-guide.rust-lang.org/getting-started.html

[*] The most specific content is a "Writing documentation" bullet point which is not itself a link to anything (I guess a patch for that might be helpful too).

### Why?

Making this change will make it easier for people who wish to make small "drive by" documentation fixes (and read contribution guidelines ;) ) which I find are often how I start contributing to a project. (Exhibit A: https://github.com/rust-lang/rust/pull/77050 :) )

### Background

My impression is the change of content linked is an unintentional change due to a couple of other changes:

 * Originally, the link pointed to  `contributing.md` which started with a "table of contents" linking to each section. But the content in `contributing.md` was removed and replaced with a link to the "Getting Started" section here:

    * 3f6928f1f6 (diff-6a3371457528722a734f3c51d9238c13L1)

   But the changed link doesn't actually point to the equivalent content, which is now located here:

    * https://rustc-dev-guide.rust-lang.org/contributing.html

   (If the "Guide to Rustc Development" is now considered the canonical location of "How to Contribute" content it might be a good idea to merge some of the "Contributing" Introduction section into the "Getting Started" section.)

 * This was then compounded by changing the link from `contributing.md` to  `contributing.html` here:

     * https://github.com/rust-lang/rust/pull/74037/files#diff-242481015141f373dcb178e93cffa850L88

    In order to even find the new location of the previous `contributing.md` content I ended up needing to do a GitHub search of the `rust-lang` org for the phrase "Documentation improvements are very welcome". :D
2020-10-11 03:19:05 +09:00
bors
7477d445c8 Auto merge of #77717 - tmiasko:posix-spawn-error-check, r=cuviper
Fix error checking in posix_spawn implementation of Command

* Check for errors returned from posix_spawn*_init functions
* Check for non-zero return value from posix_spawn functions
2020-10-10 10:59:20 +00:00
Josh Stone
f200c1e7af doc: disambiguate stat in MetadataExt::as_raw_stat
A few architectures in `os::linux::raw` import `libc::stat`, rather than
defining that type directly. However, that also imports the _function_
called `stat`, which makes this doc link ambiguous:

    error: `crate::os::linux::raw::stat` is both a struct and a function
      --> library/std/src/os/linux/fs.rs:21:19
       |
    21 |     /// [`stat`]: crate::os::linux::raw::stat
       |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^ ambiguous link
       |
       = note: `-D broken-intra-doc-links` implied by `-D warnings`
    help: to link to the struct, prefix with the item type
       |
    21 |     /// [`stat`]: struct@crate::os::linux::raw::stat
       |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    help: to link to the function, add parentheses
       |
    21 |     /// [`stat`]: crate::os::linux::raw::stat()
       |                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

We want the `struct`, so it's now prefixed accordingly.
2020-10-09 20:12:26 -07:00
Josh Stone
1d06b07765
simplify the cfg in ReadDir construction
Co-authored-by: David Tolnay <dtolnay@gmail.com>
2020-10-09 10:54:50 -07:00
Josh Stone
365e00aeee remove ReadDir.end_of_stream on targets that don't use it 2020-10-09 10:00:11 -07:00
Josh Stone
c1297eca3e unix/vxworks: make DirEntry slightly smaller
`DirEntry` contains a `ReadDir` handle, which used to just be a wrapper
on `Arc<InnerReadDir>`. Commit af75314ecd added `end_of_stream: bool`
which is not needed by `DirEntry`, but adds 8 bytes after padding. We
can let `DirEntry` have an `Arc<InnerReadDir>` directly to avoid that.
2020-10-09 10:00:11 -07:00
Mateusz Mikuła
0c97c24a6c Remove some dead code in windows-gnu std 2020-10-09 13:23:50 +02:00
Thom Chiovoloni
4f37220510 Implement the same optimization in windows/time 2020-10-08 17:04:32 -07:00