Commit Graph

265981 Commits

Author SHA1 Message Date
bors 8c2c9a9ef5 Auto merge of #130401 - matthiaskrgr:rollup-fri2j58, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #129439 (Implement feature `string_from_utf8_lossy_owned` for lossy conversion from `Vec<u8>` to `String` methods)
 - #129828 (miri: treat non-memory local variables properly for data race detection)
 - #130110 (make dist vendoring configurable)
 - #130293 (Fix lint levels not getting overridden by attrs on `Stmt` nodes)
 - #130342 (interpret, miri: fix dealing with overflow during slice indexing and allocation)

Failed merges:

 - #130394 (const: don't ICE when encountering a mutable ref to immutable memory)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-15 15:05:29 +00:00
Matthias Krüger 96195a5e24
Rollup merge of #130342 - RalfJung:slice-idx-overflow, r=saethlin
interpret, miri: fix dealing with overflow during slice indexing and allocation

This is mostly to fix https://github.com/rust-lang/rust/issues/130284.

I then realized we're using somewhat sketchy arguments for a similar multiplication in `copy`/`copy_nonoverlapping`/`write_bytes`,  so I made them all share the same function that checks exactly the right thing. (The intrinsics would previously fail on allocations larger than `1 << 47` bytes... which are theoretically possible maybe? Anyway it seems conceptually wrong to use any other bound than `isize::MAX` here.)
2024-09-15 16:01:38 +02:00
Matthias Krüger 18a93ca65e
Rollup merge of #130293 - gurry:130142-lint-level-issue, r=cjgillot
Fix lint levels not getting overridden by attrs on `Stmt` nodes

Fixes #130142. See comments on the issue for context.

r? `@cjgillot`
2024-09-15 16:01:37 +02:00
Matthias Krüger 8ad52ddf9e
Rollup merge of #130110 - onur-ozkan:configurable-dist-vendor, r=Kobzol,Mark-Simulacrum
make dist vendoring configurable

Adds a new option `dist.vendor` which allows people to decide whether to vendor dependencies for their custom distribution tarball builds. Note that our builds will not be affected, as the default for this option is the same as the previous vendoring condition from bootstrap.
2024-09-15 16:01:37 +02:00
Matthias Krüger 6ac598a472
Rollup merge of #129828 - RalfJung:miri-data-race, r=saethlin
miri: treat non-memory local variables properly for data race detection

Fixes https://github.com/rust-lang/miri/issues/3242

Miri has an optimization where some local variables are not represented in memory until something forces them to be stored in memory (most notably, creating a pointer/reference to the local will do that). However, for a subsystem triggering on memory accesses -- such as the data race detector -- this means that the memory access seems to happen only when the local is moved to memory, instead of at the time that it actually happens. This can lead to UB reports in programs that do not actually have UB.

This PR fixes that by adding machine hooks for reads and writes to such efficiently represented local variables. The data race system tracks those very similar to how it would track reads and writes to addressable memory, and when a local is moved to memory, the clocks get overwritten with the information stored for the local.
2024-09-15 16:01:36 +02:00
Matthias Krüger df3cf91b63
Rollup merge of #129439 - okaneco:vec_string_lossy, r=Noratrieb
Implement feature `string_from_utf8_lossy_owned` for lossy conversion from `Vec<u8>` to `String` methods

Accepted ACP: https://github.com/rust-lang/libs-team/issues/116
Tracking issue: #129436

Implement feature for lossily converting from `Vec<u8>` to `String`
- Add `String::from_utf8_lossy_owned`
- Add `FromUtf8Error::into_utf8_lossy`

---
Related to #64727, but unsure whether to mark it "fixed" by this PR.
That issue partly asks for in-place replacement of the original allocation. We fulfill the other half of that request with these functions.

closes #64727
2024-09-15 16:01:36 +02:00
Chris Denton 7223fd8085
Add system libs when cross compiling for Windows 2024-09-15 12:38:55 +00:00
Ralf Jung 339f68bd6c use early return for race_detecting() logic 2024-09-15 13:25:26 +02:00
bors dde7d6649e Auto merge of #130390 - matthiaskrgr:rollup-evbfwe2, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #129195 (Stabilize `&mut` (and `*mut`) as well as `&Cell` (and `*const Cell`) in const)
 - #130118 (move Option::unwrap_unchecked into const_option feature gate)
 - #130295 (Fix target-cpu fpu features on Armv8-R.)
 - #130371 (Correctly account for niche-optimized tags in rustc_transmute)
 - #130381 (library: Compute Rust exception class from its string repr)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-15 11:19:28 +00:00
bors 7d8ee71274 Auto merge of #3889 - RalfJung:android-pthread, r=RalfJung
add Android pthread support

Also extend what we test on Solarish / FreeBSD, turns out a few more things are working.
2024-09-15 10:48:17 +00:00
Ralf Jung 5f3bec427c we can test more things on Solarish, and update its status in the README 2024-09-15 12:45:30 +02:00
Ralf Jung f394c6ce8c test std::time APIs on FreeBSD and Solarish 2024-09-15 12:45:30 +02:00
Ralf Jung 8ee38bf230 add Android pthread support 2024-09-15 12:45:29 +02:00
Ralf Jung cb445d0188 make pthread-threadname nicer with cfg-if 2024-09-15 12:45:29 +02:00
bors 75921d2ca4 Auto merge of #3886 - RalfJung:freebsd-pthread, r=RalfJung
support pthread primitives on FreeBSD

Fixes https://github.com/rust-lang/miri/issues/3571: makes out pthread implementation support FreeBSD.

FreeBSD sets PHTREAD_MUTEX_DEFAULT == PHTREAD_MUTEX_ERRORCK, so the logic for handling "default vs explicitly set mutex kind" had to be adjusted.

The rest is just some general cleanup of the pthread logic, and I realized that we can enable the std::sync tests on Solarish.
2024-09-15 10:10:14 +00:00
Ralf Jung 2ed91881ef enable std::sync tests on Solarish 2024-09-15 12:05:23 +02:00
Ralf Jung 2cdf5f7e69 move two tests to a better location 2024-09-15 12:03:20 +02:00
Ralf Jung 4000027084 pthread: add FreeBSD, remove PTHREAD_MUTEX_NORMAL_FLAG hack
On FreeBSD, DEFAULT maps to ERRORCK. This clashes with the existing PTHREAD_MUTEX_NORMAL_FLAG:
hack so we replace it by a different hack that works better cross-platform.

Also fix a case of "accidental early UB" in a UB test -- pthread_mutexattr_t must be initialized.
2024-09-15 11:58:51 +02:00
Matthias Krüger 729aa49d0f
Rollup merge of #130381 - workingjubilee:sometimes-code-really-is-self-descriptive, r=Noratrieb
library: Compute Rust exception class from its string repr

Noticed this awkwardness while scanning through the code. I think we can do better than that.
2024-09-15 11:55:47 +02:00
Matthias Krüger 9ed667f8ed
Rollup merge of #130371 - saethlin:transmutability-enum-ice, r=compiler-errors
Correctly account for niche-optimized tags in rustc_transmute

This is a bit hacky, but it fixes the ICE and makes it possible to run the safe transmute check on every `mem::transmute` check we instantiate. I want to write a lint that needs to do that, but this stands well on its own.

cc `@jswrenn` here's the fix I alluded to yesterday :)

Fixes #123693
2024-09-15 11:55:47 +02:00
Matthias Krüger 3225bd5f96
Rollup merge of #130295 - chrisnc:armv8r-feature-fix, r=workingjubilee
Fix target-cpu fpu features on Armv8-R.

This is a follow-up to #123159, but applied to Armv8-R.

This required https://github.com/llvm/llvm-project/pull/88287 to work properly. Now that this change exists in rustc's llvm, we can fix Armv8-R's default fpu features. In Armv8-R's case, the default features from LLVM for floating-point are sufficient, because there is no integer-only variant of this architecture.
2024-09-15 11:55:46 +02:00
Matthias Krüger e267534b07
Rollup merge of #130118 - RalfJung:unwrap_unchecked, r=Noratrieb
move Option::unwrap_unchecked into const_option feature gate

That's where `unwrap` and `expect` are so IMO it makes more sense to group them together.

Part of #91930, #67441
2024-09-15 11:55:46 +02:00
Matthias Krüger 011289c9d4
Rollup merge of #129195 - RalfJung:const-mut-refs, r=fee1-dead
Stabilize `&mut` (and `*mut`) as well as `&Cell` (and `*const Cell`) in const

This stabilizes `const_mut_refs` and `const_refs_to_cell`. That allows a bunch of new things in const contexts:
- Mentioning `&mut` types
- Creating `&mut` and `*mut` values
- Creating `&T` and `*const T` values where `T` contains interior mutability
- Dereferencing `&mut` and `*mut` values (both for reads and writes)

The same rules as at runtime apply: mutating immutable data is UB. This includes mutation through pointers derived from shared references; the following is diagnosed with a hard error:
```rust
#[allow(invalid_reference_casting)]
const _: () = {
    let mut val = 15;
    let ptr = &val as *const i32 as *mut i32;
    unsafe { *ptr = 16; }
};
```

The main limitation that is enforced is that the final value of a const (or non-`mut` static) may not contain `&mut` values nor interior mutable `&` values. This is necessary because the memory those references point to becomes *read-only* when the constant is done computing, so (interior) mutable references to such memory would be pretty dangerous. We take a multi-layered approach here to ensuring no mutable references escape the initializer expression:
- A static analysis rejects (interior) mutable references when the referee looks like it may outlive the current MIR body.
- To be extra sure, this static check is complemented by a "safety net" of dynamic checks. ("Dynamic" in the sense of "running during/after const-evaluation, e.g. at runtime of this code" -- in contrast to "static" which works entirely by looking at the MIR without evaluating it.)
  - After the final value is computed, we do a type-driven traversal of the entire value, and if we find any `&mut` or interior-mutable `&` we error out.
  - However, the type-driven traversal cannot traverse `union` or raw pointers, so there is a second dynamic check where if the final value of the const contains any pointer that was not derived from a shared reference, we complain. This is currently a future-compat lint, but will become an ICE in #128543. On the off-chance that it's actually possible to trigger this lint on stable, I'd prefer if we could make it an ICE before stabilizing const_mut_refs, but it's not a hard blocker. This part of the "safety net" is only active for mutable references since with shared references, it has false positives.

Altogether this should prevent people from leaking (interior) mutable references out of the const initializer.

While updating the tests I learned that surprisingly, this code gets rejected:
```rust
const _: Vec<i32> = {
    let mut x = Vec::<i32>::new(); //~ ERROR destructor of `Vec<i32>` cannot be evaluated at compile-time
    let r = &mut x;
    let y = x;
    y
};
```
The analysis that rejects destructors in `const` is very conservative when it sees an `&mut` being created to `x`, and then considers `x` to be always live. See [here](https://github.com/rust-lang/rust/issues/65394#issuecomment-541499219) for a longer explanation. `const_precise_live_drops` will solve this, so I consider this problem to be tracked by https://github.com/rust-lang/rust/issues/73255.

Cc `@rust-lang/wg-const-eval` `@rust-lang/lang`
Cc https://github.com/rust-lang/rust/issues/57349
Cc https://github.com/rust-lang/rust/issues/80384
2024-09-15 11:55:45 +02:00
onur-ozkan 13542cdb80 add change entry for `dist.vendor`
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-09-15 12:24:07 +03:00
onur-ozkan 9778f25ea5 document `dist.vendor` in `config.example.toml`
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-09-15 12:23:05 +03:00
onur-ozkan 741b3164d8 make dist vendoring configurable
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-09-15 12:23:02 +03:00
bors 1ae268816c Auto merge of #130148 - RalfJung:interpret-get_ptr_alloc_mut, r=saethlin
interpret: get_ptr_alloc_mut: lookup allocation only once

I don't think this will make a big perf difference, but it makes this function symmetric with `get_ptr_alloc` -- and it's always nice to successfully solve a borrow checker puzzle like this. ;)
2024-09-15 08:59:26 +00:00
Ralf Jung efdc01bfee unix/sync: cleanup 2024-09-15 10:55:03 +02:00
Ralf Jung f16f09db63 interpret: get_ptr_alloc_mut: lookup allocation only once 2024-09-15 10:21:19 +02:00
Ralf Jung 49316f871c also stabilize const_refs_to_cell 2024-09-15 10:20:47 +02:00
Ralf Jung 544a6a7df3 const_refs_to_cell: dont let mutable references sneak past the interior mutability check 2024-09-15 09:51:34 +02:00
Ralf Jung 9ad5728593 clean up const checking of mutable references 2024-09-15 09:51:34 +02:00
Ralf Jung 3175cc2814 stabilize const_mut_refs 2024-09-15 09:51:32 +02:00
Ralf Jung 268f6cf558 also use compute_size_in_bytes for relevant multiplications in Miri 2024-09-15 09:21:43 +02:00
Jubilee Young 7b02be8abc compiler: Document AbiAndPrefAlign 2024-09-14 22:45:25 -07:00
bors bc486f31a6 Auto merge of #130379 - Zalathar:rollup-wpmcnql, r=Zalathar
Rollup of 6 pull requests

Successful merges:

 - #130042 (properly handle EOF in BufReader::peek)
 - #130061 (Add `NonNull` convenience methods to `Box` and `Vec`)
 - #130202 (set `download-ci-llvm = true` by default on "library" and "tools" profiles)
 - #130214 (MaybeUninit::zeroed: mention that padding is not zeroed)
 - #130353 (Make some lint doctests compatible with `--stage=0`)
 - #130370 (unstable-book: `trait_upcasting` example should not have `#![allow(incomplete_features)]`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-09-15 05:15:25 +00:00
Chris Copeland 1a0ba01177
Fix target-cpu fpu features on Armv8-R.
This is a follow-up to #123159, but applied to Armv8-R.

This required https://github.com/llvm/llvm-project/pull/88287 to work
properly. Now that this change exists in rustc's llvm, we can fix
Armv8-R's default fpu features. In Armv8-R's case, the default features
from LLVM for floating-point are sufficient, because there is no
integer-only variant of this architecture.
2024-09-14 21:39:23 -07:00
Jubilee Young fef7373d13 library: Compute Rust exception class from its string repr 2024-09-14 20:26:37 -07:00
Zalathar 2a3e17c6d5 coverage: Remove unnecessary `bcb_successors`
Given that we directly access the graph predecessors/successors in so many
other places, and sometimes must do so to satisfy the borrow checker, there is
little value in having this trivial helper method.
2024-09-15 12:51:57 +10:00
Zalathar 669327f575 coverage: Replace `bcb_has_multiple_in_edges` with `sole_predecessor`
This does a better job of expressing the special cases that occur when a node
in the coverage graph has exactly one in-edge.
2024-09-15 12:51:57 +10:00
Zalathar e24310b07c coverage: Simplify choosing an out-edge to be given a counter expression
By building the list of candidate edges up-front, and making the
candidate-selection method fallible, we can remove a few pieces of awkward
code.
2024-09-15 12:51:57 +10:00
Zalathar 771659d264 coverage: Track whether a node's count is the sum of its out-edges 2024-09-15 12:51:57 +10:00
Zalathar 6251d16e4c coverage: Streamline creation of physical edge counters 2024-09-15 12:51:57 +10:00
Zalathar 7cb85862b9 coverage: Streamline creation of physical node counters
- Look up the node's predecessors only once
- Get rid of some overly verbose logging
- Explain why some nodes need physical counters
- Extract a helper method to create and set a physical node counter
2024-09-15 12:51:56 +10:00
Zalathar 13b814fc17 coverage: Tweak comments in `graph` 2024-09-15 12:25:12 +10:00
Stuart Cook 4b6f838e56
Rollup merge of #130370 - kpreid:patch-2, r=compiler-errors
unstable-book: `trait_upcasting` example should not have `#![allow(incomplete_features)]`

Tracking issue: #65991

`trait_upcasting` is not currently an incomplete feature; therefore examples of its use do not require `#![allow(incomplete_features)]`.
2024-09-15 12:14:58 +10:00
Stuart Cook 12fb8e45c2
Rollup merge of #130353 - Zalathar:lint-zero, r=jieyouxu
Make some lint doctests compatible with `--stage=0`

Currently, running `x test compiler --stage=0` (with `rust.parallel-compiler=false` to avoid other problems) results in two failures, because these lint doctests aren't compatible with the current stage0 compiler.

In theory, the more “correct” solution would be to wrap the opening triple-backtick line in  `#[cfg_attr(not(bootstrap), doc = "..."]`. However, that causes a few practical problems:
- `tidy` doesn't understand that syntax, and miscounts the number of backticks in the comment block.
- `lint-docs` doesn't understand that syntax, and thinks it's trying to declare the lint name.
- Working around the above problems would cause more work and more confusion for whoever does the next bootstrap beta bump.

So instead this PR adds some bootstrap gates inside the individual doctests, which end up producing the desired behaviour, and are straightforward to remove.
2024-09-15 12:14:57 +10:00
Stuart Cook 0648987532
Rollup merge of #130214 - RalfJung:zeroed, r=Mark-Simulacrum
MaybeUninit::zeroed: mention that padding is not zeroed

That should clarify cases like [this](https://github.com/rust-lang/rust/pull/129778#issuecomment-2342542847).
2024-09-15 12:14:56 +10:00
Stuart Cook 36ee8520e8
Rollup merge of #130202 - onur-ozkan:force-ci-llvm-on-default-profiles, r=Mark-Simulacrum
set `download-ci-llvm = true` by default on "library" and "tools" profiles

It's very rare for developers to need to modify LLVM, so "if-unchanged" isn't a good default for "tools" and "library" profiles since it fetches the LLVM submodule to track changes.
2024-09-15 12:14:56 +10:00
Stuart Cook c11505f218
Rollup merge of #130061 - theemathas:box_vec_non_null, r=MarkSimulacrum,workingjubilee
Add `NonNull` convenience methods to `Box` and `Vec`

Implements the ACP: https://github.com/rust-lang/libs-team/issues/418.

The docs for the added methods are mostly copied from the existing methods that use raw pointers instead of `NonNull`.

I'm new to this "contributing to rustc" thing, so I'm sorry if I did something wrong. In particular, I don't know what the process is for creating a new unstable feature. Please advise me if I should do something. Thank you.
2024-09-15 12:14:55 +10:00