about summary refs log tree commit diff
path: root/compiler/rustc_const_eval
AgeCommit message (Collapse)AuthorLines
2024-03-22Fix validation on substituted callee bodies in MIR inlinerMichael Goulet-4/+15
2024-03-22Rollup merge of #122784 - jswrenn:tag_for_variant, r=compiler-errorsMatthias Krüger-68/+304
Add `tag_for_variant` query This query allows for sharing code between `rustc_const_eval` and `rustc_transmutability`. It's a precursor to a PR I'm working on to entirely replace the bespoke layout computations in `rustc_transmutability`. r? `@compiler-errors`
2024-03-22Add `tag_for_variant` queryJack Wrenn-68/+304
This query allows for sharing code between `rustc_const_eval` and `rustc_transmutability`. Also moves `DummyMachine` to `rustc_const_eval`.
2024-03-22Make RawPtr take Ty and Mutbl separatelyMichael Goulet-2/+2
2024-03-22Programmatically convert some of the pat ctorsMichael Goulet-10/+8
2024-03-22Rollup merge of #122542 - Zalathar:cleanup, r=oli-obkMatthias Krüger-1/+12
coverage: Clean up marker statements that aren't needed later Some of the marker statements used by coverage are added during MIR building for use by the InstrumentCoverage pass (during analysis), and are not needed afterwards. ```@rustbot``` label +A-code-coverage
2024-03-22Rollup merge of #122537 - RalfJung:interpret-allocation, r=oli-obkMatthias Krüger-3/+14
interpret/allocation: fix aliasing issue in interpreter and refactor getters a bit That new raw getter will be needed to let Miri pass pointers to natively executed FFI code ("extern-so" mode). While doing that I realized our get_bytes_mut are named less scary than get_bytes_unchecked so I rectified that. Also I realized `mem_copy_repeatedly` would break if we called it for multiple overlapping copies so I made sure this does not happen. And I realized that we are actually [violating Stacked Borrows in the interpreter](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/I.20think.20Miri.20violates.20Stacked.20Borrows.20.F0.9F.99.88).^^ That was introduced in https://github.com/rust-lang/rust/pull/87777. r? ```@oli-obk```
2024-03-22coverage: Clean up marker statements that aren't needed laterZalathar-1/+12
Some of the marker statements used by coverage are added during MIR building for use by the InstrumentCoverage pass (during analysis), and are not needed afterwards.
2024-03-20Rollup merge of #121543 - onur-ozkan:clippy-args, r=oli-obkMatthias Krüger-1/+3
various clippy fixes We need to keep the order of the given clippy lint rules before passing them. Since clap doesn't offer any useful interface for this purpose out of the box, we have to handle it manually. Additionally, this PR makes `-D` rules work as expected. Previously, lint rules were limited to `-W`. By enabling `-D`, clippy began to complain numerous lines in the tree, all of which have been resolved in this PR as well. Fixes #121481 cc `@matthiaskrgr`
2024-03-20resolve clippy errorsonur-ozkan-1/+3
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-03-19Ensure nested statics have a HIR node to prevent various queries from ICEingOli Scherer-0/+2
2024-03-19Auto merge of #122493 - lukas-code:sized-constraint, r=lcnrbors-4/+4
clean up `Sized` checking This PR cleans up `sized_constraint` and related functions to make them simpler and faster. This should not make more or less code compile, but it can change error output in some rare cases. ## enums and unions are `Sized`, even if they are not WF The previous code has some special handling for enums, which made them sized if and only if the last field of each variant is sized. For example given this definition (which is not WF) ```rust enum E<T1: ?Sized, T2: ?Sized, U1: ?Sized, U2: ?Sized> { A(T1, T2), B(U1, U2), } ``` the enum was sized if and only if `T2` and `U2` are sized, while `T1` and `T2` were ignored for `Sized` checking. After this PR this enum will always be sized. Unsized enums are not a thing in Rust and removing this special case allows us to return an `Option<Ty>` from `sized_constraint`, rather than a `List<Ty>`. Similarly, the old code made an union defined like this ```rust union Union<T: ?Sized, U: ?Sized> { head: T, tail: U, } ``` sized if and only if `U` is sized, completely ignoring `T`. This just makes no sense at all and now this union is always sized. ## apply the "perf hack" to all (non-error) types, instead of just type parameters This "perf hack" skips evaluating `sized_constraint(adt): Sized` if `sized_constraint(adt): Sized` exactly matches a predicate defined on `adt`, for example: ```rust // `Foo<T>: Sized` iff `T: Sized`, but we know `T: Sized` from a predicate of `Foo` struct Foo<T /*: Sized */>(T); ``` Previously this was only applied to type parameters and now it is applied to every type. This means that for example this type is now always sized: ```rust // Note that this definition is WF, but the type `S<T>` not WF in the global/empty ParamEnv struct S<T>([T]) where [T]: Sized; ``` I don't anticipate this to affect compile time of any real-world program, but it makes the code a bit nicer and it also makes error messages a bit more consistent if someone does write such a cursed type. ## tuples are sized if the last type is sized The old solver already has this behavior and this PR also implements it for the new solver and `is_trivially_sized`. This makes it so that tuples work more like a struct defined like this: ```rust struct TupleN<T1, T2, /* ... */ Tn: ?Sized>(T1, T2, /* ... */ Tn); ``` This might improve the compile time of programs with large tuples a little, but is mostly also a consistency fix. ## `is_trivially_sized` for more types This function is used post-typeck code (borrowck, const eval, codegen) to skip evaluating `T: Sized` in some cases. It will now return `true` in more cases, most notably `UnsafeCell<T>` and `ManuallyDrop<T>` where `T.is_trivially_sized`. I'm anticipating that this change will improve compile time for some real world programs.
2024-03-18Rollup merge of #122158 - estebank:feature-sugg, r=WaffleLapkinMatthias Krüger-5/+7
Provide structured suggestion for `#![feature(foo)]` ``` error: `S2<'_>` is forbidden as the type of a const generic parameter --> $DIR/lifetime-in-const-param.rs:5:23 | LL | struct S<'a, const N: S2>(&'a ()); | ^^ | = note: the only supported types are integers, `bool` and `char` help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | LL + #![feature(adt_const_params)] | ``` Fix #55941.
2024-03-18Provide structured suggestion for `#![feature(foo)]`Esteban Küber-5/+7
``` error: `S2<'_>` is forbidden as the type of a const generic parameter --> $DIR/lifetime-in-const-param.rs:5:23 | LL | struct S<'a, const N: S2>(&'a ()); | ^^ | = note: the only supported types are integers, `bool` and `char` help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | LL + #![feature(adt_const_params)] | ``` Fix #55941.
2024-03-18Rollup merge of #122647 - RalfJung:box-to-raw-retag, r=oli-obkMatthias Krüger-2/+2
add_retag: ensure box-to-raw-ptr casts are preserved for Miri In https://github.com/rust-lang/rust/pull/122233 I added `retag_box_to_raw` not realizing that we can already do `addr_of_mut!(*bx)` to turn a box into a raw pointer without an intermediate reference. We just need to ensure this information is preserved past the ElaborateBoxDerefs pass. r? ``@oli-obk``
2024-03-18Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few ↵Oli Scherer-8/+7
cases that used `None`
2024-03-18add_retag: ensure box-to-raw-ptr casts are preserved for MiriRalf Jung-2/+2
2024-03-17Let codegen decide when to `mem::swap` with immediatesScott McMurray-2/+23
Making `libcore` decide this is silly; the backend has so much better information about when it's a good idea. So introduce a new `typed_swap` intrinsic with a fallback body, but replace that implementation for immediates and scalar pairs.
2024-03-17interpret/memory: explain why we use == on boolRalf Jung-0/+2
2024-03-17Print a backtrace in const eval if interruptedBen Kimock-1/+18
2024-03-15interpret/allocation: fix aliasing issue in interpreter and refactor getters ↵Ralf Jung-3/+14
a bit - rename mutating functions to be more scary - add a new raw bytes getter
2024-03-14remove unnecessary sized checksLukas Markeffsky-4/+4
2024-03-14Rename some things around validation error reporting to signal that it is in ↵Oli Scherer-13/+15
fact about validation failures
2024-03-14Move the entire success path into `eval_body_using_ecx`Oli Scherer-41/+33
2024-03-14Move validation into eval_body_using_ecxOli Scherer-6/+4
2024-03-14Share the `InterpCx` creation between static and const evaluationOli Scherer-19/+11
2024-03-14Remove an argument that can be computed cheaplyOli Scherer-7/+3
2024-03-14Directly pass in the stack instead of computing it from a machineOli Scherer-5/+6
2024-03-14Move generate_stacktrace_from_stack away from InterpCx to avoid having to ↵Oli Scherer-36/+31
know the `Machine` type
2024-03-14Move InterpCx into eval_in_interpreterOli Scherer-9/+9
2024-03-14Move error handling into const_validate_mplaceOli Scherer-11/+6
2024-03-14Move only usage of `take_static_root_alloc` to its definition and inline itOli Scherer-24/+19
2024-03-14Generalize `eval_in_interpreter` with a helper traitOli Scherer-10/+34
2024-03-14Fix accidental re-addition of removed code in a previous PROli Scherer-3/+0
2024-03-14Auto merge of #122243 - RalfJung:local-place-sanity-check, r=oli-obkbors-70/+59
interpret: ensure that Place is never used for a different frame We store the address where the stack frame stores its `locals`. The idea is that even if we pop and push, or switch to a different thread with a larger number of frames, then the `locals` address will most likely change so we'll notice that problem. This is made possible by some recent changes by `@WaffleLapkin,` where we no longer use `Place` across things that change the number of stack frames. I made these debug assertions for now, just to make sure this can't cost us any perf. The first commit is unrelated but it's a one-line comment change so it didn't warrant a separate PR... r? `@oli-obk`
2024-03-13placate tidy.Felix S. Klock II-1/+1
2024-03-13downgrade mutable-ptr-in-final-value from hard-error to future-incompat lint ↵Felix S. Klock II-6/+13
to address issue 121610.
2024-03-13Auto merge of #122240 - RalfJung:miri-addr-reuse, r=oli-obkbors-2/+4
miri: add some chance to reuse addresses of previously freed allocations The hope is that this can help us find ABA issues. Unfortunately this needs rustc changes so I can't easily run the regular benchmark suite. I used `src/tools/miri/tests/pass/float_nan.rs` as a substitute: ``` Before: Benchmark 1: ./x.py run miri --stage 0 --args src/tools/miri/tests/pass/float_nan.rs --args --edition=2021 Time (mean ± σ): 9.570 s ± 0.013 s [User: 9.279 s, System: 0.290 s] Range (min … max): 9.561 s … 9.579 s 2 runs After: Benchmark 1: ./x.py run miri --stage 0 --args src/tools/miri/tests/pass/float_nan.rs --args --edition=2021 Time (mean ± σ): 9.698 s ± 0.046 s [User: 9.413 s, System: 0.279 s] Range (min … max): 9.666 s … 9.731 s 2 runs ``` That's a ~1.3% slowdown, which seems fine to me. I have seen a lot of noise in this style of benchmarking so I don't quite trust this anyway; we can make further experiments in the Miri repo after this migrated there. r? `@oli-obk`
2024-03-12Exhaustively match on the mutability and nestednessOli Scherer-7/+9
2024-03-12s/mt/mutability/Oli Scherer-4/+4
2024-03-12Ensure nested allocations in statics do not get deduplicatedOli Scherer-36/+110
2024-03-12Add `nested` bool to `DefKind::Static`.Oli Scherer-1/+1
Will be used in the next commit
2024-03-12Change `DefKind::Static` to a struct variantOli Scherer-10/+11
2024-03-11Rollup merge of #122249 - RalfJung:machine-read-hook, r=oli-obkJubilee-12/+45
interpret: do not call machine read hooks during validation Fixes https://github.com/rust-lang/miri/issues/3347 r? ``@oli-obk``
2024-03-11Rollup merge of #121893 - RalfJung:const-interior-mut-tests, r=oli-obkJubilee-5/+6
Add tests (and a bit of cleanup) for interior mut handling in promotion and const-checking Basically these are the parts of https://github.com/rust-lang/rust/pull/121786 that can be salvaged. r? ``@oli-obk``
2024-03-11const-checking: add some corner case tests, and fix some nitsRalf Jung-5/+5
2024-03-11Auto merge of #122132 - nnethercote:diag-renaming3, r=nnethercotebors-13/+12
Diagnostic renaming 3 A sequel to https://github.com/rust-lang/rust/pull/121780. r? `@davidtwco`
2024-03-11Rename `DecorateLint` as `LintDiagnostic`.Nicholas Nethercote-1/+1
To match `derive(LintDiagnostic)`.
2024-03-11Rename `IntoDiagnostic` as `Diagnostic`.Nicholas Nethercote-5/+4
To match `derive(Diagnostic)`. Also rename `into_diagnostic` as `into_diag`.
2024-03-11Rename `IntoDiagnosticArg` as `IntoDiagArg`.Nicholas Nethercote-7/+7
Also rename `into_diagnostic_arg` as `into_diag_arg`, and `NotIntoDiagnosticArg` as `NotInotDiagArg`.