about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
AgeCommit message (Collapse)AuthorLines
2024-09-23Check vtable projections for validity in miriMichael Goulet-47/+66
2024-09-23fix unqualified_local_imports in rustc_const_evalRalf Jung-8/+11
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-129/+117
2024-09-22Rollup merge of #130690 - RalfJung:interpret-abi-compat-fixme, r=jieyouxuGuillaume Gomez-1/+0
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-22Auto merge of #130689 - RalfJung:rustc_nonnull_optimization_guaranteed, ↵bors-0/+1
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-22fix rustc_nonnull_optimization_guaranteed docsRalf Jung-0/+1
2024-09-22interpret: remove outdated FIXMERalf Jung-1/+0
2024-09-21Rollup merge of #130665 - veera-sivarajan:fix-118612, r=compiler-errorsJubilee-1/+10
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-21Prevent Deduplication of `LongRunningWarn`Veera-1/+10
2024-09-16layout computation: eagerly error for unexpected unsized fieldsLukas Markeffsky-5/+7
2024-09-16make `LayoutCx` not genericLukas Markeffsky-4/+4
2024-09-15const: don't ICE when encountering a mutable ref to immutable memoryRalf Jung-8/+2
2024-09-15Rollup merge of #130342 - RalfJung:slice-idx-overflow, r=saethlinMatthias Krüger-14/+34
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-15Rollup merge of #129828 - RalfJung:miri-data-race, r=saethlinMatthias Krüger-11/+51
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-15Auto merge of #130390 - matthiaskrgr:rollup-evbfwe2, r=matthiaskrgrbors-371/+30
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-15interpret: get_ptr_alloc_mut: lookup allocation only onceRalf Jung-24/+40
2024-09-15also stabilize const_refs_to_cellRalf Jung-84/+21
2024-09-15const_refs_to_cell: dont let mutable references sneak past the interior ↵Ralf Jung-1/+12
mutability check
2024-09-15clean up const checking of mutable referencesRalf Jung-77/+2
2024-09-15stabilize const_mut_refsRalf Jung-223/+9
2024-09-15also use compute_size_in_bytes for relevant multiplications in MiriRalf Jung-9/+11
2024-09-14Auto merge of #128543 - RalfJung:const-interior-mut, r=fee1-deadbors-47/+81
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-14Rollup merge of #130294 - nnethercote:more-lifetimes, r=lcnrLeón Orell Valerian Liehr-8/+8
Lifetime cleanups The last commit is very opinionated, let's see how we go. r? `@oli-obk`
2024-09-14interpret: fix dealing with overflow during slice indexingRalf Jung-7/+25
2024-09-13interpret: simplify SIMD type handlingRalf Jung-52/+40
2024-09-13Rename and reorder lots of lifetimes.Nicholas Nethercote-8/+8
- 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-12Rollup merge of #130250 - compiler-errors:useless-conversion, r=jieyouxuStuart Cook-7/+2
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-12Rollup merge of #130235 - compiler-errors:nested-if, r=michaelwoeristerStuart Cook-7/+15
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-11Rollup merge of #130239 - RalfJung:miri-ptr-offset-unsigned, r=compiler-errorsJubilee-1/+8
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-11Rollup merge of #130114 - eduardosm:needless-returns, r=compiler-errorsJubilee-2/+2
Remove needless returns detected by clippy in the compiler
2024-09-11clippy::useless_conversionMichael Goulet-7/+2
2024-09-11miri: fix overflow detection for unsigned pointer offsetRalf Jung-1/+8
2024-09-11Simplify some nested if statementsMichael Goulet-7/+15
2024-09-10interpret: mark some hot functions inline(always)Ralf Jung-0/+5
recovers some of the perf regressions from #129778
2024-09-10turn errors that should be impossible due to our static checks into ICEsRalf Jung-21/+40
2024-09-10const-eval interning: accpt interior mutable pointers in final value (but ↵Ralf Jung-32/+47
keep rejecting mutable references)
2024-09-10miri: treat non-memory local variables properly for data race detectionRalf Jung-11/+51
2024-09-09union padding computation: add fast-path for ZSTRalf Jung-12/+27
Also avoid even tracking empty ranges, and add fast-path for arrays of scalars
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-2/+2
2024-09-08clarify comments and names in check_validity_requirementRalf Jung-9/+11
2024-09-08interpret: reset padding during validationRalf Jung-35/+335
2024-09-08interpret: reset provenance on typed copiesRalf Jung-132/+264
2024-09-08interpret: factor out common code for place mutationRalf Jung-81/+89
2024-09-08interpret: make Writeable trait about a to_place operationRalf Jung-18/+13
2024-09-08interpret: remove Readable trait, we can use Projectable insteadRalf Jung-43/+17
2024-09-06Make `Ty::boxed_ty` return an `Option`Pavel Grigorenko-1/+1
2024-09-03Auto merge of #129777 - nnethercote:unreachable_pub-4, r=Urgaubors-25/+26
Add `unreachable_pub`, round 4 A follow-up to #129732. r? `@Urgau`
2024-09-03Add `warn(unreachable_pub)` to `rustc_const_eval`.Nicholas Nethercote-25/+26
2024-09-02chore: Fix typos in 'compiler' (batch 1)Alexander Cyon-6/+6
2024-08-31Auto merge of #129831 - matthiaskrgr:rollup-befq6zx, r=matthiaskrgrbors-11/+1
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