Commit graph

976 commits

Author SHA1 Message Date
Mara Bos
77f333b304
Rollup merge of #78811 - a1phyr:const_io_structs, r=dtolnay
Make some std::io functions `const`

Tracking issue: #78812

Make the following functions `const`:
- `io::Cursor::new`
- `io::Cursor::get_ref`
- `io::Cursor::position`
- `io::empty`
- `io::repeat`
- `io::sink`

r? `````@dtolnay`````
2020-11-08 13:36:19 +01:00
Mara Bos
eef9951e44
Rollup merge of #78572 - de-vri-es:bsd-cloexec, r=m-ou-se
Use SOCK_CLOEXEC and accept4() on more platforms.

This PR enables the use of `SOCK_CLOEXEC` and `accept4` on more platforms.

-----

Android uses the linux kernel, so it should also support it.

DragonflyBSD introduced them in 4.4 (December 2015):
https://www.dragonflybsd.org/release44/

FreeBSD introduced them in 10.0 (January 2014):
https://wiki.freebsd.org/AtomicCloseOnExec

Illumos introduced them in a commit in April 2013, not sure when it was released. It is quite possible that is has always been in Illumos:
5dbfd19ad5
https://illumos.org/man/3socket/socket
https://illumos.org/man/3socket/accept4

NetBSD introduced them in 6.0 (Oktober 2012) and 8.0 (July 2018):
https://man.netbsd.org/NetBSD-6.0/socket.2
https://man.netbsd.org/NetBSD-8.0/accept.2

OpenBSD introduced them in 5.7 (May 2015):
https://man.openbsd.org/socket https://man.openbsd.org/accept
2020-11-08 13:36:07 +01:00
Mara Bos
1f034f77bc
Rollup merge of #76097 - pickfire:stabilize-spin-loop, r=KodrAus
Stabilize hint::spin_loop

Partially fix #55002, deprecate in another release

r? ``````@KodrAus``````
2020-11-08 13:35:54 +01:00
Camelid
8258cf285f Convert a bunch of intra-doc links 2020-11-07 12:50:57 -08:00
Christiaan Dirkx
94d73d4403 Refactor parse_prefix on Windows
Refactor `get_first_two_components` to `get_next_component`.

Fixes the following behaviour of `parse_prefix`:
 - series of separator bytes in a prefix are correctly parsed as a single separator
 - device namespace prefixes correctly recognize both `\\` and `/` as separators
2020-11-07 16:15:48 +01:00
Benoît du Garreau
001dd7e6a5 Add tracking issue 2020-11-06 18:04:52 +01:00
Benoît du Garreau
ae059b532f Make some std::io functions const
Includes:
- io::Cursor::new
- io::Cursor::get_ref
- io::Cursor::position
- io::empty
- io::repeat
- io::sink
2020-11-06 17:48:26 +01:00
Yuki Okushi
0e71fc75cc
Rollup merge of #78006 - pitaj:master, r=jyn514
Use Intra-doc links for std::io::buffered

Helps with #75080. I used the implicit link style for intrinsics, as that was what `minnumf32` and others already had.

``@rustbot`` modify labels: T-doc, A-intra-doc-links

r? ``@jyn514``
2020-11-07 01:02:03 +09:00
Yuki Okushi
4136ed26a1
Rollup merge of #74979 - maekawatoshiki:fix, r=Mark-Simulacrum
`#![deny(unsafe_op_in_unsafe_fn)]` in sys/hermit

Partial fix of #73904.

This encloses ``unsafe`` operations in ``unsafe fn`` in ``sys/hermit``.
Some unsafe blocks are not well documented because some system-based functions lack documents.
2020-11-07 01:01:59 +09:00
Ivan Tham
e8b5be5dff Stabilize hint::spin_loop
Partially fix #55002, deprecate in another release

Co-authored-by: Ashley Mannix <kodraus@hey.com>

Update stable version for stabilize_spin_loop

Co-authored-by: Joshua Nelson <joshua@yottadb.com>

Use better example for spinlock

As suggested by KodrAus

Remove renamed_spin_loop already available in master

Fix spin loop example
2020-11-06 23:41:55 +08:00
Maarten de Vries
3bee37c290 Disable accept4 on Android. 2020-11-06 14:17:48 +01:00
Peter Jaszkowiak
8d48e3bbb2 document HACKs 2020-11-05 19:26:08 -07:00
Peter Jaszkowiak
fe6dfcd28a Intra-doc links for std::io::buffered 2020-11-05 19:09:42 -07:00
Mara Bos
f383e4f1d9
Rollup merge of #78757 - camelid:crate-link-text, r=jyn514
Improve and clean up some intra-doc links
2020-11-05 10:30:02 +01:00
Mara Bos
43e1b58bcc
Rollup merge of #78716 - est31:array_traits, r=Dylan-DPC
Array trait impl comment/doc fixes

Two small doc/comment fixes regarding trait implementations on arrays.
2020-11-05 10:29:46 +01:00
Mara Bos
10d2843604
Rollup merge of #78093 - camelid:as-cleanup, r=jyn514
Clean up docs for 'as' keyword
2020-11-05 10:29:38 +01:00
Camelid
677b2acb48 Add missing comma
'Note however,' -> 'Note, however,'
2020-11-04 18:57:54 -08:00
Camelid
bbdb1f0f66 Clean up some intra-doc links 2020-11-04 18:57:52 -08:00
Camelid
d8afe98eba Clean up docs for 'as' keyword 2020-11-04 16:05:55 -08:00
LinkTed
ead7185db6 Fix docs for MacOs (again) 2020-11-04 19:45:48 +01:00
est31
5801109ba9 Move Copy and Clone into the list of traits implemented for all sizes 2020-11-04 01:28:37 +01:00
LinkTed
c779405686 Fix docs for MacOs (correction) 2020-11-03 18:28:04 +01:00
Mara Bos
8ed31d2782
Rollup merge of #78602 - RalfJung:raw-ptr-aliasing-issues, r=m-ou-se
fix various aliasing issues in the standard library

This fixes various cases where the standard library either used raw pointers after they were already invalidated by using the original reference again, or created raw pointers for one element of a slice and used it to access neighboring elements.
2020-11-01 11:53:36 +01:00
Mara Bos
f281a76f83
Rollup merge of #78599 - panstromek:master, r=m-ou-se
Add note to process::arg[s] that args shouldn't be escaped or quoted

This came out of discussion on [forum](https://users.rust-lang.org/t/how-to-get-full-output-from-command/50626), where I recently asked a question and it turned out that the problem was redundant quotation:

```rust
 Command::new("rg")
        .arg("\"pattern\"") // this will look for "pattern" with quotes included
```

This is something that has bitten me few times already (in multiple languages actually), so It'd be grateful to have it in the docs, even though it's not sctrictly Rust specific problem. Other users also agreed.

This can be really annoying to debug, because in many cases (inluding mine), quotes can be legal part of the argument, so the command doesn't fail, it just behaves unexpectedly. Not everybody (including me) knows that quotes around arguments are part of the shell and not part of the called program. Coincidentally, somoene had the same problem [yesterday](https://www.reddit.com/r/rust/comments/jkxelc/going_crazy_over_running_a_curl_process_from_rust/) on reddit.

I am not a native speaker, so I welcome any corrections or better formulation, I don't expect this to be merged as is. I was also reminded that this is platform/shell specific behaviour, but I didn't find a good way to formulate that briefly, any ideas welcome.

 It's also my first PR here, so I am not sure I did everything correctly, I did this just from Github UI.
2020-11-01 11:53:34 +01:00
Matyáš Racek
db416b232c
Apply suggestions from code review
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2020-10-31 17:28:44 +01:00
Ralf Jung
9f630af930 fix aliasing issue in unix sleep function 2020-10-31 16:26:06 +01:00
Matyáš Racek
d417bbef95
Add note to process::arg[s] that args shouldn't be escaped or quoted 2020-10-31 14:40:36 +01:00
Mara Bos
4ebd5536b4
Rollup merge of #77099 - tspiteri:exp_m1-examples, r=m-ou-se
make exp_m1 and ln_1p examples more representative of use

With this PR, the examples for `exp_m1` would fail if `x.exp() - 1.0` is used instead of `x.exp_m1()`, and the examples for `ln_1p` would fail if `(x + 1.0).ln()` is used instead of `x.ln_1p()`.
2020-10-31 09:49:32 +01:00
Mara Bos
76b8b00b4f
Rollup merge of #74622 - fusion-engineering-forks:panic-box, r=KodrAus
Add std::panic::panic_any.

The discussion of #67984 lead to the conclusion that there should be a macro or function separate from `std::panic!()` for throwing arbitrary payloads, to make it possible to deprecate or disallow (in edition 2021) `std::panic!(arbitrary_payload)`.

Alternative names:

- `panic_with!(..)`
- ~~`start_unwind(..)`~~ (panicking doesn't always unwind)
- `throw!(..)`
- `panic_throwing!(..)`
- `panic_with_value(..)`
- `panic_value(..)`
- `panic_with(..)`
- `panic_box(..)`
- `panic(..)`

The equivalent (private, unstable) function in `libstd` is called `std::panicking::begin_panic`.

I suggest `panic_any`, because it allows for any (`Any + Send`) type.

_Tracking issue: #78500_
2020-10-31 09:49:28 +01:00
Maarten de Vries
59c6ae615e Use SOCK_CLOEXEC and accept4() on more platforms. 2020-10-30 14:20:10 +01:00
Yuki Okushi
73d0340fd5
Rollup merge of #78554 - camelid:improve-drop_in_place-docs-wording, r=jyn514
Improve wording of `core::ptr::drop_in_place` docs

And two small intra-doc link conversions in `std::{f32, f64}`.
2020-10-30 18:00:58 +09:00
Yuki Okushi
02a4b58a3f
Rollup merge of #77921 - wcampbell0x2a:f64-collapsible-if, r=jyn514
f64: Refactor collapsible_if
2020-10-30 18:00:49 +09:00
Camelid
fee4f8feb0 Improve wording of core::ptr::drop_in_place docs
And two small intra-doc link conversions in `std::{f32, f64}`.
2020-10-29 20:09:29 -07:00
Mara Bos
b48fee010c Add tracking issue number for panic_any. 2020-10-28 21:23:45 +01:00
Mara Bos
a9d334d386
Update panic_any feature name.
Co-authored-by: Camelid <camelidcamel@gmail.com>
2020-10-28 21:21:41 +01:00
LinkTed
ea5e012ba7 Fix test cases for MacOs 2020-10-28 18:22:16 +01:00
Camelid
0217edbd29
Clean up intra-doc links in std::path 2020-10-27 20:54:30 -07:00
Tom Kaitchuck
5b3d98d9f8 Change link to point to crates.io keyword "hasher"
Signed-off-by: Tom Kaitchuck <Tom.Kaitchuck@gmail.com>
2020-10-27 20:49:52 -07:00
bors
90e6d0d46b Auto merge of #75671 - nathanwhit:cstring-temp-lint, r=oli-obk
Uplift `temporary-cstring-as-ptr` lint from `clippy` into rustc

The general consensus seems to be that this lint covers a common enough mistake to warrant inclusion in rustc.
The diagnostic message might need some tweaking, as I'm not sure the use of second-person perspective matches the rest of rustc, but I'd like to hear others' thoughts on that.

(cc #53224).

r? `@oli-obk`
2020-10-27 22:59:13 +00:00
bors
56d288fa46 Auto merge of #78227 - SergioBenitez:test-stdout-threading, r=m-ou-se
Capture output from threads spawned in tests

This is revival of #75172.

Original text:
> Fixes #42474.
>
> r? `@​dtolnay` since you expressed interest in this, but feel free to redirect if you aren't the right person anymore.

---

Closes #75172.
2020-10-27 11:43:18 +00:00
Nathan Whitaker
39941e6281 Fix bootstrap doctest failure 2020-10-26 22:09:47 -04:00
Yuki Okushi
4236d27c9b
Rollup merge of #78412 - camelid:cleanup-hash-docs, r=jonas-schievink
Improve formatting of hash collections docs
2020-10-27 08:45:30 +09:00
Yuki Okushi
f6f8764b25
Rollup merge of #78394 - rubik:master, r=m-ou-se
fix(docs): typo in BufWriter documentation

This PR fixes a small typo in the BufWriter documentation. The current documentation looks like this:

![2020-10-26-111501_438x83_scrot](https://user-images.githubusercontent.com/238549/97160357-83d3a000-177c-11eb-8a35-3cdd3a7d89de.png)

The `<u8>` at the end is mangled by Markdown. This PR makes the `BufWriter` documentation like the `BufReader` one:

https://github.com/rust-lang/rust/blob/master/library/std/src/io/buffered/bufreader.rs#L16

I'm tagging Steve as per the Rustc dev guide.

r? @steveklabnik
2020-10-27 08:45:20 +09:00
Yuki Okushi
5a33fa5179
Rollup merge of #78375 - taiki-e:question-in-macros, r=kennytm
Use ? in core/std macros
2020-10-27 08:45:10 +09:00
Yuki Okushi
2c307fab49
Rollup merge of #77703 - Keruspe:system-libunwind, r=Mark-Simulacrum
add system-llvm-libunwind config option

allows using the system-wide llvm-libunwind as the unwinder

Workaround for #76020
2020-10-27 08:44:44 +09:00
Nathan Whitaker
cb8b9012db Address review comments 2020-10-26 19:19:06 -04:00
Nathan Whitaker
1bcd2452fe Address review comments 2020-10-26 18:19:48 -04:00
Nathan Whitaker
737bfeffd2 Change to warn by default / fix typo 2020-10-26 18:19:48 -04:00
Nathan Whitaker
ce95122e95 Update doctest 2020-10-26 18:19:47 -04:00
Camelid
59f108885e Improve formatting of hash collections docs 2020-10-26 14:05:06 -07:00
Michele Lacchia
a4ba179bdd
fix(docs): typo in BufWriter documentation 2020-10-26 11:13:47 +01:00
DevJPM
3daa93f555 Updated documentation, x86 feature detection testing, and removed LLVM 9 exclusive features
Updated the added documentation in llvm_util.rs to note which copies of LLVM need to be inspected.
Removed avx512bf16 and avx512vp2intersect because they are unsupported before LLVM 9 with the build with external LLVM 8 being supported
Re-introduced detection testing previously removed for un-requestable features tsc and mmx
2020-10-26 08:36:14 +01:00
Dylan DPC
e0c08ae4e1
Rollup merge of #74477 - chansuke:sys-wasm-unsafe-op-in-unsafe-fn, r=Mark-Simulacrum
`#[deny(unsafe_op_in_unsafe_fn)]` in sys/wasm

This is part of #73904.

This encloses unsafe operations in unsafe fn in `libstd/sys/wasm`.

@rustbot modify labels: F-unsafe-block-in-unsafe-fn
2020-10-26 03:08:56 +01:00
Taiki Endo
04c0018d1b Use ? in core/std macros 2020-10-26 07:15:37 +09:00
DevJPM
cd95e939bb Removed movbe from run-time-detect
`movbe` seems to not be a run-time detectable feature on x86.
It has thus been removed from the list.
It was only commented out to ease comparison against the full list.
2020-10-25 17:27:22 +01:00
DevJPM
9feb567399 Updated the list of white-listed target features for x86
This PR both adds in-source documentation on what to look out for
when adding a new (X86) feature set and adds all that are detectable at run-time in Rust stable
as of 1.27.0.

This should only enable the use of the corresponding LLVM intrinsics.
Actual intrinsics need to be added separately in rust-lang/stdarch.

It also re-orders the run-time-detect test statements to be more consistent
with the actual list of intrinsics whitelisted and removes underscores not present
in the actual names (which might be mistaken as being part of the name)
2020-10-25 17:06:40 +01:00
Yuki Okushi
72e02b015e
Rollup merge of #78208 - liketechnik:issue-69399, r=oli-obk
replace `#[allow_internal_unstable]` with `#[rustc_allow_const_fn_unstable]` for `const fn`s

`#[allow_internal_unstable]` is currently used to side-step feature gate and stability checks.
While it was originally only meant to be used only on macros, its use was expanded to `const fn`s.

This pr adds stricter checks for the usage of `#[allow_internal_unstable]` (only on macros) and introduces the `#[rustc_allow_const_fn_unstable]` attribute for usage on `const fn`s.

This pr does not change any of the functionality associated with the use of `#[allow_internal_unstable]` on macros or the usage of `#[rustc_allow_const_fn_unstable]` (instead of `#[allow_internal_unstable]`) on `const fn`s (see https://github.com/rust-lang/rust/issues/69399#issuecomment-712911540).

Note: The check for `#[rustc_allow_const_fn_unstable]` currently only validates that the attribute is used on a function, because I don't know how I would check if the function is a `const fn` at the place of the check. I therefore openend this as a 'draft pull request'.

Closes rust-lang/rust#69399

r? @oli-obk
2020-10-25 18:43:40 +09:00
Jonas Schievink
e3808edeee
Rollup merge of #78119 - fusion-engineering-forks:panic-use-as-str, r=Amanieu
Throw core::panic!("message") as &str instead of String.

This makes `core::panic!("message")` consistent with `std::panic!("message")`, which throws a `&str` and not a `String`.

This also makes any other panics from `core::panicking::panic` result in a `&str` rather than a `String`, which includes compiler-generated panics such as the panics generated for `mem::zeroed()`.

---

Demonstration:

```rust
use std::panic;
use std::any::Any;

fn main() {
    panic::set_hook(Box::new(|panic_info| check(panic_info.payload())));

    check(&*panic::catch_unwind(|| core::panic!("core")).unwrap_err());
    check(&*panic::catch_unwind(|| std::panic!("std")).unwrap_err());
}

fn check(msg: &(dyn Any + Send)) {
    if let Some(s) = msg.downcast_ref::<String>() {
        println!("Got a String: {:?}", s);
    } else if let Some(s) = msg.downcast_ref::<&str>() {
        println!("Got a &str: {:?}", s);
    }
}
```

Before:
```
Got a String: "core"
Got a String: "core"
Got a &str: "std"
Got a &str: "std"
```

After:
```
Got a &str: "core"
Got a &str: "core"
Got a &str: "std"
Got a &str: "std"
```
2020-10-24 22:39:53 +02:00
Jonas Schievink
e34263d86a
Rollup merge of #77610 - hermitcore:dtors, r=m-ou-se
revise Hermit's mutex interface to support the behaviour of StaticMutex

rust-lang/rust#77147 simplifies things by splitting this Mutex type into two types matching the two use cases: StaticMutex and MovableMutex. To support the new behavior of StaticMutex, we move part of the mutex implementation into libstd.

The interface to the OS changed. Consequently, I removed a few functions, which aren't longer needed.
2020-10-24 22:39:44 +02:00
Jonas Schievink
01a38f0d9a
Rollup merge of #75115 - chansuke:sys-cloudabi-unsafe, r=KodrAus
`#[deny(unsafe_op_in_unsafe_fn)]` in sys/cloudabi

Partial fix of #73904.

This encloses unsafe operations in unsafe fn in sys/cloudabi.
2020-10-24 22:39:35 +02:00
Dan Gohman
6249cda78f Disable use of linkat on Android as well.
According to [the bionic status page], `linkat` has only been available
since API level 21. Since Android is based on Linux and Linux's `link`
doesn't follow symlinks, just use `link` on Android.

[the bionic status page]: https://android.googlesource.com/platform/bionic/+/master/docs/status.md
2020-10-24 09:43:31 -07:00
Jonas Schievink
eaa982305d
Rollup merge of #78274 - Enet4:patch-1, r=jonas-schievink
Update description of Empty Enum for accuracy

An empty enum is similar to the never type `!`, rather than the unit type `()`.
2020-10-24 14:12:11 +02:00
chansuke
d37b8cf729 Remove unnecessary unsafe block from condvar_atomics & mutex_atomics 2020-10-24 18:22:18 +09:00
chansuke
d147f78e36 Fix unsafe operation of wasm32::memory_atomic_notify 2020-10-24 18:14:17 +09:00
chansuke
de87ae7961 Add documents for DLMALLOC 2020-10-24 17:59:58 +09:00
chansuke
eed45107da Add some description for (malloc/calloc/free/realloc) 2020-10-24 11:50:09 +09:00
chansuke
d413bb6f57 #[deny(unsafe_op_in_unsafe_fn)] in sys/wasm 2020-10-24 11:50:09 +09:00
Eduardo Pinho
efedcb2344
Update description of Empty Enum for accuracy
An empty enum is similar to the never type `!`, rather than the unit type `()`.
2020-10-23 12:13:07 +01:00
Yuki Okushi
b968738348
Rollup merge of #77918 - wcampbell0x2a:cleanup-network-tests, r=m-ou-se
Cleanup network tests

Some cleanup for network related tests
2020-10-23 18:26:22 +09:00
Sergio Benitez
db15596c57 Only load LOCAL_STREAMS if they are being used 2020-10-22 18:15:48 -07:00
Tyler Mandry
d0d0e78208 Capture output from threads spawned in tests
Fixes #42474.
2020-10-22 18:15:44 -07:00
Jubilee Young
ef027a1eed Duration::zero() -> Duration::ZERO
Duration::ZERO composes better with match and various other things,
at the cost of an occasional parens, and results in less work for the
optimizer, so let's use that instead.
2020-10-21 20:44:03 -07:00
Jubilee Young
d72d5f48c2 Dogfood Duration API in std::time tests
This expands time's test suite to use more and in more places the
range of methods and constants added to Duration in recent
proposals for the sake of testing more API surface area and
improving legibility.
2020-10-21 20:03:56 -07:00
varkor
878c97e70c Update to rustc-demangle 0.1.18 2020-10-21 21:11:11 +01:00
varkor
2b9d22d3a9 Update rustc-demangle 2020-10-21 21:05:38 +01:00
Florian Warzecha
05f4a9a42a
switch allow_internal_unstable const fns to rustc_allow_const_fn_unstable 2020-10-21 20:54:20 +02:00
Marc-Antoine Perennou
66fa42a946 allow using the system-wide llvm-libunwind as the unwinder
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
2020-10-21 14:45:58 +02:00
Dan Gohman
d0178b4f99 Make it platform-specific whether hard_link follows symlinks.
Also mention that where possible, `hard_link` does not follow symlinks.
2020-10-21 01:46:27 -07:00
Yuki Okushi
6df79bf8a8
Rollup merge of #77923 - wcampbell0x2a:cleanup-net-module, r=scottmcm
[net] apply clippy lints

Applied helpful clippy lints to the network std library module.
2020-10-20 12:11:04 +09:00
Yuki Okushi
f9db00839e
Rollup merge of #77838 - RalfJung:const-fn, r=kennytm
const keyword: brief paragraph on 'const fn'

`const fn` were mentioned in the title, but called "deterministic functions" which is not their main property (though at least currently it is a consequence of being const-evaluable). This adds a brief paragraph discussing them, also in the hopes of clarifying that they do *not* have any effect on run-time uses.
2020-10-20 12:11:02 +09:00
Tomasz Miąsko
21c29b1e95 Check that pthread mutex initialization succeeded
If pthread mutex initialization fails, the failure will go unnoticed unless
debug assertions are enabled. Any subsequent use of mutex will also silently
fail, since return values from lock & unlock operations are similarly checked
only through debug assertions.

In some implementations the mutex initialization requires a memory
allocation and so it does fail in practice.

Check that initialization succeeds to ensure that mutex guarantees
mutual exclusion.
2020-10-20 00:00:00 +00:00
Mara Bos
2780e35246 Throw core::panic!("message") as &str instead of String.
This makes it consistent with std::panic!("message"), which also throws
a &str, not a String.
2020-10-19 22:31:11 +02:00
wcampbell
736c27ec0b Revert "[net] clippy: needless_update"
This reverts commit 058699d0a2.
2020-10-19 07:22:45 -04:00
Mara Bos
ff8df0bbe3 Add cfg(not(test)) to std_panic_macro rustc_diagnostic_item. 2020-10-19 10:57:44 +02:00
pierwill
67dc9b7581
Add missing punctuation 2020-10-18 23:03:16 -07:00
Mara Bos
dd262e3856 Add cfg(not(bootstrap)) on the new rustc_diagnostic_item attributes.
The beta compiler doesn't accept rustc_diagnostic_items on macros yet.
2020-10-18 23:45:20 +02:00
Mara Bos
462ee9c1b5 Mark the panic macros as diagnostic items. 2020-10-18 22:20:19 +02:00
Chai T. Rex
c2de8fe294 Stabilize or_insert_with_key 2020-10-18 15:45:09 -04:00
est31
a687420d17 Remove redundant 'static from library crates 2020-10-18 17:25:51 +02:00
Dan Gohman
ce00b3e2e0 Use link on platforms which lack linkat. 2020-10-18 07:47:32 -07:00
Dan Gohman
23a5c21415 Fix a typo in a comment. 2020-10-18 07:21:41 -07:00
Mara Bos
16201da6a4 Rename panic_box to panic_any. 2020-10-18 12:29:13 +02:00
Mara Bos
01b0aff1df Add std::panic::panic_box. 2020-10-18 12:25:26 +02:00
chansuke
d3467fe520 #[deny(unsafe_op_in_unsafe_fn)] in sys/cloudabi 2020-10-18 17:59:54 +09:00
bors
c38ddb8040 Auto merge of #74480 - yoshuawuyts:hardware_threads, r=dtolnay
Add std:🧵:available_concurrency

This PR adds a counterpart to [C++'s `std:🧵:hardware_concurrency`](https://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency) to Rust, tracking issue https://github.com/rust-lang/rust/issues/74479.

cc/ `@rust-lang/libs`

## Motivation

Being able to know how many hardware threads a platform supports is a core part of building multi-threaded code. In C++ 11 this has become available through the [`std:🧵:hardware_concurrency`](https://en.cppreference.com/w/cpp/thread/thread/hardware_concurrency) API. Currently in Rust most of the ecosystem depends on the [`num_cpus` crate](https://docs.rs/num_cpus/1.13.0/num_cpus/) ([no.35 in top 500 crates](https://docs.google.com/spreadsheets/d/1wwahRMHG3buvnfHjmPQFU4Kyfq15oTwbfsuZpwHUKc4/edit#gid=1253069234)) to provide this functionality. This PR proposes an API to provide access to the number of hardware threads available on a given platform.

__edit (2020-07-24):__ The purpose of this PR is to provide a hint for how many threads to spawn to saturate the processor. There's value in introducing APIs for NUMA and Windows processor groups, but those are intentionally out of scope for this PR. See: https://github.com/rust-lang/rust/pull/74480#issuecomment-662116186.

## Naming

Discussing the naming of the API on Zulip surfaced two options:

- `std:🧵:hardware_concurrency`
- `std:🧵:hardware_threads`

Both options seemed acceptable, but overall people seem to gravitate the most towards `hardware_threads`. Additionally `@jonas-schievink` pointed out that the "hardware threads" terminology is well-established and is used in among other the [RISC-V specification](https://riscv.org/specifications/isa-spec-pdf/) (page 20):

> A component is termed a core if it contains an independent instruction fetch unit. A RISC-V-compatible core might support multiple RISC-V-compatible __hardware threads__, or harts, through multithreading.

It's also worth noting that [the original paper introducing C++'s `std::thread` submodule](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2007/n2320.html) unfortunately doesn't feature any discussion on the naming of `hardware_concurrency`, so we can't use that to help inform our decision here.

## Return type

An important consideration `@joshtriplett` brought up is that we don't want to default to `1` for platforms where the number of available threads cannot be retrieved. Instead we want to inform the users of the fact that we don't know and allow them to handle that case. Which is why this PR uses `Option<NonZeroUsize>` as its return type, where `None` is returned on platforms where we don't know the number of hardware threads available.

The reasoning for `NonZeroUsize` vs `usize` is that if the number of threads for a platform are known, they'll always be at least 1. As evidenced by the example the `NonZero*` family of APIs may currently not be the most ergonomic to use, but improving the ergonomics of them is something that I think we can address separately.

## Implementation

`@Mark-Simulacrum` pointed out that most of the code we wanted to expose here was already available under `libtest`. So this PR mostly moves the internal code of libtest into a public API.
2020-10-18 02:28:21 +00:00
LinkTed
79273fa30c Fix cannot find type ucred for MacOs by using fake definitions 2020-10-17 19:36:11 +02:00
bors
4cb7ef0f94 Auto merge of #77455 - asm89:faster-spawn, r=kennytm
Use posix_spawn() on unix if program is a path

Previously `Command::spawn` would fall back to the non-posix_spawn based
implementation if the `PATH` environment variable was possibly changed.
On systems with a modern (g)libc `posix_spawn()` can be significantly
faster. If program is a path itself the `PATH` environment variable is
not used for the lookup and it should be safe to use the
`posix_spawnp()` method. [1]

We found this, because we have a cli application that effectively runs a
lot of subprocesses. It would sometimes noticeably hang while printing
output. Profiling showed that the process was spending the majority of
time in the kernel's `copy_page_range` function while spawning
subprocesses. During this time the process is completely blocked from
running, explaining why users were reporting the cli app hanging.

Through this we discovered that `std::process::Command` has a fast and
slow path for process execution. The fast path is backed by
`posix_spawnp()` and the slow path by fork/exec syscalls being called
explicitly. Using fork for process creation is supposed to be fast, but
it slows down as your process uses more memory.  It's not because the
kernel copies the actual memory from the parent, but it does need to
copy the references to it (see `copy_page_range` above!).  We ended up
using the slow path, because the command spawn implementation in falls
back to the slow path if it suspects the PATH environment variable was
changed.

Here is a smallish program demonstrating the slowdown before this code
change:

```
use std::process::Command;
use std::time::Instant;

fn main() {
    let mut args = std::env::args().skip(1);
    if let Some(size) = args.next() {
        // Allocate some memory
        let _xs: Vec<_> = std::iter::repeat(0)
            .take(size.parse().expect("valid number"))
            .collect();

        let mut command = Command::new("/bin/sh");
        command
            .arg("-c")
            .arg("echo hello");

        if args.next().is_some() {
            println!("Overriding PATH");
            command.env("PATH", std::env::var("PATH").expect("PATH env var"));
        }

        let now = Instant::now();
        let child = command
            .spawn()
            .expect("failed to execute process");

        println!("Spawn took: {:?}", now.elapsed());

        let output = child.wait_with_output().expect("failed to wait on process");
        println!("Output: {:?}", output);
    } else {
        eprintln!("Usage: prog [size]");
        std::process::exit(1);
    }
    ()
}
```

Running it and passing different amounts of elements to use to allocate
memory shows that the time taken for `spawn()` can differ quite
significantly. In latter case the `posix_spawnp()` implementation is 30x
faster:

```
$ cargo run --release 10000000
...
Spawn took: 324.275µs
hello
$ cargo run --release 10000000 changepath
...
Overriding PATH
Spawn took: 2.346809ms
hello
$ cargo run --release 100000000
...
Spawn took: 387.842µs
hello
$ cargo run --release 100000000 changepath
...
Overriding PATH
Spawn took: 13.434677ms
hello
```

[1]: 5f72f9800b/posix/execvpe.c (L81)
2020-10-17 06:16:00 +00:00
Yoshua Wuyts
3717646366 Add std:🧵:available_concurrency 2020-10-16 23:36:15 +02:00
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
Dan Gohman
91a9f83dd1 Define fs::hard_link to not follow symlinks.
POSIX leaves it implementation-defined whether `link` follows symlinks.
In practice, for example, on Linux it does not and on FreeBSD it does.
So, switch to `linkat`, so that we can pick a behavior rather than
depending on OS defaults.

Pick the option to not follow symlinks. This is somewhat arbitrary, but
seems the less surprising choice because hard linking is a very
low-level feature which requires the source and destination to be on
the same mounted filesystem, and following a symbolic link could end
up in a different mounted filesystem.
2020-10-16 12:05:49 -07: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
Tom Kaitchuck
1d287255f5 Change mention of fnv in HashMap to mention aHash as an alternitive hasher.
Signed-off-by: Tom Kaitchuck <tom.kaitchuck@emc.com>
2020-10-15 14:03:39 -07: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
wcampbell
ce04836327
fmt
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13 20:11:29 -04:00
wcampbell
7da0e58da4
use matches! in library/std/src/net/ip.rs
Apply suggestion from review

Co-authored-by: LingMan <LingMan@users.noreply.github.com>
2020-10-13 19:33:39 -04:00
wcampbell
7a75f44183
[net] clippy: identity_op
warning: the operation is ineffective. Consider reducing it to
`self.segments()[0]`
    --> library/std/src/net/ip.rs:1265:9
     |
1265 |         (self.segments()[0] & 0xffff) == 0xfe80
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = note: `#[warn(clippy::identity_op)]` on by default
     = help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#identity_op

warning: the operation is ineffective. Consider reducing it to
`self.segments()[1]`
    --> library/std/src/net/ip.rs:1266:16
     |
1266 |             && (self.segments()[1] & 0xffff) == 0
     |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#identity_op

warning: the operation is ineffective. Consider reducing it to
`self.segments()[2]`
    --> library/std/src/net/ip.rs:1267:16
     |
1267 |             && (self.segments()[2] & 0xffff) == 0
     |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#identity_op

warning: the operation is ineffective. Consider reducing it to
`self.segments()[3]`
    --> library/std/src/net/ip.rs:1268:16
     |
1268 |             && (self.segments()[3] & 0xffff) == 0
     |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
     |
     = help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#identity_op

Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13 18:03:27 -04:00
wcampbell
e6dc604e8b
[net] clippy: match_like_matches_macro
warning: match expression looks like `matches!` macro
   --> library/std/src/net/ip.rs:459:9
    |
459 | /         match self.octets() {
460 | |             [169, 254, ..] => true,
461 | |             _ => false,
462 | |         }
    | |_________^ help: try this: `matches!(self.octets(), [169, 254,
..])`
    |
    = note: `#[warn(clippy::match_like_matches_macro)]` on by default
    = help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro

Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13 18:00:59 -04:00
wcampbell
058699d0a2
[net] clippy: needless_update
warning: struct update has no effect, all the fields in the struct have
already been specified
   --> library/std/src/net/addr.rs:367:19
    |
367 |                 ..unsafe { mem::zeroed() }
    |                   ^^^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: `#[warn(clippy::needless_update)]` on by default
    = help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#needless_update
2020-10-13 17:58:29 -04:00
wcampbell
096722ff76
Refactor collapsible_if
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13 17:50:10 -04:00
Stefan Lankes
bf268fe928
box mutex to get a movable mutex
the commit avoid an alignement issue in Mutex implementation
2020-10-13 23:25:42 +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
wcampbell
964a5ac962
Use is_ok() instead of empty Ok(_)
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13 17:01:50 -04:00
wcampbell
a93f58f5e6
Join map operators
Signed-off-by: wcampbell <wcampbell1995@gmail.com>
2020-10-13 17:01:09 -04:00
Gray Olson
a6d98d8ec9 generalize warning 2020-10-13 11:03:31 -07: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
Jacob Kiesel
a7d3368448 Stabilize clamp 2020-10-12 15:09:45 -06: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
Ralf Jung
c8405d2251 fix markdown reference
Co-authored-by: Dariusz Niedoba <darksv@users.noreply.github.com>
2020-10-12 09:47:43 +02:00
Stefan Lankes
1741e5b8f5
define required type 'MovableMutex' 2020-10-12 06:54:48 +02:00
Stefan Lankes
30c3dadb4d
reuse implementation of the system provider "unsupported" 2020-10-12 06:53:06 +02:00
Stefan Lankes
33fd08b61f
remove obsolete function diverge 2020-10-12 06:51:52 +02:00
Ralf Jung
0ec3ea9e69 const keyword: brief paragraph on 'const fn' 2020-10-12 00:12:45 +02:00
LinkTed
d8c75d9f91 Fix unresolved imports for recv_vectored_with_ancillary_from, send_vectored_with_ancillary_to and SocketAncillary 2020-10-11 19:23:41 +02: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
Stefan Lankes
8d8a290c69
add hermit to the list of omit OS 2020-10-11 11:56:09 +02:00
Stefan Lankes
530f575466
revise code to pass the format check 2020-10-11 11:56:00 +02:00
Stefan Lankes
d6e955f3bf
fix typos in new method 2020-10-11 11:55:51 +02:00
Stefan Lankes
986c1fc053
revise comments and descriptions of the helper functions 2020-10-11 11:54:54 +02:00
Stefan Lankes
d560b50d87
revise code to pass the format check 2020-10-11 11:54:16 +02:00
Stefan Lankes
98fcc3fbc7
using the latest version of libhermit-rs 2020-10-11 11:53:54 +02:00
Stefan Lankes
16d65d0432
revise Hermit's mutex interface to support the behaviour of StaticMutex
rust-lang/rust#77147 simplifies things by splitting this Mutex type
into two types matching the two use cases: StaticMutex and MovableMutex.
To support the behavior of StaticMutex, we move part of the mutex
implementation into libstd.
2020-10-11 11:53:30 +02: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
LinkTed
64facfef51 Fix unresolved link to SocketAncillary 2020-10-10 15:19:13 +02:00
LinkTed
7b596f2e13 Fix libc is ambiguous for Windows 2020-10-10 15:19:13 +02:00
LinkTed
fc65f6a0ce Fix import errors for #[cfg(doc)] target 2020-10-10 15:19:13 +02:00
LinkTed
a81764731c Add fake definitions for Windows 2020-10-10 15:19:13 +02:00
LinkTed
d0069a0cc5 Fix imports for MacOs 2020-10-10 15:19:13 +02:00
LinkTed
1ae54e560a Change imports for cfg(doc) 2020-10-10 15:19:13 +02:00
LinkTed
e9bf69954c Remove passcred for emscripten 2020-10-10 15:19:13 +02:00
LinkTed
6b0c3dfe00 Remove unnecessary trailing semicolon 2020-10-10 15:19:13 +02:00
LinkTed
ce167f8be7 Fix type mismatching for different OSes. 2020-10-10 15:19:13 +02:00
LinkTed
889c9272cb Remove SocketCred for emscripten 2020-10-10 15:19:13 +02:00
LinkTed
0fcb834832 Fix unused import for IoSliceMut for macos 2020-10-10 15:19:13 +02:00
LinkTed
31e6e3896d Fix SO_PASSCRED for macos 2020-10-10 15:19:13 +02:00
LinkTed
b01ce2cfd0 Fix MSG_CMSG_CLOEXEC for macos 2020-10-10 15:19:13 +02:00
LinkTed
c2a1b50140 Add conditional compilation for import 2020-10-10 15:19:13 +02:00
LinkTed
e0cedba63e Fix cfg condition for test 2020-10-10 15:19:13 +02:00
LinkTed
d30508f95c Remove target_os, which does not have SO_PASSCRED constant in libc 2020-10-10 15:19:13 +02:00
LinkTed
1f6d7dcc0a Remove target_os, which does not have cmsghdr struct in libc 2020-10-10 15:19:13 +02:00
LinkTed
7b476d87fb Remove target_os, which does not have MSG_CMSG_CLOEXEC constant in libc 2020-10-10 15:19:12 +02:00
LinkTed
db902bca3a Add the code of the tracking issue 2020-10-10 15:19:12 +02:00
LinkTed
cc085e9170 Replace assert with unreachable 2020-10-10 15:19:12 +02:00
LinkTed
e61148f98a Cast boolean into int directly in function set_passcred 2020-10-10 15:19:12 +02:00
LinkTed
d0b133cdc6 Remove unsupported target_os for SocketCred 2020-10-10 15:19:12 +02:00
LinkTed
5964d599ac Change standard types to libc types 2020-10-10 15:19:12 +02:00
LinkTed
1902711f38 Change name of struct to SocketCred 2020-10-10 15:19:12 +02:00
LinkTed
eeea5c23b4 Change API to unsafe and add doc comments 2020-10-10 15:19:12 +02:00
LinkTed
686964f0f5 Add set_passcred and passcred methods to UnixStream and UnixDatagram 2020-10-10 15:19:12 +02:00
LinkTed
19c5fdda7c Rename test.rs to tests.rs 2020-10-10 15:19:12 +02:00
LinkTed
a91fd7328c Add doc comments 2020-10-10 15:19:12 +02:00
LinkTed
46764d48bb Add doc(cfg(...)) 2020-10-10 15:19:12 +02:00
LinkTed
1869141e54 Reduce impl trait by using macro in raw_fd.rs 2020-10-10 15:19:12 +02:00
LinkTed
53791b3ff4 Move conditional compilation to the upper module and sort the target OS list alphabetically 2020-10-10 15:19:12 +02:00
LinkTed
07ed6afc6d Remove unnecessary path 2020-10-10 15:19:12 +02:00
LinkTed
6ed9bface6 Use fill instead of memset 2020-10-10 15:19:12 +02:00
LinkTed
1f3195a5df Remove inner function in bind, connect and send_to 2020-10-10 15:19:12 +02:00
LinkTed
4c929a00ee Remove lifetime annotation in messages function 2020-10-10 15:19:12 +02:00
LinkTed
b82f29d780 Remove Clone trait bound in add_to_ancillary_data 2020-10-10 15:19:11 +02:00
LinkTed
3dfab6fb64 Add integer overflow check 2020-10-10 15:19:11 +02:00
LinkTed
e1084052a7 Replace TryFrom of AncillaryData with a private method. 2020-10-10 15:19:11 +02:00
LinkTed
8784ffbb4e Using read_unaligned instead of memcpy. 2020-10-10 15:19:11 +02:00
LinkTed
8783b06bd2 Move add_to_ancillary_data and AncillaryDataIter to ancillary.rs 2020-10-10 15:19:11 +02:00
LinkTed
e6984eee6f Add UCred struct 2020-10-10 15:19:11 +02:00
LinkTed
6f82ddf18e Add AncillaryError 2020-10-10 15:19:11 +02:00
LinkTed
6fa7c3f79e Split net.rs into multiple files 2020-10-10 15:19:11 +02:00
LinkTed
0b3c9d8465 unix: Extend UnixStream and UnixDatagram to send and receive file descriptors
Add the functions `recv_vectored_fds` and `send_vectored_fds` to send and receive file descriptors, by using `recvmsg` and `sendmsg` system call.
2020-10-10 15:19:11 +02: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
Thom Chiovoloni
59c06e9e40 Switch to using a single atomic and treating 0 as 'uninitialized' 2020-10-08 17:03:16 -07:00
Mara Bos
f1c3edbfab
Assert state in sys/unsupported's RwLock::write_unlock.
Co-authored-by: Joshua Nelson <joshua@yottadb.com>
2020-10-09 00:39:03 +02:00
Thom Chiovoloni
e4cf24bd45 Fiddle with the comments 2020-10-08 15:17:35 -07:00
Tomasz Miąsko
6cd5506897 Check for errors returned from posix_spawn*_init functions
The posix_spawnattr_init & posix_spawn_file_actions_init might fail,
but their return code is not checked.

Check for non-zero return code and destroy only succesfully initialized
objects.
2020-10-08 23:53:15 +02:00
Tomasz Miąsko
5faf25b95c Check for non-zero return value from posix_spawn functions
The cvt function compares the argument with -1 and when equal returns a new
io::Error constructed from errno. It is used together posix_spawn_* functions.
This is incorrect. Those functions do not set errno. Instead they return
non-zero error code directly.

Check for non-zero return code and use it to construct a new io::Error.
2020-10-08 23:53:15 +02:00
Mara Bos
f4e884288d Apply deny(unsafe_op_in_unsafe_fn) to all of sys/unsupported. 2020-10-08 23:37:23 +02:00
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
maekawatoshiki
14158f5514 Remove #![allow(unsafe_op_in_unsafe_fn)] except for mod.rs 2020-10-08 22:13:19 +09:00
Jacob Hughes
bf0adc3c36 Rename LayoutErr to LayoutError outside of core 2020-10-08 00:40:10 -04: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
Mara Bos
03fb61cfef Formatting. 2020-10-06 18:46:57 +02:00
Mara Bos
13f166a9e6 Add comment documenting NtWaitForKeyedEvent's timeout interpretation. 2020-10-06 18:41:26 +02:00
Mara Bos
43f844b84d Add documentation to Windows thread parker implementation. 2020-10-06 18:41:26 +02:00