Commit Graph

19369 Commits

Author SHA1 Message Date
Matthias Krüger
3ebdd59770 Rollup merge of #141669 - tgross35:float-test-cleanup, r=RalfJung
float: Replace some approximate assertions with exact

As was mentioned at [1], we currently use `assert_approx_eq` for testing
some math functions that guarantee exact results. Replace approximate
assertions with exact ones for the following:

* `ceil`
* `floor`
* `fract`
* `from_bits`
* `mul_add`
* `round_ties_even`
* `round`
* `trunc`

This likely wasn't done in the past to avoid writing out exact decimals
that don't match the intuitive answer (e.g. 1.3 - 1.0 = 0.300...004),
but ensuring our results are accurate seems more important here.

[1]: https://github.com/rust-lang/rust/pull/138087#issuecomment-2842069281

The first commit is a small bit of macro cleanup.

try-job: aarch64-gnu
try-job: x86_64-gnu-aux
2025-05-30 07:01:31 +02:00
Matthias Krüger
ad2d91ce11 Rollup merge of #141507 - RalfJung:atomic-intrinsics, r=bjorn3
atomic_load intrinsic: use const generic parameter for ordering

We have a gazillion intrinsics for the atomics because we encode the ordering into the intrinsic name rather than making it a parameter. This is particularly bad for those operations that take two orderings. Let's fix that!

This PR only converts `load`, to see if there's any feedback that would fundamentally change the strategy we pursue for the const generic intrinsics.

The first two commits are preparation and could be a separate PR if you prefer.

`@BoxyUwU` -- I hope this is a use of const generics that is unlikely to explode? All we need is a const generic of enum type. We could funnel it through an integer if we had to but an enum is obviously nicer...

`@bjorn3` it seems like the cranelift backend entirely ignores the ordering?
2025-05-30 07:01:30 +02:00
bors
1ac1950c33 Auto merge of #141739 - GuillaumeGomez:rollup-ivboqwd, r=GuillaumeGomez
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#137574 (Make `std/src/num` mirror `core/src/num`)
 - rust-lang/rust#141384 (Enable review queue tracking)
 - rust-lang/rust#141448 (A variety of improvements to the codegen backends)
 - rust-lang/rust#141636 (avoid some usages of `&mut P<T>` in AST visitors)
 - rust-lang/rust#141676 (float: Disable `total_cmp` sNaN tests for `f16`)
 - rust-lang/rust#141705 (Add eslint as part of `tidy` run)
 - rust-lang/rust#141715 (Add `loongarch64` with `d` feature to `f32::midpoint` fast path)
 - rust-lang/rust#141723 (Provide secrets to try builds with new bors)
 - rust-lang/rust#141728 (Fix false documentation of FnCtxt::diverges)
 - rust-lang/rust#141729 (resolve target-libdir directly from rustc)
 - rust-lang/rust#141732 (creader: Remove extraenous String::clone)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-29 23:02:31 +00:00
Trevor Gross
70cce1c762 float: Use assert_biteq! where possible
`assert_eq!` ignores the sign of zero, but for any tests involving zeros
we do care about this sign. Replace `assert_eq!` with `assert_biteq!`
everywhere possible for float tests to ensure we don't miss this.
`assert_biteq!` is also updated to check equality on non-NaNs, to catch
the unlikely case that bitwise equality works but our `==`
implementation is broken.

There is one notable output change: we were asserting that
`(-0.0).fract()` and `(-1.0).fract()` both return -0.0, but both
actually return +0.0.
2025-05-29 21:13:26 +00:00
Trevor Gross
5446ba3c2d float: Enable some f16 and f128 rounding tests on miri
The rounding tests are now supported, so there is no longer any reason
to skip these.
2025-05-29 21:13:26 +00:00
Trevor Gross
9907c5a806 float: Replace some approximate assertions with exact
As was mentioned at [1], we currently use `assert_approx_eq` for testing
some math functions that guarantee exact results. Replace approximate
assertions with exact ones for the following:

* `ceil`
* `floor`
* `fract`
* `from_bits`
* `mul_add`
* `round_ties_even`
* `round`
* `trunc`

This likely wasn't done in the past to avoid writing out exact decimals
that don't match the intuitive answer (e.g. 1.3 - 1.0 = 0.300...004),
but ensuring our results are accurate seems more important here.

[1]: https://github.com/rust-lang/rust/pull/138087#issuecomment-2842069281
2025-05-29 21:13:26 +00:00
Trevor Gross
6a79b272ba float: Use a shared assert_biteq! macro for tests
Clean up the separate `assert_f{16,32,64,128}` macros with a single
`assert_biteq!` macro that works for all float widths.
2025-05-29 21:13:26 +00:00
Guillaume Gomez
8c708a473d Rollup merge of #141715 - heiher:loong64-f32-midpoint, r=the8472
Add `loongarch64` with `d` feature to `f32::midpoint` fast path

This patch enables the optimized implementation of `f32::midpoint` for `loongarch64` targets that support the `d`feature. Targets with reliable 64-bit float support can safely use the faster and more accurate computation via `f64`, avoiding the fallback branchy version.
2025-05-29 17:03:01 +02:00
Guillaume Gomez
cb7efc0cbd Rollup merge of #141676 - tgross35:f16-disable-total-cmp, r=workingjubilee
float: Disable `total_cmp` sNaN tests for `f16`

There is an LLVM bug with lowering of basic `f16` operations that mean a round trip via `__extendhfsf2` and `__truncsfhf2` may happen for simple `abs` calls or bitcasts [1]. This is problematic because the round trip quiets signaling NaNs. For most operations this is acceptable, but it is causing `total_cmp` tests to fail unless optimizations are enabled.

Disable `total_cmp` tests involving signaling NaNs until this issue is resolved.

Fixes: https://github.com/rust-lang/rustc_codegen_cranelift/issues/1578
Fixes: https://github.com/rust-lang/rust/issues/141503

[1]: https://github.com/llvm/llvm-project/issues/104915
2025-05-29 17:03:00 +02:00
Trevor Gross
a5f3b1e5df Make std/src/num mirror core/src/num
The float modules in `std` are currently top-level but for `core`, they
are nested within the `num` directory and referenced by `#[path = ...]`.
For consistency, adjust `std` to use the same structure as `core`.

Also change the `f16` and `f128` gates from outer attributes to inner
attributes like `core` has.
2025-05-29 13:10:32 +00:00
bors
13718eb788 Auto merge of #141595 - bjorn3:rustc_no_sysroot_proc_macro, r=onur-ozkan
Do not get proc_macro from the sysroot in rustc

With the stage0 refactor the proc_macro version found in the sysroot will no longer always match the proc_macro version that proc-macros get compiled with by the rustc executable that uses this proc_macro. This will cause problems as soon as the ABI of the bridge gets changed to implement new features or change the way existing features work.

To fix this, this commit changes rustc crates to depend directly on the local version of proc_macro which will also be used in the sysroot that rustc will build.
2025-05-29 12:07:53 +00:00
bors
8afd71079a Auto merge of #141717 - jhpratt:rollup-neu8nzl, r=jhpratt
Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#138285 (Stabilize `repr128`)
 - rust-lang/rust#139994 (add `CStr::display`)
 - rust-lang/rust#141571 (coretests: extend and simplify float tests)
 - rust-lang/rust#141656 (CI: Add cargo tests to aarch64-apple-darwin)

Failed merges:

 - rust-lang/rust#141430 (remove `visit_clobber` and move `DummyAstNode` to `rustc_expand`)
 - rust-lang/rust#141636 (avoid some usages of `&mut P<T>` in AST visitors)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-29 08:53:27 +00:00
Jacob Pratt
bf1343b963 Rollup merge of #141571 - RalfJung:float-tests, r=tgross35
coretests: extend and simplify float tests

Also de-duplicate tests by removing a ui test that duplicates the tests in core.
r? `@tgross35`
2025-05-29 04:50:47 +02:00
Jacob Pratt
ba042d7cb1 Rollup merge of #139994 - tamird:cstr-display, r=Amanieu
add `CStr::display`

The implementation delegates to `<ByteStr as Display>::fmt`.

Link: https://github.com/rust-lang/libs-team/issues/550
Link: https://github.com/rust-lang/rust/issues/139984.

r? ```@BurntSushi```
cc ```@Darksonn``` ```@tgross35``` ```@ojeda``` ```@joshtriplett```
2025-05-29 04:50:47 +02:00
Jacob Pratt
e7ef07a523 Rollup merge of #141690 - Patrick-6:intercept-mutex, r=m-ou-se
Add `rustc_diagnostic_item` to `sys::Mutex` methods

For an ongoing project for adding a concurrency model checker to Miri we need to be able to intercept locking/unlocking operations on standard library mutexes.

This PR adds diagnostic items to the relevant calls `lock`, `try_lock` and `unlock` for the `sys::Mutex` implementation on the targets we care about.
This PR also makes the internals of `pthread::Mutex` less public, to reduce the chance of anyone locking/unlocking a mutex without going through the intercepted methods.

r? ``@RalfJung``
2025-05-29 04:49:47 +02:00
Jacob Pratt
f4dcb7fad0 Rollup merge of #141687 - RalfJung:atomic_compare_exchange, r=bjorn3
core: unstably expose atomic_compare_exchange so stdarch can use it

Due to https://github.com/rust-lang/stdarch/issues/1655, cleaning up the atomic intrinsics will be a bunch of extra work: stdarch directly calls them [here](8764244589/crates/core_arch/src/x86_64/cmpxchg16b.rs (L58-L74)).

Instead of duplicating that match, stdarch should use what we have in libcore, so let's expose that.

r? `@bjorn3`
2025-05-29 04:49:46 +02:00
Jacob Pratt
1c46b4a4a9 Rollup merge of #141612 - jhpratt:phantom-docs, r=tgross35
Call out possibility of invariant result in variance markers

ref https://github.com/rust-lang/rust/issues/135806#issuecomment-2766191535
2025-05-29 04:49:42 +02:00
Jacob Pratt
6bf4224f68 Rollup merge of #141533 - RalfJung:rintf, r=bjorn3
clean up old rintf leftovers

As usual stdarch needed special treatment due to https://github.com/rust-lang/stdarch/issues/1655, and apparently I forgot to clean up these leftovers here. They can be removed now.
2025-05-29 04:49:41 +02:00
Jacob Pratt
ffdd3b16dc Rollup merge of #141477 - tshepang:patch-1, r=ChrisDenton
Path::with_extension: show that it adds an extension where one did no…

…t exist

I think the times I encountered this, I had to check first if files without extensions were added, since all examples only had files with existing extensions.

Also, this replaced example already has a similar example below.
2025-05-29 04:49:41 +02:00
Jacob Pratt
d9ed86729b Rollup merge of #141104 - PaulDance:fix-win7-test_eq_windows_file_type, r=ChrisDenton
Test(fs): Fix `test_eq_windows_file_type` for Windows 7

Would otherwise fail on:

```
thread 'fs::tests::test_eq_windows_file_type' panicked at library/std/src/test_helpers.rs:53:20:
called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }
```

This came from the read-only attribute set on the test file. In order to fix this, instead of simply disabling the test, the attribute is reset before the test's end so it may still run successfully.

`@rustbot` label T-libs A-filesystem A-testsuite O-windows-7 O-windows-msvc
2025-05-29 04:49:40 +02:00
WANG Rui
b2858f3132 Add loongarch64 with d feature to f32::midpoint fast path
This patch enables the optimized implementation of `f32::midpoint` for
`loongarch64` targets that support the `d`feature. Targets with reliable
64-bit float support can safely use the faster and more accurate computation
via `f64`, avoiding the fallback branchy version.
2025-05-29 09:30:25 +08:00
Ralf Jung
4794ea176b atomic_load intrinsic: use const generic parameter for ordering 2025-05-28 22:57:55 +02:00
Patrick-6
8237107d88 Add comments to diagnostic items 2025-05-28 17:05:45 +02:00
Trevor Gross
7f5f29b663 Rollup merge of #140697 - Sa4dUs:split-autodiff, r=ZuseZ4
Split `autodiff` into `autodiff_forward` and `autodiff_reverse`

This PR splits `#[autodiff]` macro so `#[autodiff(df, Reverse, args)]` would become `#[autodiff_reverse(df, args)]` and `#[autodiff(df, Forward, args)]` would become `#[autodiff_forwad(df, args)]`.
2025-05-28 10:28:08 -04:00
Trevor Gross
5f17779a03 Rollup merge of #140369 - jplatte:mutex-rwlock-data-ptr, r=Amanieu
Add data_ptr method to Mutex and RwLock

Implementation of https://github.com/rust-lang/rust/issues/140368 / https://github.com/rust-lang/libs-team/issues/531.

I tried to write a useful safety section about when it is safe to read or write through the returned pointers, but couldn't come up with something nice. Hoping this PR is still useful without that. I'm happy to add any doc strings other people come up with if needed before merge, of course.

Unresolved questions:

- Return a `LockResult` or not?
- Return `*mut T` like existing APIs (`Cell::as_ptr` / `MaybeUninit::as[_mut]_ptr` / `Vec::as_ptr` / ...) or be more precise and return `NonNull<T>`?
2025-05-28 10:28:07 -04:00
Ralf Jung
2593df8837 core: unstably expose atomic_compare_exchange so stdarch can use it 2025-05-28 15:20:29 +02:00
Patrick-6
149b5b2567 Make pthread Mutex internals less public 2025-05-28 15:13:38 +02:00
Patrick-6
2e99a880e2 Add diagnostic items to sys::Mutex 2025-05-28 15:12:56 +02:00
Paul Mabileau
0dd5722d67 Test(fs): Fix test_eq_windows_file_type for Windows 7
Would otherwise fail on:

```
thread 'fs::tests::test_eq_windows_file_type' panicked at library/std/src/test_helpers.rs:53:20:
called `Result::unwrap()` on an `Err` value: Os { code: 5, kind: PermissionDenied, message: "Access is denied." }
```

This came from the read-only attribute set on the test file. In order to
fix this, instead of simply disabling the test, the attribute is reset
before the test's end so it may still run successfully.

Signed-off-by: Paul Mabileau <paul.mabileau@harfanglab.fr>
2025-05-28 12:06:25 +02:00
Trevor Gross
19fd098446 float: Disable total_cmp sNaN tests for f16
There is an LLVM bug with lowering of basic `f16` operations that mean a
round trip via `__extendhfsf2` and `__truncsfhf2` may happen for simple
`abs` calls or bitcasts [1]. This is problematic because the round trip
quiets signaling NaNs. For most operations this is acceptable, but it is
causing `total_cmp` tests to fail unless optimizations are enabled.

Disable `total_cmp` tests involving signaling NaNs until this issue is
resolved.

Fixes: https://github.com/rust-lang/rustc_codegen_cranelift/issues/1578
Fixes: https://github.com/rust-lang/rust/issues/141503

[1]: https://github.com/llvm/llvm-project/issues/104915
2025-05-28 06:49:04 +00:00
Ralf Jung
e0ff77aea5 coretests: add abs() and copysign() tests, and remove now-unnecessary ui test 2025-05-28 08:32:08 +02:00
Ralf Jung
2a9363e593 coretests: simplify test_float macro to derive more things from the type name 2025-05-28 08:30:14 +02:00
bors
04a67d5a05 Auto merge of #141668 - tgross35:rollup-03gg6lf, r=tgross35
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#140367 (add `asm_cfg`: `#[cfg(...)]` within `asm!`)
 - rust-lang/rust#140894 (Make check-cfg diagnostics work in `#[doc(cfg(..))]`)
 - rust-lang/rust#141252 (gvn: bail out unavoidable non-ssa locals in repeat)
 - rust-lang/rust#141517 (rustdoc: use descriptive tooltip if doctest is conditionally ignored)
 - rust-lang/rust#141551 (Make two transmute-related MIR lints into HIR lint)
 - rust-lang/rust#141591 (ci: fix llvm test coverage)
 - rust-lang/rust#141647 (Bump master `stage0` compiler)
 - rust-lang/rust#141659 (Add `Result::map_or_default` and `Option::map_or_default`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-28 01:20:50 +00:00
Trevor Gross
da61494400 Rollup merge of #141659 - tkr-sh:map-or-default, r=Amanieu
Add `Result::map_or_default` and `Option::map_or_default`

Closes: https://github.com/rust-lang/rust/pull/138068

_This PR has been recreated because of the inactivity of the author (Cf. https://github.com/rust-lang/rust/pull/138068#issuecomment-2912412288)_
2025-05-27 20:28:34 -04:00
bors
be42293944 Auto merge of #129658 - saethlin:spare-a-crumb, r=jhpratt
Add some track_caller info to precondition panics

Currently, when you encounter a precondition check, you'll always get the caller location of the implementation of the precondition checks. But with this PR, you'll be told the location of the invalid call. Which is useful.

I thought of this while looking at https://github.com/rust-lang/rust/pull/129642#issuecomment-2311703898.

The changes to `tests/ui/const*` happen because the const-eval interpreter skips `#[track_caller]` frames in its backtraces.

The perf implications of this are:
* Increased debug binary sizes. The caller_location implementation requires that the additional data we want to display here be stored in const allocations, which are deduplicated but not across crates. There is no impact on optimized build sizes. The panic path and the caller location data get optimized out.
* The compile time hit to opt-incr-patched bitmaps happens because the patch changes the line number of some function calls with precondition checks, causing us to go from 0 dirty CGUs to 1 dirty CGU.
* The other compile time hits are marginal but real, and due to doing a handful of new queries. Adding more useful data isn't completely free.
2025-05-27 22:11:53 +00:00
Matthias Krüger
88b12f3649 Rollup merge of #141312 - cberner:filelock_from, r=joshtriplett
Add From<TryLockError> for io::Error

Adds a `From` impl to make error propagation easier, as discussed in the tracking issue

`TryLockError` is unstable under the "file_lock" feature. The related tracking issue is https://github.com/rust-lang/rust/issues/130994

This PR also cleanups the Windows implementation of `try_lock()` and `try_lock_shared()` as [discussed here](https://github.com/rust-lang/rust/pull/140718#discussion_r2076678485)
2025-05-27 20:57:53 +02:00
tk
eed065958b feat: map_or_default for result and option 2025-05-27 19:47:14 +02:00
bjorn3
026baa1c6f Do not get proc_macro from the sysroot in rustc
With the stage0 refactor the proc_macro version found in the sysroot
will no longer always match the proc_macro version that proc-macros get
compiled with by the rustc executable that uses this proc_macro. This
will cause problems as soon as the ABI of the bridge gets changed to
implement new features or change the way existing features work.

To fix this, this commit changes rustc crates to depend directly on the
local version of proc_macro which will also be used in the sysroot that
rustc will build.
2025-05-27 15:49:28 +00:00
Michael Goulet
fb4cc991c0 Rollup merge of #141582 - RalfJung:cleanup, r=bjorn3
intrinsics, ScalarInt: minor cleanup

Taken out of https://github.com/rust-lang/rust/pull/141507 while we resolve technical disagreements in that PR.

r? ``@bjorn3``
2025-05-27 13:01:39 +02:00
Marcelo Domínguez
c6c2fde737 Minor macro docs fixes 2025-05-26 19:47:42 +00:00
Jacob Pratt
7aef56d9b9 Call out possibility of invariant result 2025-05-26 15:06:36 -04:00
许杰友 Jieyou Xu (Joe)
408dc51f97 Rollup merge of #141516 - bend-n:okay, r=workingjubilee
speed up charsearcher for ascii chars

attempt at fixing rust-lang/rust#82471

this implementation should be valid because ascii characters are always one byte and there are no continuation bytes that overlap with ascii characters

im not completely sure that this is _always_ an improvement but it seems to be an improvement for this case and i dont think it can significantly regress any cases
2025-05-27 01:29:20 +08:00
Jacob Pratt
a49ae1c40f Rollup merge of #141472 - fluiderson:dev, r=workingjubilee
Attempt to improve the `std::fs::create_dir_all` docs related to atomicity

The original paragraph was added in rust-lang/rust#124520. It doesn't match the actual code logic. It says "function returns an error" if "the parent components" _(which also implies directories)_ "have been created already". The code is as follows:

e88e854634/library/std/src/fs.rs (L3146)
e88e854634/library/std/src/fs.rs (L3160)

These lines suppress all errors if any path component is a directory. I've updated the paragraph to mirror this.
2025-05-26 03:38:18 +02:00
Jacob Pratt
8624f9c62f Rollup merge of #140952 - SimonSapin:ascii_whitespace_definition, r=dtolnay
Specify that split_ascii_whitespace uses the same definition as is_ascii_whitespace
2025-05-26 03:38:17 +02:00
Jacob Pratt
9aae60befc Rollup merge of #140936 - teor2345:wtf-surrogate-docs, r=workingjubilee
Clarify WTF-8 safety docs

This PR is a follow-up to PR #140159, which clarifies ~~two things~~:
- the WTF-8 safety comment [was confusing](https://github.com/rust-lang/rust/pull/140159#discussion_r2082766965), either surrogate condition is actually sufficient for safety, both are not required
- ~~the private `os_str::Slice` type name is easily confused with `std::slice`~~

~~Happy to bikeshed the `OsSlice` name, other alternatives are `OsStrSlice` and `StrSlice`. Now it's got a distinct name from `std::slice`, it's easy to search and replace.~~

cc ``@thaliaarchi`` ``@workingjubilee``
2025-05-26 03:38:17 +02:00
Jacob Pratt
6341f4ef23 Rollup merge of #134696 - ChrisDenton:normalize-lexically, r=workingjubilee
Implement `normalize_lexically`

Implements #134694

This is, I think, the most straightforward implementation I could do, which will hopefully more easily allow experimentation if we decide to change the design here.
2025-05-26 03:38:15 +02:00
bendn
245bf503e2 increase perf of charsearcher for single ascii characters 2025-05-26 01:50:13 +07:00
bors
88b3b520e8 Auto merge of #141086 - a1phyr:spec_advance_by, r=jhpratt
Implement `advance_by` via `try_fold` for `Sized` iterators

When `try_fold` is overriden, it is usually easier for compilers to optimize.

Example difference: https://iter.godbolt.org/z/z8cEfnKro
2025-05-25 11:34:43 +00:00
Chris Denton
c299e297ee Implement normalize lexically 2025-05-25 08:11:41 +00:00
Ralf Jung
396c5cafe7 clean up old rintf leftovers 2025-05-25 09:24:28 +02:00