Commit Graph

2135 Commits

Author SHA1 Message Date
Ding Xiang Fei
1576a6d618
Stabilize const_refs_to_static
update tests

fix bitwidth-sensitive stderr output

use build-fail for asm tests
2024-09-26 13:21:15 +02:00
León Orell Valerian Liehr
01a063f9df
Compiler: Rename "object safe" to "dyn compatible" 2024-09-25 13:26:48 +02:00
Lukas Markeffsky
bd31e3ed70 be even more precise about "cast" vs "coercion" 2024-09-24 23:12:02 +02:00
Lukas Markeffsky
46ecb23198 unify dyn* coercions with other pointer coercions 2024-09-24 22:17:55 +02:00
Michael Goulet
ec1ccff8ce
Rollup merge of #130727 - compiler-errors:objects, r=RalfJung
Check vtable projections for validity in miri

Currently, miri does not catch when we transmute `dyn Trait<Assoc = A>` to `dyn Trait<Assoc = B>`. This PR implements such a check, and fixes https://github.com/rust-lang/miri/issues/3905.

To do this, we modify `GlobalAlloc::VTable` to contain the *whole* list of `PolyExistentialPredicate`, and then modify `check_vtable_for_type` to validate the `PolyExistentialProjection`s of the vtable, along with the principal trait that was already being validated.

cc ``@RalfJung``
r? ``@lcnr`` or types

I also tweaked the diagnostics a bit.

---

**Open question:** We don't validate the auto traits. You can transmute `dyn Foo` into `dyn Foo + Send`. Should we check that? We currently have a test that *exercises* this as not being UB:

6c6d210089/src/tools/miri/tests/pass/dyn-upcast.rs (L14-L20)

I'm not actually sure if we ever decided that's actually UB or not 🤔

We could perhaps still check that the underlying type of the object (i.e. the concrete type that was unsized) implements the auto traits, to catch UB like:

```rust
fn main() {
    let x: &dyn Trait = &std::ptr::null_mut::<()>();
    let _: &(dyn Trait + Send) = std::mem::transmute(x);
    //~^ this vtable is not allocated for a type that is `Send`!
}
```
2024-09-23 23:49:12 -04:00
Michael Goulet
702a644b74 Check vtable projections for validity in miri 2024-09-23 19:38:26 -04:00
Ralf Jung
1eb51e717e fix unqualified_local_imports in rustc_const_eval 2024-09-23 11:57:32 +02:00
Michael Goulet
c682aa162b Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
Guillaume Gomez
f40efa44ab
Rollup merge of #130690 - RalfJung:interpret-abi-compat-fixme, r=jieyouxu
interpret: remove outdated FIXME

The rule about `repr(C)` types with compatible fields got removed from the ABI compat docs before they landed, so this FIXME here is no longer correct. (So this is basically a follow-up to https://github.com/rust-lang/rust/pull/130185, doing some more cleanup around deciding not to guarantee ABI compatibility for structurally compatible `repr(C)` types.)
2024-09-22 19:19:15 +02:00
bors
4ae36d906f Auto merge of #130689 - RalfJung:rustc_nonnull_optimization_guaranteed, r=jieyouxu
fix rustc_nonnull_optimization_guaranteed docs

As far as I can tell, even back when this was [added](https://github.com/rust-lang/rust/pull/60300) it never *enabled* any optimizations. It just indicates that the FFI compat lint should accept those types for NPO.
2024-09-22 10:18:59 +00:00
Ralf Jung
8103505a4d fix rustc_nonnull_optimization_guaranteed docs 2024-09-22 10:00:24 +02:00
Ralf Jung
27400ea4ed interpret: remove outdated FIXME 2024-09-22 08:18:30 +02:00
Jubilee
b0208640c6
Rollup merge of #130665 - veera-sivarajan:fix-118612, r=compiler-errors
Prevent Deduplication of `LongRunningWarn`

Fixes #118612

As mention in the issue, `LongRunningWarn` is meant to be repeated multiple times.

Therefore, this PR stores a unique number in every instance of `LongRunningWarn` so that it's not hashed into the same value and omitted by the deduplication mechanism.
2024-09-21 22:34:34 -07:00
Veera
669f610f74 Prevent Deduplication of LongRunningWarn 2024-09-21 11:23:34 -04:00
Lukas Markeffsky
697450151c layout computation: eagerly error for unexpected unsized fields 2024-09-16 15:53:21 +02:00
Lukas Markeffsky
16be6666d4 make LayoutCx not generic 2024-09-16 15:53:17 +02:00
Ralf Jung
7dfffe7e70 const: don't ICE when encountering a mutable ref to immutable memory 2024-09-15 22:53:04 +02: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
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
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
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
bors
9b72238eb8 Auto merge of #128543 - RalfJung:const-interior-mut, r=fee1-dead
const-eval interning: accept interior mutable pointers in final value

…but keep rejecting mutable references

This fixes https://github.com/rust-lang/rust/issues/121610 by no longer firing the lint when there is a pointer with interior mutability in the final value of the constant. On stable, such pointers can be created with code like:
```rust
pub enum JsValue {
    Undefined,
    Object(Cell<bool>),
}
impl Drop for JsValue {
    fn drop(&mut self) {}
}
// This does *not* get promoted since `JsValue` has a destructor.
// However, the outer scope rule applies, still giving this 'static lifetime.
const UNDEFINED: &JsValue = &JsValue::Undefined;
```
It's not great to accept such values since people *might* think that it is legal to mutate them with unsafe code. (This is related to how "infectious" `UnsafeCell` is, which is a [wide open question](https://github.com/rust-lang/unsafe-code-guidelines/issues/236).) However, we [explicitly document](https://doc.rust-lang.org/reference/behavior-considered-undefined.html) that things created by `const` are immutable. Furthermore, we also accept the following even more questionable code without any lint today:
```rust
let x: &'static Option<Cell<i32>> = &None;
```
This is even more questionable since it does *not* involve a `const`, and yet still puts the data into immutable memory. We could view this as promotion [potentially introducing UB](https://github.com/rust-lang/unsafe-code-guidelines/issues/493). However, we've accepted this since ~forever and it's [too late to reject this now](https://github.com/rust-lang/rust/pull/122789); the pattern is just too useful.

So basically, if you think that `UnsafeCell` should be tracked fully precisely, then you should want the lint we currently emit to be removed, which this PR does. If you think `UnsafeCell` should "infect" surrounding `enum`s, the big problem is really https://github.com/rust-lang/unsafe-code-guidelines/issues/493 which does not trigger the lint -- the cases the lint triggers on are actually the "harmless" ones as there is an explicit surrounding `const` explaining why things end up being immutable.

What all this goes to show is that the hard error added in https://github.com/rust-lang/rust/pull/118324 (later turned into the future-compat lint that I am now suggesting we remove) was based on some wrong assumptions, at least insofar as it concerns shared references. Furthermore, that lint does not help at all for the most problematic case here where the potential UB is completely implicit. (In fact, the lint is actively in the way of [my preferred long-term strategy](https://github.com/rust-lang/unsafe-code-guidelines/issues/493#issuecomment-2028674105) for dealing with this UB.) So I think we should go back to square one and remove that error/lint for shared references. For mutable references, it does seem to work as intended, so we can keep it. Here it serves as a safety net in case the static checks that try to contain mutable references to the inside of a const initializer are not working as intended; I therefore made the check ICE to encourage users to tell us if that safety net is triggered.

Closes https://github.com/rust-lang/rust/issues/122153 by removing the lint.

Cc `@rust-lang/opsem` `@rust-lang/lang`
2024-09-14 21:11:04 +00:00
León Orell Valerian Liehr
03e8b6bbfa
Rollup merge of #130294 - nnethercote:more-lifetimes, r=lcnr
Lifetime cleanups

The last commit is very opinionated, let's see how we go.

r? `@oli-obk`
2024-09-14 18:12:13 +02:00
Ralf Jung
3b806d337c interpret: fix dealing with overflow during slice indexing 2024-09-14 10:00:07 +02:00
Ralf Jung
e2bc16c101 interpret: simplify SIMD type handling 2024-09-13 15:26:08 +02:00
Nicholas Nethercote
8d32578fe1 Rename and reorder lots of lifetimes.
- Replace non-standard names like 's, 'p, 'rg, 'ck, 'parent, 'this, and
  'me with vanilla 'a. These are cases where the original name isn't
  really any more informative than 'a.
- Replace names like 'cx, 'mir, and 'body with vanilla 'a when the lifetime
  applies to multiple fields and so the original lifetime name isn't
  really accurate.
- Put 'tcx last in lifetime lists, and 'a before 'b.
2024-09-13 15:46:20 +10:00
Stuart Cook
57020e0f8c
Rollup merge of #130250 - compiler-errors:useless-conversion, r=jieyouxu
Fix `clippy::useless_conversion`

Self-explanatory. Probably the last clippy change I'll actually put up since this is the only other one I've actually seen in the wild.
2024-09-12 20:37:17 +10:00
Stuart Cook
3ba12756d3
Rollup merge of #130235 - compiler-errors:nested-if, r=michaelwoerister
Simplify some nested `if` statements

Applies some but not all instances of `clippy::collapsible_if`. Some ended up looking worse afterwards, though, so I left those out. Also applies instances of `clippy::collapsible_else_if`

Review with whitespace disabled please.
2024-09-12 20:37:16 +10:00
Jubilee
142598214c
Rollup merge of #130239 - RalfJung:miri-ptr-offset-unsigned, r=compiler-errors
miri: fix overflow detection for unsigned pointer offset

This is the Miri part of https://github.com/rust-lang/rust/pull/130229. This is already UB in codegen so we better make Miri detect it; updating the docs may take time if we have to follow some approval process, but let's make Miri match reality ASAP.

r? ``@scottmcm``
2024-09-11 15:53:24 -07:00
Jubilee
a31a8fe0cf
Rollup merge of #130114 - eduardosm:needless-returns, r=compiler-errors
Remove needless returns detected by clippy in the compiler
2024-09-11 15:53:22 -07:00
Michael Goulet
6d064295c8 clippy::useless_conversion 2024-09-11 17:52:53 -04:00
Ralf Jung
3842ea671b miri: fix overflow detection for unsigned pointer offset 2024-09-11 20:40:55 +02:00
Michael Goulet
954419aab0 Simplify some nested if statements 2024-09-11 13:45:23 -04:00
Ralf Jung
d104dedad9 interpret: mark some hot functions inline(always)
recovers some of the perf regressions from #129778
2024-09-10 22:43:56 +02:00
Ralf Jung
123757ae07 turn errors that should be impossible due to our static checks into ICEs 2024-09-10 10:27:30 +02:00
Ralf Jung
f76f128dc9 const-eval interning: accpt interior mutable pointers in final value (but keep rejecting mutable references) 2024-09-10 10:26:16 +02:00
Ralf Jung
a888905226 miri: treat non-memory local variables properly for data race detection 2024-09-10 10:25:22 +02:00
Ralf Jung
65c70900ce union padding computation: add fast-path for ZST
Also avoid even tracking empty ranges, and add fast-path for arrays of scalars
2024-09-09 14:46:26 +02:00
Eduardo Sánchez Muñoz
0b20ffcb63 Remove needless returns detected by clippy in the compiler 2024-09-09 13:32:22 +02:00
Ralf Jung
a2410425b3 clarify comments and names in check_validity_requirement 2024-09-08 16:53:23 +02:00
Ralf Jung
8cd982caa1 interpret: reset padding during validation 2024-09-08 16:53:23 +02:00
Ralf Jung
cbdcbf0d6a interpret: reset provenance on typed copies 2024-09-08 16:53:23 +02:00
Ralf Jung
85dc22f2cf interpret: factor out common code for place mutation 2024-09-08 16:53:23 +02:00
Ralf Jung
8ad808db7e interpret: make Writeable trait about a to_place operation 2024-09-08 16:53:23 +02:00
Ralf Jung
fa60ea7d38 interpret: remove Readable trait, we can use Projectable instead 2024-09-08 16:53:22 +02:00
Pavel Grigorenko
f6e8a84eea Make Ty::boxed_ty return an Option 2024-09-06 00:30:36 +03:00
bors
6199b69c53 Auto merge of #129777 - nnethercote:unreachable_pub-4, r=Urgau
Add `unreachable_pub`, round 4

A follow-up to #129732.

r? `@Urgau`
2024-09-03 01:27:20 +00:00
Nicholas Nethercote
88b6a78d0b Add warn(unreachable_pub) to rustc_const_eval. 2024-09-03 08:50:33 +10:00
Alexander Cyon
ac69544a17
chore: Fix typos in 'compiler' (batch 1) 2024-09-02 07:42:38 +02:00
bors
a7399ba69d Auto merge of #129831 - matthiaskrgr:rollup-befq6zx, r=matthiaskrgr
Rollup of 11 pull requests

Successful merges:

 - #128523 (Add release notes for 1.81.0)
 - #129605 (Add missing `needs-llvm-components` directives for run-make tests that need target-specific codegen)
 - #129650 (Clean up `library/profiler_builtins/build.rs`)
 - #129651 (skip stage 0 target check if `BOOTSTRAP_SKIP_TARGET_SANITY` is set)
 - #129684 (Enable Miri to pass pointers through FFI)
 - #129762 (Update the `wasm-component-ld` binary dependency)
 - #129782 (couple more crash tests)
 - #129816 (tidy: say which feature gate has a stability issue mismatch)
 - #129818 (make the const-unstable-in-stable error more clear)
 - #129824 (Fix code examples buttons not appearing on click on mobile)
 - #129826 (library: Fix typo in `core::mem`)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-08-31 20:59:27 +00:00
Matthias Krüger
b8b2a65035
Rollup merge of #129818 - RalfJung:const-stability, r=compiler-errors
make the const-unstable-in-stable error more clear

The default should be to add `rustc_const_unstable`, not `rustc_allow_const_fn_unstable`.

Also I discovered our check for missing const stability attributes on stable functions -- but strangely that check only kicks in for "reachable" functions. `check_missing_stability` checks for reachability since all reachable functions must have a stability attribute, but I would say if a function has `#[stable]` it should also have const-stability attributes regardless of reachability.
2024-08-31 20:36:27 +02:00
Matthias Krüger
a5fb8b90bf
Rollup merge of #129684 - Strophox:miri-pass-pointer-to-ffi, r=RalfJung
Enable Miri to pass pointers through FFI

Following https://github.com/rust-lang/rust/pull/126787, the purpose of this PR is to now enable Miri to execute native calls that make use of pointers.

> <details>
>
> <summary> Simple example </summary>
>
> ```rust
> extern "C" {
>     fn ptr_printer(ptr: *mut i32);
> }
>
> fn main() {
>     let ptr = &mut 42 as *mut i32;
>     unsafe {
>         ptr_printer(ptr);
>     }
> }
> ```
> ```c
> void ptr_printer(int *ptr) {
>   printf("printing pointer dereference from C: %d\n", *ptr);
> }
> ```
> should now show `printing pointer dereference from C: 42`.
>
> </details>

Note that this PR does not yet implement any logic involved in updating Miri's "analysis" state (byte initialization, provenance) upon such a native call.

r? ``@RalfJung``
2024-08-31 20:36:25 +02:00
Ralf Jung
e3b1966137 make the const-unstable-in-stable error more clear 2024-08-31 15:11:48 +02:00
Matthias Krüger
830b1deaee
Rollup merge of #129812 - RalfJung:box-custom-alloc, r=compiler-errors
interpret, codegen: tweak some comments and checks regarding Box with custom allocator

Cc https://github.com/rust-lang/rust/issues/95453
2024-08-31 14:46:14 +02:00
Matthias Krüger
ea5bb99c0f
Rollup merge of #129659 - RalfJung:const-fn-lang-feat, r=fee1-dead
const fn stability checking: also check declared language features

Fixes https://github.com/rust-lang/rust/issues/129656

`@oli-obk` I assume it is just an oversight that this didn't use `features().declared()`? Or is there a deep reason that this must only check `declared_lib_features`?
2024-08-31 14:46:06 +02:00
Ralf Jung
c2984179d9 const fn stability checking: also check declared language features 2024-08-31 12:14:05 +02:00
Ralf Jung
d0aedfbb90 interpret, codegen: tweak some comments and checks regarding Box with custom allocator 2024-08-31 11:29:02 +02:00
Strophox
7fde02ea53 enable Miri to pass const pointers through FFI
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-08-30 16:05:53 +02:00
Ralf Jung
de34a91350 interpret/visitor: make memory order iteration slightly more efficient 2024-08-29 16:53:14 +02:00
Matthias Krüger
5c2996d750
Rollup merge of #129666 - RalfJung:raw-eq-align, r=compiler-errors
interpret: add missing alignment check in raw_eq

The intrinsic requires alignment, but we forgot to check for that in Miri and const-eval.
2024-08-28 17:12:19 +02:00
Matthias Krüger
39e840f804
Rollup merge of #129613 - RalfJung:interpret-target-feat, r=saethlin
interpret: do not make const-eval query result depend on tcx.sess

The check against calling functions with missing target features uses `tcx.sess` to determine which target features are available. However, this can differ between different crates in a crate graph, so the same const-eval query can come to different conclusions about whether a constant evaluates successfully or not -- which is bad, we should consistently get the same result everywhere.
2024-08-28 17:12:17 +02:00
Matthias Krüger
3456b1d245
Rollup merge of #129608 - RalfJung:const-eval-ub-checks, r=saethlin
const-eval: do not make UbChecks behavior depend on current crate's flags

Fixes https://github.com/rust-lang/rust/issues/129552

Let's see if we can get away with just always enabling these checks.
2024-08-28 17:12:17 +02:00
bors
d9a2cc4dae Auto merge of #128506 - compiler-errors:by-move-body, r=cjgillot
Stop storing a special inner body for the coroutine by-move body for async closures

...and instead, just synthesize an item which is treated mostly normally by the MIR pipeline.

This PR does a few things:
* We synthesize a new `DefId` for the by-move body of a closure, which has its `mir_built` fed with the output of the `ByMoveBody` MIR transformation, and some other relevant queries.
* This has the `DefKind::ByMoveBody`, which we use to distinguish it from "real" bodies (that come from HIR) which need to be borrowck'd. Introduce `TyCtxt::is_synthetic_mir` to skip over `mir_borrowck` which is called by `mir_promoted`; borrowck isn't really possible to make work ATM since it heavily relies being called on a body generated from HIR, and is redundant by the construction of the by-move-body.
* Remove the special `PassManager` hacks for handling the inner `by_move_body` stored within the coroutine's mir body. Instead, this body is fed like a regular MIR body, so it's goes through all of the `tcx.*_mir` stages normally (build -> promoted -> ...etc... -> optimized) .
* Remove the `InstanceKind::ByMoveBody` shim, since now we have a "regular" def id, we can just use `InstanceKind::Item`. This also allows us to remove the corresponding hacks from codegen, such as in `fn_sig_for_fn_abi` .

Notable remarks:
* ~~I know it's kind of weird to be using `DefKind::Closure` here, since it's not a distinct closure but just a new MIR body. I don't believe it really matters, but I could also use a different `DefKind`... maybe one that we could use for synthetic MIR bodies in general?~~ edit: We're doing this now.
2024-08-27 23:30:24 +00:00
Ralf Jung
e17be955bb interpret: add missing alignment check in raw_eq 2024-08-27 19:29:52 +02:00
Matthias Krüger
849c240c1e
Rollup merge of #129507 - RalfJung:per-fn-const_precise_live_drops, r=wesleywiser
make it possible to enable const_precise_live_drops per-function

This makes const_precise_live_drops work with rustc_allow_const_fn_unstable so that we can stabilize individual functions that rely on const_precise_live_drops.

The goal is that we can use that to stabilize some of https://github.com/rust-lang/rust/issues/67441 without having to stabilize const_precise_live_drops.
2024-08-27 18:59:27 +02:00
Trevor Gross
427019e37f
Rollup merge of #128942 - RalfJung:interpret-weak-memory, r=saethlin
miri weak memory emulation: put previous value into initial store buffer

Fixes https://github.com/rust-lang/miri/issues/2164 by doing a read before each atomic write so that we can initialize the store buffer. The read suppresses memory access hooks and UB exceptions, to avoid otherwise influencing the program behavior. If the read fails, we store that as `None` in the store buffer, so that when an atomic read races with the first atomic write to some memory and previously the memory was uninitialized, we can report UB due to reading uninit memory.

``@cbeuw`` this changes a bit the way we initialize the store buffers. Not sure if you still remember all this code, but if you could have a look to make sure this still makes sense, that would be great. :)

r? ``@saethlin``
2024-08-27 01:46:51 -05:00
Michael Goulet
4609841c07 Stop using a special inner body for the coroutine by-move body for async closures 2024-08-26 18:44:19 -04:00
Ralf Jung
7a290fce90 interpret: do not make const-eval query result depend on tcx.sess 2024-08-26 17:08:52 +02:00
Ralf Jung
7ea2981605 const-eval: do not make UbChecks behavior depend on current crate's flags 2024-08-26 13:56:40 +02:00
bors
22572d0994 Auto merge of #129508 - RalfJung:transient-locals, r=cjgillot
const checking: properly compute the set of transient locals

For const-checking the MIR of a const/static initializer, we have to know the set of "transient" locals. The reason for this is that creating a mutable (or interior mutable) reference to a transient local is "safe" in the sense that this reference cannot possibly end up in the final value of the const -- even if it is turned into a raw pointer and stored in a union, we will see that pointer during interning and reliably reject it as dangling.

So far, we determined the set of transient locals as "locals that have a `StorageDead` somewhere". But that's not quite right -- if we had MIR like
```rust
StorageLive(_5);
StorageDead(_5);
StorageLive(_5);
// no further storage annotations for _5
```
Then we'd consider `_5` to be "transient", but it is not actually transient.

We do not currently generate such MIR, but I feel uneasy relying on subtle invariants like this. So this PR implements a proper analysis for computing the set of "transient" locals: a local is "transient" if it is guaranteed dead at all `Return` terminators.

Cc `@cjgillot`
2024-08-26 08:44:10 +00:00
Matthias Krüger
d6a3aa4fc4
Rollup merge of #129590 - compiler-errors:ref-tykind, r=fmease
Avoid taking reference of &TyKind

It's already a ref anyways. Just a tiny cleanup here.
2024-08-26 01:49:04 +02:00
Michael Goulet
48f43fa0ed Avoid taking reference of &TyKind 2024-08-25 16:02:29 -04:00
Ralf Jung
ba24121ad6 tweak rustc_allow_const_fn_unstable hint, and add back test for stable-const-can-only-call-stable-const 2024-08-25 13:50:55 +02:00
Ralf Jung
5412499ad5 make it possible to enable const_precise_live_drops per-function 2024-08-25 13:49:16 +02:00
Ralf Jung
74a21425cc dont iterate over the bitset 2024-08-25 12:33:55 +02:00
Ralf Jung
172c05cca2 only visit reachable blocks, do not use a visitor 2024-08-25 11:42:55 +02:00
Matthias Krüger
9e1f6281ab
Rollup merge of #129505 - RalfJung:imm-ty-offset, r=davidtwco
interpret: ImmTy: tighten sanity checks in offset logic

Also make some debug assertions into assertions. (Will need to be perf'd.)
2024-08-24 22:14:15 +02:00
Matthias Krüger
05b8bcc662
Rollup merge of #129199 - RalfJung:writes_through_immutable_pointer, r=compiler-errors
make writes_through_immutable_pointer a hard error

This turns the lint added in https://github.com/rust-lang/rust/pull/118324 into a hard error. This has been reported in cargo's future-compat reports since Rust 1.76 (released in February). Given that const_mut_refs is still unstable, it should be impossible to even hit this error on stable: we did accidentally stabilize some functions that can cause this error, but that got reverted in https://github.com/rust-lang/rust/pull/117905. Still, let's do a crater run just to be sure.

Given that this should only affect unstable code, I don't think it needs an FCP, but let's Cc ``@rust-lang/lang`` anyway -- any objection to making this unambiguous UB into a hard error during const-eval? This can be viewed as part of https://github.com/rust-lang/rust/pull/129195 which is already nominated for discussion.
2024-08-24 22:14:12 +02:00
Ralf Jung
5343550142 const checking: properly compute the set of transient locals 2024-08-24 17:14:31 +02:00
Ralf Jung
493cf6a7e9 interpret: ImmTy: tighten sanity checks in offset logic 2024-08-24 15:12:30 +02:00
Ralf Jung
ebfa3e3f62 stabilize const_fn_floating_point_arithmetic 2024-08-22 08:25:54 +02:00
Matthias Krüger
937a18daf9
Rollup merge of #129344 - compiler-errors:less-option-unit-diagnostics, r=jieyouxu
Use `bool` in favor of `Option<()>` for diagnostics

We originally only supported `Option<()>` for optional notes/labels, but we now support `bool`. Let's use that, since it usually leads to more readable code.

I'm not removing the support from the derive macro, though I guess we could error on it... 🤔
2024-08-21 18:15:05 +02:00
Michael Goulet
25ff9b6bcb Use bool in favor of Option<()> for diagnostics 2024-08-21 01:31:11 -04:00
Ralf Jung
38af7b068f ctfe: make CompileTimeInterpCx type alias public 2024-08-20 14:58:10 +02:00
Ralf Jung
35709be02d rename AddressOf -> RawBorrow inside the compiler 2024-08-18 19:46:53 +02:00
Ralf Jung
8b642a1883 make writes_through_immutable_pointer a hard error 2024-08-17 14:49:35 +02:00
Slanterns
e2ec11502d
stabilize is_none_or 2024-08-14 18:28:40 +08:00
bors
e9c965df7b Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errors
Shrink `TyKind::FnPtr`.

By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI.

r? `@compiler-errors`
2024-08-14 00:56:53 +00:00
bors
591ecb88df Auto merge of #128742 - RalfJung:miri-vtable-uniqueness, r=saethlin
miri: make vtable addresses not globally unique

Miri currently gives vtables a unique global address. That's not actually matching reality though. So this PR enables Miri to generate different addresses for the same type-trait pair.

To avoid generating an unbounded number of `AllocId` (and consuming unbounded amounts of memory), we use the "salt" technique that we also already use for giving constants non-unique addresses: the cache is keyed on a "salt" value n top of the actually relevant key, and Miri picks a random salt (currently in the range `0..16`) each time it needs to choose an `AllocId` for one of these globals -- that means we'll get up to 16 different addresses for each vtable. The salt scheme is integrated into the global allocation deduplication logic in `tcx`, and also used for functions and string literals. (So this also fixes the problem that casting the same function to a fn ptr over and over will consume unbounded memory.)

r? `@saethlin`
Fixes https://github.com/rust-lang/miri/issues/3737
2024-08-13 04:32:34 +00:00
Matthias Krüger
4c49418472
Rollup merge of #128712 - compiler-errors:normalize-borrowck, r=lcnr
Normalize struct tail properly for `dyn` ptr-to-ptr casting in new solver

Realized that the new solver didn't handle ptr-to-ptr casting correctly.

r? lcnr

Built on #128694
2024-08-12 23:10:50 +02:00
Guillaume Gomez
7c6dca9050
Rollup merge of #128978 - compiler-errors:assert-matches, r=jieyouxu
Use `assert_matches` around the compiler more

It's a useful assertion, especially since it actually prints out the LHS.
2024-08-12 17:09:19 +02:00
Ralf Jung
8b18c6bdd3 miri weak memory emulation: initialize store buffer only on atomic writes; pre-fill with previous value 2024-08-12 10:36:45 +02:00
Michael Goulet
f15997ffec Remove struct_tail_no_normalization 2024-08-11 19:40:03 -04:00
Michael Goulet
b5d2079fb9 Rename normalization functions to raw 2024-08-11 19:40:03 -04:00
Michael Goulet
c361c924a0 Use assert_matches around the compiler 2024-08-11 12:25:39 -04:00