about summary refs log tree commit diff
path: root/compiler/rustc_const_eval
AgeCommit message (Collapse)AuthorLines
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-13/+3
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-31Rollup merge of #129818 - RalfJung:const-stability, r=compiler-errorsMatthias Krüger-2/+2
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-31Rollup merge of #129684 - Strophox:miri-pass-pointer-to-ffi, r=RalfJungMatthias Krüger-11/+1
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-31make the const-unstable-in-stable error more clearRalf Jung-2/+2
2024-08-31Rollup merge of #129812 - RalfJung:box-custom-alloc, r=compiler-errorsMatthias Krüger-5/+7
interpret, codegen: tweak some comments and checks regarding Box with custom allocator Cc https://github.com/rust-lang/rust/issues/95453
2024-08-31Rollup merge of #129659 - RalfJung:const-fn-lang-feat, r=fee1-deadMatthias Krüger-3/+1
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-31const fn stability checking: also check declared language featuresRalf Jung-3/+1
2024-08-31interpret, codegen: tweak some comments and checks regarding Box with custom ↵Ralf Jung-5/+7
allocator
2024-08-30enable Miri to pass const pointers through FFIStrophox-11/+1
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-08-29interpret/visitor: make memory order iteration slightly more efficientRalf Jung-9/+10
2024-08-28Rollup merge of #129666 - RalfJung:raw-eq-align, r=compiler-errorsMatthias Krüger-5/+5
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-28Rollup merge of #129613 - RalfJung:interpret-target-feat, r=saethlinMatthias Krüger-45/+24
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-28Rollup merge of #129608 - RalfJung:const-eval-ub-checks, r=saethlinMatthias Krüger-1/+11
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-27Auto merge of #128506 - compiler-errors:by-move-body, r=cjgillotbors-1/+0
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-27interpret: add missing alignment check in raw_eqRalf Jung-5/+5
2024-08-27Rollup merge of #129507 - RalfJung:per-fn-const_precise_live_drops, ↵Matthias Krüger-2/+8
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-27Rollup merge of #128942 - RalfJung:interpret-weak-memory, r=saethlinTrevor Gross-1/+1
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-26Stop using a special inner body for the coroutine by-move body for async ↵Michael Goulet-1/+0
closures
2024-08-26interpret: do not make const-eval query result depend on tcx.sessRalf Jung-45/+24
2024-08-26const-eval: do not make UbChecks behavior depend on current crate's flagsRalf Jung-1/+11
2024-08-26Auto merge of #129508 - RalfJung:transient-locals, r=cjgillotbors-18/+32
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-26Rollup merge of #129590 - compiler-errors:ref-tykind, r=fmeaseMatthias Krüger-3/+3
Avoid taking reference of &TyKind It's already a ref anyways. Just a tiny cleanup here.
2024-08-25Avoid taking reference of &TyKindMichael Goulet-3/+3
2024-08-25tweak rustc_allow_const_fn_unstable hint, and add back test for ↵Ralf Jung-1/+1
stable-const-can-only-call-stable-const
2024-08-25make it possible to enable const_precise_live_drops per-functionRalf Jung-2/+8
2024-08-25dont iterate over the bitsetRalf Jung-4/+2
2024-08-25only visit reachable blocks, do not use a visitorRalf Jung-28/+16
2024-08-24Rollup merge of #129505 - RalfJung:imm-ty-offset, r=davidtwcoMatthias Krüger-6/+15
interpret: ImmTy: tighten sanity checks in offset logic Also make some debug assertions into assertions. (Will need to be perf'd.)
2024-08-24Rollup merge of #129199 - RalfJung:writes_through_immutable_pointer, ↵Matthias Krüger-14/+10
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-24const checking: properly compute the set of transient localsRalf Jung-17/+45
2024-08-24interpret: ImmTy: tighten sanity checks in offset logicRalf Jung-6/+15
2024-08-22stabilize const_fn_floating_point_arithmeticRalf Jung-48/+12
2024-08-21Rollup merge of #129344 - compiler-errors:less-option-unit-diagnostics, ↵Matthias Krüger-12/+12
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-21Use bool in favor of Option<()> for diagnosticsMichael Goulet-12/+12
2024-08-20ctfe: make CompileTimeInterpCx type alias publicRalf Jung-2/+5
2024-08-18rename AddressOf -> RawBorrow inside the compilerRalf Jung-9/+9
2024-08-17make writes_through_immutable_pointer a hard errorRalf Jung-14/+10