summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/interpret
AgeCommit message (Collapse)AuthorLines
2024-11-19`InterpCx` store `TypingEnv` instead of a `ParamEnv`lcnr-15/+17
2024-11-19move `fn is_item_raw` to `TypingEnv`lcnr-3/+3
2024-11-19Auto merge of #133164 - RalfJung:promoted-oom, r=jieyouxubors-2/+13
interpret: do not ICE when a promoted fails with OOM Fixes https://github.com/rust-lang/rust/issues/130687 try-job: aarch64-apple try-job: dist-x86_64-linux
2024-11-18interpret: do not ICE when a promoted fails with OOMRalf Jung-2/+13
2024-11-18use `TypingEnv` when no `infcx` is availablelcnr-12/+13
the behavior of the type system not only depends on the current assumptions, but also the currentnphase of the compiler. This is mostly necessary as we need to decide whether and how to reveal opaque types. We track this via the `TypingMode`.
2024-11-09make return type of get_alloc_info a struct, and reduce some code ↵Ralf Jung-3/+83
duplication with validity checking
2024-11-03compiler: Directly use rustc_abi in metadata and middleJubilee Young-8/+8
Stop reexporting ReprOptions from middle::ty
2024-10-23nightly feature tracking: get rid of the per-feature bool fieldsRalf Jung-1/+1
2024-10-19interpret errors: add map_err_kind, rename InterpError -> InterpErrorKindRalf Jung-36/+47
2024-10-12mark InterpResult as must_useRalf Jung-0/+1
2024-10-01make InterpResult a dedicated type to avoid accidentally discarding the errorRalf Jung-86/+218
2024-09-30panic when an interpreter error gets unintentionally discardedRalf Jung-9/+64
2024-09-23Check vtable projections for validity in miriMichael Goulet-11/+17
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-11/+11
2024-09-14Auto merge of #128543 - RalfJung:const-interior-mut, r=fee1-deadbors-4/+43
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-12Rollup merge of #130235 - compiler-errors:nested-if, r=michaelwoeristerStuart Cook-16/+14
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 #130114 - eduardosm:needless-returns, r=compiler-errorsJubilee-1/+1
Remove needless returns detected by clippy in the compiler
2024-09-11Simplify some nested if statementsMichael Goulet-16/+14
2024-09-10const-eval interning: accpt interior mutable pointers in final value (but ↵Ralf Jung-4/+43
keep rejecting mutable references)
2024-09-09Remove needless returns detected by clippy in the compilerEduardo Sánchez Muñoz-1/+1
2024-09-08interpret: reset provenance on typed copiesRalf Jung-0/+13
2024-09-02chore: Fix typos in 'compiler' (batch 2)Alexander Cyon-3/+3
2024-08-31Rollup merge of #129684 - Strophox:miri-pass-pointer-to-ffi, r=RalfJungMatthias Krüger-1/+2
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-30enable Miri to pass const pointers through FFIStrophox-1/+2
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-08-29Add `warn(unreachable_pub)` to `rustc_middle`.Nicholas Nethercote-1/+1
I am surprised the diff is so small for this enormous crate.
2024-08-14use the new Box methods in the interpreterRalf Jung-4/+2
2024-08-06miri: make vtable addresses not globally uniqueRalf Jung-94/+51
2024-08-01interpret: simplify pointer arithmetic logicRalf Jung-88/+12
2024-08-01on a signed deref check, mention the right pointer in the errorRalf Jung-9/+7
2024-07-29Rollup merge of #128277 - RalfJung:offset_from_wildcard, r=oli-obkMatthias Krüger-6/+14
miri: fix offset_from behavior on wildcard pointers offset_from wouldn't behave correctly when the "end" pointer was a wildcard pointer (result of an int2ptr cast) just at the end of the allocation. Fix that by expressing the "same allocation" check in terms of two `check_ptr_access_signed` instead of something specific to offset_from, which is both more canonical and works better with wildcard pointers. The second commit just improves diagnostics: I wanted the "pointer is dangling (has no provenance)" message to say how many bytes of memory it expected to see (since if it were 0 bytes, this would actually be legal, so it's good to tell the user that it's not 0 bytes). And then I was annoying that the error looks so different for when you deref a dangling pointer vs an out-of-bounds pointer so I made them more similar. Fixes https://github.com/rust-lang/miri/issues/3767
2024-07-29Reformat `use` declarations.Nicholas Nethercote-54/+39
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-27improve dangling/oob errors and make them more uniformRalf Jung-6/+14
2024-07-22Auto merge of #127442 - saethlin:alloc-decoding-lock, r=oli-obkbors-89/+25
Try to fix ICE from re-interning an AllocId with different allocation contents As far as I can tell, based on my investigation in https://github.com/rust-lang/rust/issues/126741, the racy decoding scheme implemented here was never fully correct, but the arrangement of Allocations that's required to ICE the compiler requires some very specific MIR optimizations to create. As far as I can tell, GVN likes to create the problematic pattern, which is why we're noticing this problem now. So the solution here is to not do racy decoding. If two threads race to decoding an AllocId, one of them is going to sit on a lock until the other is done.
2024-07-21Explain why the new setup can't deadlockBen Kimock-1/+13
2024-07-18valtree construction: keep track of which type was valtree-incompatibleRalf Jung-3/+5
2024-07-17Remove in-progress allocation decoding statesBen Kimock-89/+13
2024-07-14Add cache for `allocate_str`Adwin White-6/+11
2024-07-04Auto merge of #123781 - RalfJung:miri-fn-identity, r=oli-obkbors-23/+50
Miri function identity hack: account for possible inlining Having a non-lifetime generic is not the only reason a function can be duplicated. Another possibility is that the function may be eligible for cross-crate inlining. So also take into account the inlining attribute in this Miri hack for function pointer identity. That said, `cross_crate_inlinable` will still sometimes return true even for `inline(never)` functions: - when they are `DefKind::Ctor(..) | DefKind::Closure` -- I assume those cannot be `InlineAttr::Never` anyway? - when `cross_crate_inline_threshold == InliningThreshold::Always` so maybe this is still not quite the right criterion to use for function pointer identity.
2024-07-02Instance::resolve -> Instance::try_resolve, and other nitsMichael Goulet-2/+2
2024-07-02Miri function identity hack: account for possible inliningRalf Jung-23/+50
2024-06-22don't ICE when encountering an extern type field during validationRalf Jung-0/+2
2024-06-21add as_ptr to trait AllocBytes, fix 2 impls; add pub fn ↵Strophox-3/+23
get_bytes_unchecked_raw in allocation.rs; add pub fn get_alloc_bytes_unchecked_raw[_mut] in memory.rs
2024-06-18Rollup merge of #126583 - RalfJung:interpret-oom, r=saethlinGuillaume Gomez-2/+5
interpret: better error when we ran out of memory
2024-06-17Remove an unused validation error variantOli Scherer-3/+0
2024-06-17interpret: better error when we ran out of memoryRalf Jung-2/+5
2024-06-14Enable const evaluation for `f16` and `f128`Trevor Gross-0/+14
This excludes casting, which needs more tests.
2024-06-10ScalarInt: size mismatches are a bug, do not delay the panicRalf Jung-24/+9
2024-06-08add missing Scalar::from_i128Ralf Jung-0/+5
2024-06-05Don't walk the bodies of free constants for reachability.Oli Scherer-3/+23
2024-05-27miri: avoid making a full copy of all new allocationsRalf Jung-22/+21