summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src/interpret
AgeCommit message (Collapse)AuthorLines
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
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-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-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-42/+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 #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-42/+24
2024-08-26const-eval: do not make UbChecks behavior depend on current crate's flagsRalf Jung-1/+11
2024-08-25Avoid taking reference of &TyKindMichael Goulet-3/+3
2024-08-24interpret: ImmTy: tighten sanity checks in offset logicRalf Jung-6/+15
2024-08-18rename AddressOf -> RawBorrow inside the compilerRalf Jung-1/+1
2024-08-14Auto merge of #128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errorsbors-6/+6
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-13Auto merge of #128742 - RalfJung:miri-vtable-uniqueness, r=saethlinbors-4/+32
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-12miri weak memory emulation: initialize store buffer only on atomic writes; ↵Ralf Jung-1/+1
pre-fill with previous value
2024-08-11Use assert_matches around the compilerMichael Goulet-5/+8
2024-08-09interpret: make identity upcasts a NOP again to avoid them generating a new ↵Ralf Jung-0/+6
random vtable
2024-08-09Shrink `TyKind::FnPtr`.Nicholas Nethercote-6/+6
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.
2024-08-08Rename struct_tail_erasing_lifetimes to struct_tail_for_codegenMichael Goulet-5/+4
2024-08-07Disallow enabling features without their implied featuresCaleb Zulawski-7/+1
2024-08-07Hide implicit target features from diagnostics when possibleCaleb Zulawski-3/+10
2024-08-06miri: make vtable addresses not globally uniqueRalf Jung-4/+26
2024-08-06various cleanups based on reviewRalf Jung-55/+54
2024-08-06make some Frame fields more privateRalf Jung-4/+12
2024-08-06interpret: refactor function call handling to be better-abstractedRalf Jung-1220/+1251
2024-08-05interpret: move nullary-op evaluation into operator.rsRalf Jung-38/+46
2024-08-03Miri: add a flag to do recursive validity checkingRalf Jung-76/+127
2024-08-02Rollup merge of #128494 - RalfJung:mir-lazy-lists, r=compiler-errorsMatthias Krüger-1/+1
MIR required_consts, mentioned_items: ensure we do not forget to fill these lists Bodies initially get created with empty required_consts and mentioned_items, but at some point those should be filled. Make sure we notice when that is forgotten.
2024-08-02Rollup merge of #128453 - RalfJung:raw_eq, r=saethlinMatthias Krüger-3/+0
raw_eq: using it on bytes with provenance is not UB (outside const-eval) The current behavior of raw_eq violates provenance monotonicity. See https://github.com/rust-lang/rust/pull/124921 for an explanation of provenance monotonicity. It is violated in raw_eq because comparing bytes without provenance is well-defined, but adding provenance makes the operation UB. So remove the no-provenance requirement from raw_eq. However, the requirement stays in-place for compile-time invocations of raw_eq, that indeed cannot deal with provenance. Cc `@rust-lang/opsem`
2024-08-01MIR required_consts, mentioned_items: ensure we do not forget to fill these ↵Ralf Jung-1/+1
lists
2024-08-01fix the way we detect overflow for inbounds arithmetic (and tweak the error ↵Ralf Jung-8/+14
message)
2024-08-01interpret: simplify pointer arithmetic logicRalf Jung-23/+7
2024-08-01on a signed deref check, mention the right pointer in the errorRalf Jung-46/+69
2024-07-31raw_eq: using it on bytes with provenance is not UB (outside const-eval)Ralf Jung-3/+0
2024-07-30Auto merge of #128083 - Mark-Simulacrum:bump-bootstrap, r=albertlarsan68bors-7/+2
Bump bootstrap compiler to new beta https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-07-29Rollup merge of #128277 - RalfJung:offset_from_wildcard, r=oli-obkMatthias Krüger-54/+68
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-104/+68
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-28step cfg(bootstrap)Mark Rousskov-7/+2
2024-07-27improve dangling/oob errors and make them more uniformRalf Jung-7/+13
2024-07-27miri: fix offset_from behavior on wildcard pointersRalf Jung-47/+55
2024-07-26Rollup merge of #127950 - nnethercote:rustfmt-skip-on-use-decls, r=cuviperMatthias Krüger-0/+2
Use `#[rustfmt::skip]` on some `use` groups to prevent reordering. `use` declarations will be reformatted in #125443. Very rarely, there is a desire to force a group of `use` declarations together in a way that auto-formatting will break up. E.g. when you want a single comment to apply to a group. #126776 dealt with all of these in the codebase, ensuring that no comments intended for multiple `use` declarations would end up in the wrong place. But some people were unhappy with it. This commit uses `#[rustfmt::skip]` to create these custom `use` groups in an idiomatic way for a few of the cases changed in #126776. This works because rustfmt treats any `use` item annotated with `#[rustfmt::skip]` as a barrier and won't reorder other `use` items around it. r? `@cuviper`
2024-07-19Rollup merge of #127856 - RalfJung:interpret-cast-sanity, r=oli-obkMatthias Krüger-41/+95
interpret: add sanity check in dyn upcast to double-check what codegen does For dyn receiver calls, we already have two codepaths: look up the function to call by indexing into the vtable, or alternatively resolve the DefId given the dynamic type of the receiver. With debug assertions enabled, the interpreter does both and compares the results. (Without debug assertions we always use the vtable as it is simpler.) This PR does the same for dyn trait upcasts. However, for casts *not* using the vtable is the easier thing to do, so now the vtable path is the debug-assertion-only path. In particular, there are cases where the vtable does not contain a pointer for upcasts but instead reuses the old pointer: when the supertrait vtable is a prefix of the larger vtable. We don't want to expose this optimization and detect UB if people do a transmute assuming this optimization, so we cannot in general use the vtable indexing path. r? ``@oli-obk``
2024-07-19Use `#[rustfmt::skip]` on some `use` groups to prevent reordering.Nicholas Nethercote-0/+2
`use` declarations will be reformatted in #125443. Very rarely, there is a desire to force a group of `use` declarations together in a way that auto-formatting will break up. E.g. when you want a single comment to apply to a group. #126776 dealt with all of these in the codebase, ensuring that no comments intended for multiple `use` declarations would end up in the wrong place. But some people were unhappy with it. This commit uses `#[rustfmt::skip]` to create these custom `use` groups in an idiomatic way for a few of the cases changed in #126776. This works because rustfmt treats any `use` item annotated with `#[rustfmt::skip]` as a barrier and won't reorder other `use` items around it.
2024-07-18interpret: add sanity check in dyn upcast to double-check what codegen doesRalf Jung-41/+95