Commit Graph

2716 Commits

Author SHA1 Message Date
Stefan Lankes
1ab5b0bc05 removing architecture requirements for RustyHermit
RustHermit and HermitCore is able to run on aarch64 and x86_64.
In the future these operating systems will also support RISC-V.
Consequently, the dependency to a specific target should be removed.
Building hermit-abi fails if the architecture isn't supported.
2022-02-15 13:57:07 +01:00
bors
1f4681ad7a Auto merge of #91673 - ChrisDenton:path-absolute, r=Mark-Simulacrum
`std::path::absolute`

Implements #59117 by adding a `std::path::absolute` function that creates an absolute path without reading the filesystem. This is intended to be a drop-in replacement for [`std::fs::canonicalize`](https://doc.rust-lang.org/std/fs/fn.canonicalize.html) in cases where it isn't necessary to resolve symlinks. It can be used on paths that don't exist or where resolving symlinks is unwanted. It can also be used to avoid circumstances where `canonicalize` might otherwise fail.

On Windows this is a wrapper around [`GetFullPathNameW`](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamew). On Unix it partially implements the POSIX [pathname resolution](https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_13) specification, stopping just short of actually resolving symlinks.
2022-02-13 12:03:52 +00:00
Matthias Krüger
92613a25fc
Rollup merge of #89926 - the8472:saturate-instant, r=Mark-Simulacrum
make `Instant::{duration_since, elapsed, sub}` saturating and remove workarounds

This removes all mutex/atomic-based workarounds for non-monotonic clocks and makes the previously panicking methods saturating instead. Additionally `saturating_duration_since` becomes deprecated since `duration_since` now fills that role.

Effectively this moves the fixup from `Instant` construction to the comparisons.

This has some observable effects, especially on platforms without monotonic clocks:

* Incorrectly ordered Instant comparisons no longer panic in release mode. This could hide some programming errors, but since debug mode still panics tests can still catch them.
* `checked_duration_since` will now return `None` in more cases. Previously it only happened when one compared instants obtained in the wrong order or manually created ones. Now it also does on backslides.
* non-monotonic intervals will not be transitive, i.e. `b.duration_since(a) + c.duration_since(b) != c.duration_since(a)`

The upsides are reduced complexity and lower overhead of `Instant::now`.

## Motivation

Currently we must choose between two poisons. One is high worst-case latency and jitter of `Instant::now()` due to explicit synchronization; see #83093 for benchmarks, the worst-case overhead is > 100x. The other is sporadic panics on specific, rare combinations of CPU/hypervisor/operating system due to platform bugs.

Use-cases where low-overhead, fine-grained timestamps are needed - such as syscall tracing, performance profiles or sensor data acquisition (drone flight controllers were mentioned in a libs meeting) in multi-threaded programs - are negatively impacted by the synchronization.

The panics are user-visible (program crashes), hard to reproduce and can be triggered by any dependency that might be using Instants for any reason.

A solution that is fast _and_ doesn't panic is desirable.

----

closes #84448
closes #86470
2022-02-13 06:44:12 +01:00
bors
01c4c41301 Auto merge of #93696 - Amanieu:compiler-builtins-0.1.68, r=Mark-Simulacrum
Bump compiler-builtins to 0.1.69

This includes https://github.com/rust-lang/compiler-builtins/pull/452 which should fix some issues with duplicate symbol defintions of some intrinsics.
2022-02-13 02:40:56 +00:00
Josh Triplett
37a1fc542f Capitalize "Rust"
Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
2022-02-13 01:06:36 +01:00
The 8472
376d955a32 Add panic docs describing old, current and possible future behavior 2022-02-13 01:06:34 +01:00
The 8472
bda2693e9b Add caveat about the monotonicity guarantee by linking to the later section 2022-02-13 01:05:00 +01:00
The8472
9d8ef11607 make Instant::{duration_since, elapsed, sub} saturating and remove workarounds
This removes all mutex/atomics based workarounds for non-monotonic clocks and makes the previously panicking methods saturating instead.

Effectively this moves the monotonization from `Instant` construction to the comparisons.

This has some observable effects, especially on platforms without monotonic clocks:

* Incorrectly ordered Instant comparisons no longer panic. This may hide some programming errors until someone actually looks at the resulting `Duration`
* `checked_duration_since` will now return `None` in more cases. Previously it only happened when one compared instants obtained in the wrong order or
  manually created ones. Now it also does on backslides.

The upside is reduced complexity and lower overhead of `Instant::now`.
2022-02-13 01:04:55 +01:00
bors
9c3a3e3d5b Auto merge of #93697 - the8472:fix-windows-path-hash, r=Mark-Simulacrum
Fix hashing for windows paths containing a CurDir component

* the logic only checked for / but not for \
* verbatim paths shouldn't skip items at all since they don't get normalized
* the extra branches get optimized out on unix since is_sep_byte is a trivial comparison and is_verbatim is always-false
* tests lacked windows coverage for these cases

That lead to equal paths not having equal hashes and to unnecessary collisions.
2022-02-12 14:01:13 +00:00
bors
f19851069e Auto merge of #93921 - matthiaskrgr:rollup-wn3jlxj, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #90955 (Rename `FilenameTooLong` to `InvalidFilename` and also use it for Windows' `ERROR_INVALID_NAME`)
 - #91607 (Make `span_extend_to_prev_str()` more robust)
 - #92895 (Remove some unused functionality)
 - #93635 (Add missing platform-specific information on current_dir and set_current_dir)
 - #93660 (rustdoc-json: Add some tests for typealias item)
 - #93782 (Split `pauth` target feature)
 - #93868 (Fix incorrect register conflict detection in asm!)
 - #93888 (Implement `AsFd` for `&T` and `&mut T`.)
 - #93909 (Fix typo: explicitely -> explicitly)
 - #93910 (fix mention of moved function in `rustc_hir` docs)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-02-11 23:01:50 +00:00
Matthias Krüger
34997f0114
Rollup merge of #93888 - sunfishcode:sunfishcode/impl-asfd-for-ref, r=joshtriplett
Implement `AsFd` for `&T` and `&mut T`.

Add implementations of `AsFd` for `&T` and `&mut T`, so that users can
write code like this:

```rust
pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
```

with `fd: F` rather than `fd: &F`.

And similar for `AsHandle` and `AsSocket` on Windows.

Also, adjust the `fchown` example to pass the file by reference. The
code can work either way now, but passing by reference is more likely
to be what users will want to do.

This is an alternative to #93869, and is a simpler way to achieve the
same goals: users don't need to pass borrowed-`BorrowedFd` arguments,
and it prevents a pitfall in the case where users write `fd: F` instead
of `fd: &F`.

r? ```@joshtriplett```
2022-02-11 21:48:50 +01:00
Matthias Krüger
15d71cff2d
Rollup merge of #93635 - GuillaumeGomez:missing-platform-spec-info, r=Amanieu
Add missing platform-specific information on current_dir and set_current_dir

Fixes #93598.
2022-02-11 21:48:46 +01:00
Matthias Krüger
ce4df92c8c
Rollup merge of #90955 - JohnTitor:os-error-123-as-invalid-input, r=m-ou-se
Rename `FilenameTooLong` to `InvalidFilename` and also use it for Windows' `ERROR_INVALID_NAME`

Address https://github.com/rust-lang/rust/issues/90940#issuecomment-970157931
`ERROR_INVALID_NAME` (i.e. "The filename, directory name, or volume label syntax is incorrect") happens if we pass an invalid filename, directory name, or label syntax, so mapping as `InvalidInput` is reasonable to me.
2022-02-11 21:48:42 +01:00
bors
e789f3a3a3 Auto merge of #90271 - adamgemmell:dev/feat-detect-stabilise, r=Amanieu
Stabilise `is_aarch64_feature_detected!` under `simd_aarch64` feature

Initial implementation, looking for feedback on the approach here. https://github.com/rust-lang/rust/issues/86941

One point I noticed was that I haven't seen different "since" versions for the same feature - does this mean that other features can't be added to to the `simd_aarch64` feature once this is in stable? If so it might need a more specific name.

r? `@Amanieu`
2022-02-11 20:41:51 +00:00
Guillaume Gomez
22a24c98d3 Add missing platform-specific information on current_dir and set_current_dir 2022-02-11 16:33:02 +01:00
Dan Gohman
1f98ef7793 Implement AsFd for &T and &mut T.
Add implementations of `AsFd` for `&T` and `&mut T`, so that users can
write code like this:

```rust
pub fn fchown<F: AsFd>(fd: F, uid: Option<u32>, gid: Option<u32>) -> io::Result<()> {
```

with `fd: F` rather than `fd: &F`.

And similar for `AsHandle` and `AsSocket` on Windows.

Also, adjust the `fchown` example to pass the file by reference. The
code can work either way now, but passing by reference is more likely
to be what users will want to do.

This is an alternative to #93869, and is a simpler way to achieve the
same goals: users don't need to pass borrowed-`BorrowedFd` arguments,
and it prevents a pitfall in the case where users write `fd: F` instead
of `fd: &F`.
2022-02-10 18:26:12 -08:00
Adam Gemmell
102a0ffd37 Move is_aarch64_feature_detected! to simd_aarch64 feature and stabilise 2022-02-10 15:24:13 +00:00
Yuki Okushi
a898b31662
Rename to InvalidFilename 2022-02-10 23:49:27 +09:00
Josh Triplett
861f3c70a2
Fix description of FilenameInvalid
Co-authored-by: Mara Bos <m-ou.se@m-ou.se>
2022-02-10 23:42:27 +09:00
Yuki Okushi
cc9407924d
Map ERROR_INVALID_NAME to FilenameInvalid 2022-02-10 23:42:27 +09:00
Yuki Okushi
755e475c8b
Rename FilenameTooLong to FilenameInvalid 2022-02-10 23:42:26 +09:00
Yuki Okushi
1115f15e1c
windows: Map ERROR_INVALID_NAME as InvalidInput 2022-02-10 23:42:23 +09:00
Matthias Krüger
8c60f44877
Rollup merge of #93843 - solid-rs:fix-kmc-solid-condvar, r=m-ou-se
kmc-solid: Fix wait queue manipulation errors in the `Condvar` implementation

This PR fixes a number of bugs in the `Condvar` wait queue implementation used by the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets. These bugs can occur when there are multiple threads waiting on the same `Condvar` and sometimes manifest as an `unwrap` failure.
2022-02-10 12:10:02 +01:00
Tomoaki Kawada
1d180caf1a kmc-solid: Wait queue should be sorted in the descending order of task priorities
In ITRON, lower priority values mean higher priorities.
2022-02-10 11:35:37 +09:00
Tomoaki Kawada
bdc9508bb6 kmc-solid: Fix wait queue manipulation errors in the Condvar implementation 2022-02-10 10:21:39 +09:00
Amanieu d'Antras
7b8f6ac5ab Bump compiler-builtins to 0.1.69 2022-02-09 21:03:13 +00:00
Amanieu d'Antras
49d4823112 Stabilize cfg_target_has_atomic
Closes #32976
2022-02-09 18:45:44 +00:00
Yuki Okushi
ec2fd8a35f
Rollup merge of #93445 - yaahc:exitcode-constructor, r=dtolnay
Add From<u8> for ExitCode

This should cover a mostly cross-platform subset of supported exit codes.

We decided to stick with `u8` initially since its the common subset between all platforms that we support (excluding wasm which I think only works with `true` or `false`). Posix is supposed to take i32s, but in practice many unix platforms mask out all but the low 8 bits or in some cases the 8-15th bits. Windows takes a u32 instead of an i32. Bourne-compatible shells also report signals as exitcode 128 + `signal_no`, so there's some ambiguity there when returning exit codes > 127, but it is possible to disambiguate them on the other side so we decided against restricting the possible codes further than to `u8`.

## Related

- Detailed analysis of exit code support on various platforms: https://internals.rust-lang.org/t/mini-pre-rfc-redesigning-process-exitstatus/5426
- https://github.com/rust-lang/rust/issues/48711
- https://github.com/rust-lang/rust/issues/43301
- https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Termination.2FExit.20Status.20Stabilization
2022-02-09 14:12:17 +09:00
Matthias Krüger
9cb39a6083
Rollup merge of #93206 - ChrisDenton:ntopenfile, r=nagisa
Use `NtCreateFile` instead of `NtOpenFile` to open a file

Generally the internal `Nt*` functions should be avoided but when we do need to use one we should stick to the most commonly used for the job. To that end, this PR replaces `NtOpenFile` with `NtCreateFile`.

NOTE: The initial version of this comment hypothesised that this may help with some recent false positives from malware scanners. This hypothesis proved wrong. Sorry for the distraction.
2022-02-08 16:40:49 +01:00
Chris Denton
81cc3afe20
Fix absolute issues 2022-02-08 14:57:35 +00:00
Chris Denton
d59d32c4f1
std::path::absolute 2022-02-08 14:57:34 +00:00
Jane Lusby
4c5a36e2d1 fix exclusive range error 2022-02-07 12:45:36 -08:00
bors
734368a200 Auto merge of #87869 - thomcc:skinny-io-error, r=yaahc
Make io::Error use 64 bits on targets with 64 bit pointers.

I've wanted this for a long time, but didn't see a good way to do it without having extra allocation. When looking at it yesterday, it was more clear what to do for some reason.

This approach avoids any additional allocations, and reduces the size by half (8 bytes, down from 16). AFAICT it doesn't come additional runtime cost, and the compiler seems to do a better job with code using it.

Additionally, this `io::Error` has a niche (still), so `io::Result<()>` is *also* 64 bits (8 bytes, down from 16), and `io::Result<usize>` (used for lots of io trait functions) is 2x64 bits (16 bytes, down from 24 — this means on x86_64 it can use the nice rax/rdx 2-reg struct return). More generally, it shaves a whole 64 bit integer register off of the size of basically any `io::Result<()>`.

(For clarity: Improving `io::Result` (rather than io::Error) was most of the motivation for this)

On 32 bit (or other non-64bit) targets we still use something equivalent the old repr — I don't think think there's improving it, since one of the fields it stores is a `i32`, so we can't get below that, and it's already about as close as we can get to it.

---

### Isn't Pointer Tagging Dodgy?

The details of the layout, and why its implemented the way it is, are explained in the header comment of library/std/src/io/error/repr_bitpacked.rs. There's probably more details than there need to be, but I didn't trim it down that much, since there's a lot of stuff I did deliberately, that might have not seemed that way.

There's actually only one variant holding a pointer which gets tagged. This one is the (holder for the) user-provided error.

I believe the scheme used to tag it is not UB, and that it preserves pointer provenance (even though often pointer tagging does not) because the tagging operation is just `core::ptr::add`, and untagging is `core::ptr::sub`. The result of both operations lands inside the original allocation, so it would follow the safety contract of `core::ptr::{add,sub}`.

The other pointer this had to encode is not tagged — or rather, the tagged repr is equivalent to untagged (it's tagged with 0b00, and has >=4b alignment, so we can reuse the bottom bits). And the other variants we encode are just integers, which (which can be untagged using bitwise operations without worry — they're integers).

CC `@RalfJung` for the stuff in repr_bitpacked.rs, as my comments are informed by a lot of the UCG work, but it's possible I missed something or got it wrong (even if the implementation is okay, there are parts of the header comment that says things like "We can't do $x" which could be false).

---

### Why So Many Changes?

The repr change was mostly internal, but changed one widely used API: I had to switch how `io::Error::new_const` works.

This required switching `io::Error::new_const` to take the full message data (including the kind) as a `&'static`, rather than just the string. This would have been really tedious, but I made a macro that made it much simpler, but it was a wide change since `io::Error::new_const` is used everywhere.

This included changing files for a lot of targets I don't have easy access to (SGX? Haiku? Windows? Who has heard of these things), so I expect there to be spottiness in CI initially, unless luck is on my side.

Anyway this large only tangentially-related change is all in the first commit (although that commit also pulls the previous repr out into its own file), whereas the packing stuff is all in commit 2.

---

P.S. I haven't looked at all of this since writing it, and will do a pass over it again later, sorry for any obvious typos or w/e. I also definitely repeat myself in comments and such.

(It probably could use more tests too. I did some basic testing, and made it so we `debug_assert!` in cases the decode isn't what we encoded, but I don't know the degree which I can assume libstd's testing of IO would exercise this. That is: it wouldn't be surprising to me if libstds IO testing were minimal, especially around error cases, although I have no idea).
2022-02-07 20:32:56 +00:00
Jane Lusby
cf4ac6b1e1
Add From<u8> for ExitCode
This should cover a mostly cross-platform subset of supported exit codes.
2022-02-06 12:43:12 -08:00
Inteon
afb7a502f6
rewrite from_bytes_with_nul to match code style in from_vec_with_nul
Signed-off-by: Inteon <42113979+inteon@users.noreply.github.com>
2022-02-06 20:07:03 +01:00
The 8472
45082b077b Fix hashing for windows paths containing a CurDir component
* the logic only checked for / but not for \
* verbatim paths shouldn't skip items at all since they don't get normalized
* the extra branches get optimized out on unix since is_sep_byte is a trivial comparison and is_verbatim is always-false
* tests lacked windows coverage for these cases

That lead to equal paths not having equal hashes and to unnecessary collisions.
2022-02-06 11:43:50 +01:00
Thom Chiovoloni
9cbe99488b
Add more tests for io::Error packing, and fix some comments that weren't quite accurate anymore 2022-02-04 23:15:02 -08:00
Thom Chiovoloni
a17a896d09
Update documentation somewhat 2022-02-04 18:47:31 -08:00
Thom Chiovoloni
e98c7f7209
Use wrapping pointer arithmetic in the bitpacked io::Error 2022-02-04 18:47:31 -08:00
Thom Chiovoloni
f950edbef7
Elaborate some in the documentation and respond to some review comments 2022-02-04 18:47:31 -08:00
Thom Chiovoloni
06edf082c3
Update library/std/src/io/error/repr_bitpacked.rs
Co-authored-by: the8472 <the8472@users.noreply.github.com>
2022-02-04 18:47:30 -08:00
Thom Chiovoloni
9f7eb7d473
Fix comment typos noticed by code review.
Co-authored-by: Ralf Jung <post@ralfj.de>
2022-02-04 18:47:30 -08:00
Thom Chiovoloni
6b068437cb
Address address comments, improve comments slightly 2022-02-04 18:47:30 -08:00
Thom Chiovoloni
ea211695bf
Optimize io::error::Repr layout on 64 bit targets. 2022-02-04 18:47:30 -08:00
Thom Chiovoloni
554918e311
Hide Repr details from io::Error, and rework io::Error::new_const. 2022-02-04 18:47:29 -08:00
Matthias Krüger
af2886eef9
Rollup merge of #93495 - solid-rs:fix-kmc-solid-rtc-month, r=yaahc
kmc-solid: Fix off-by-one error in `SystemTime::now`

Fixes a miscalculation of `SystemTime`  on the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.

Unlike the identically-named libc counterpart `tm::tm_mon`, `SOLID_RTC_TIME::tm_mon` contains a 1-based month number.
2022-02-04 18:42:14 +01:00
Matthias Krüger
f070e0b5a6
Rollup merge of #93555 - ChrisDenton:fs-try-exists-doc, r=Mark-Simulacrum
Link `try_exists` docs to `Path::exists`

Links to the existing `Path::exists` method from both `std::Path::try_exists` and `std::fs:try_exists`.

Tracking issue for `path_try_exists`: #83186
2022-02-04 14:59:02 +01:00
bors
796bf14f2e Auto merge of #93146 - workingjubilee:use-std-simd, r=Mark-Simulacrum
pub use std::simd::StdFloat;

Syncs portable-simd up to commit rust-lang/portable-simd@03f6fbb21e,
Diff: 533f0fc81a...03f6fbb21e

This sync requires a little bit more legwork because it also introduces a trait into `std::simd`, so that it is no longer simply a reexport of `core::simd`. Out of simple-minded consistency and to allow more options, I replicated the pattern for the way `core::simd` is integrated in the first place, however this is not necessary if it doesn't acquire any interdependencies inside `std`: it could be a simple crate reexport. I just don't know yet if that will happen or not.

To summarize other misc changes:
- Shifts no longer panic, now wrap on too-large shifts (like `Simd` integers usually do!)
- mask16x32 will now be many i16s, not many i32s... 🙃
- `#[must_use]` is spread around generously
- Adjusts division, float min/max, and `Mask::{from,to}_array` internally to be faster
- Adds the much-requested `Simd::cast::<U>` function (equivalent to `simd.to_array().map(|lane| lane as U)`)
2022-02-03 09:15:16 +00:00
bors
b3800860e1 Auto merge of #93101 - Mark-Simulacrum:library-backtrace, r=yaahc
Support configuring whether to capture backtraces at runtime

Tracking issue: https://github.com/rust-lang/rust/issues/93346

This adds a new API to the `std::panic` module which configures whether and how the default panic hook will emit a backtrace when a panic occurs.

After discussion with `@yaahc` on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/backtrace.20lib.20vs.2E.20panic), this PR chooses to avoid adjusting or seeking to provide a similar API for the (currently unstable) std::backtrace API. It seems likely that the users of that API may wish to expose more specific settings rather than just a global one (e.g., emulating the `env_logger`, `tracing` per-module configuration) to avoid the cost of capture in hot code. The API added here could plausibly be copied and/or re-exported directly from std::backtrace relatively easily, but I don't think that's the right call as of now.

```rust
mod panic {
    #[derive(Copy, Clone, Debug, PartialEq, Eq)]
    #[non_exhaustive]
    pub enum BacktraceStyle {
        Short,
        Full,
        Off,
    }
    fn set_backtrace_style(BacktraceStyle);
    fn get_backtrace_style() -> Option<BacktraceStyle>;
}
```

Several unresolved questions:

* Do we need to move to a thread-local or otherwise more customizable strategy for whether to capture backtraces? See [this comment](https://github.com/rust-lang/rust/pull/79085#issuecomment-727845826) for some potential use cases for this.
   * Proposed answer: no, leave this for third-party hooks.
* Bikeshed on naming of all the options, as usual.
* Should BacktraceStyle be moved into `std::backtrace`?
   * It's already somewhat annoying to import and/or re-type the `std::panic::` prefix necessary to use these APIs, probably adding a second module to the mix isn't worth it.

Note that PR #79085 proposed a much simpler API, but particularly in light of the desire to fully replace setting environment variables via `env::set_var` to control the backtrace API, a more complete API seems preferable. This PR likely subsumes that one.
2022-02-02 22:03:23 +00:00
Mark Rousskov
85930c8f44 Configure panic hook backtrace behavior 2022-02-02 13:46:42 -05:00