summary refs log tree commit diff
path: root/compiler/rustc_middle/src/mir/interpret
AgeCommit message (Collapse)AuthorLines
2025-03-15Move codec module back into middleMichael Goulet-15/+13
2025-03-15Fold visit into tyMichael Goulet-2/+1
2025-03-13Auto merge of #137152 - saethlin:bss-const-allocs, r=wesleywiserbors-2/+115
Add a .bss-like scheme for encoded const allocs This check if all bytes are zero feel like it should be too slow, and instead we should have a flag that we track, but that seems hard. Let's see how this perfs first. Also we can probably stash the "it's all zero actually" flag inside one of the other struct members that's already not using an entire byte. This optimization doesn't fire all that often, so it's possible that by sticking it in the varint length field, this PR actually makes rmeta size worse.
2025-03-12Rollup merge of #137701 - cuviper:sharded-hashtable, r=fmeaseMatthias Krüger-15/+5
Convert `ShardedHashMap` to use `hashbrown::HashTable` The `hash_raw_entry` feature (#56167) has finished fcp-close, so the compiler should stop using it to allow its removal. Several `Sharded` maps were using raw entries to avoid re-hashing between shard and map lookup, and we can do that with `hashbrown::HashTable` instead.
2025-03-11miri native_calls: ensure we actually expose *mutable* provenance to the ↵Ralf Jung-0/+5
memory FFI can access
2025-03-10Convert `ShardedHashMap` to use `hashbrown::HashTable`Josh Stone-15/+5
The `hash_raw_entry` feature has finished fcp-close, so the compiler should stop using it to allow its removal. Several `Sharded` maps were using raw entries to avoid re-hashing between shard and map lookup, and we can do that with `hashbrown::HashTable` instead.
2025-03-09Rollup merge of #138040 - thaliaarchi:use-prelude-size-of.compiler, ↵Matthias Krüger-3/+3
r=compiler-errors compiler: Use `size_of` from the prelude instead of imported Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. Apply this change across the compiler. These functions were added to all preludes in Rust 1.80. r? ``@compiler-errors``
2025-03-07compiler: Use size_of from the prelude instead of importedThalia Archibald-3/+3
Use `std::mem::{size_of, size_of_val, align_of, align_of_val}` from the prelude instead of importing or qualifying them. These functions were added to all preludes in Rust 1.80.
2025-03-06Rollup merge of #137920 - RalfJung:provenance-map-emptiness, r=oli-obkMichael Goulet-22/+22
interpret/provenance_map: consistently use range_is_empty https://github.com/rust-lang/rust/pull/137704 started using this for per-ptr provenance; let's be consistent and use it also for the per-byte provenance check. Also rename the methods to avoid having both "get" and "is_empty" in the name. r? ````@oli-obk````
2025-03-03Rollup merge of #137894 - compiler-errors:no-scalar-pair-opt, r=oli-obkMatthias Krüger-1/+1
Revert "store ScalarPair via memset when one side is undef and the other side can be memset" cc #137892 reverts #135335 r? oli-obk
2025-03-03interpret/provenance_map: consistently use range_is_emptyRalf Jung-22/+22
2025-03-02Revert "Auto merge of #135335 - oli-obk:push-zxwssomxxtnq, r=saethlin"Michael Goulet-1/+1
This reverts commit a7a6c64a657f68113301c2ffe0745b49a16442d1, reversing changes made to ebbe63891f1fae21734cb97f2f863b08b1d44bf8.
2025-02-27Optimize empty provenance range checks.Nicholas Nethercote-10/+27
Currently it gets the pointers in the range and checks if the result is empty, but it can be done faster if you combine those two steps.
2025-02-25Teach structured errors to display short `Ty`Esteban Küber-4/+4
Make it so that every structured error annotated with `#[derive(Diagnostic)]` that has a field of type `Ty<'_>`, the printing of that value into a `String` will look at the thread-local storage `TyCtxt` in order to shorten to a length appropriate with the terminal width. When this happen, the resulting error will have a note with the file where the full type name was written to. ``` error[E0618]: expected function, found `((..., ..., ..., ...), ..., ..., ...)`` --> long.rs:7:5 | 6 | fn foo(x: D) { //~ `x` has type `(... | - `x` has type `((..., ..., ..., ...), ..., ..., ...)` 7 | x(); //~ ERROR expected function, found `(... | ^-- | | | call expression requires function | = note: the full name for the type has been written to 'long.long-type-14182675702747116984.txt' = note: consider using `--verbose` to print the full type name to the console ```
2025-02-22Greatly simplify lifetime captures in edition 2024Michael Goulet-1/+1
2025-02-19Add a .bss-like scheme for encoded const allocsBen Kimock-2/+115
2025-02-19Make fewer crates depend on rustc_ast_irMichael Goulet-2/+1
2025-02-11Rollup merge of #136847 - nnethercote:simplify-intra-crate-quals, r=oli-obkMatthias Krüger-1/+1
Simplify intra-crate qualifiers. The following is a weird pattern for a file within `rustc_middle`: ``` use rustc_middle::aaa; use crate::bbb; ``` More sensible and standard would be this: ``` use crate::{aaa, bbb}; ``` I.e. we generally prefer using `crate::` to using a crate's own name. (Exceptions are things like in macros where `crate::` doesn't work because the macro is used in multiple crates.) This commit fixes a bunch of these weird qualifiers. r? `@jieyouxu`
2025-02-11Simplify intra-crate qualifiers.Nicholas Nethercote-1/+1
The following is a weird pattern for a file within `rustc_middle`: ``` use rustc_middle::aaa; use crate::bbb; ``` More sensible and standard would be this: ``` use crate::{aaa, bbb}; ``` I.e. we generally prefer using `crate::` to using a crate's own name. (Exceptions are things like in macros where `crate::` doesn't work because the macro is used in multiple crates.) This commit fixes a bunch of these weird qualifiers.
2025-02-10compiler: die immediately instead of handling unknown target codegenJubilee Young-4/+0
We cannot produce anything useful if asked to compile unknown targets. We should handle the error immediately at the point of discovery instead of propagating it upward, and preferably in the simplest way: Die. This allows cleaning up our "error-handling" spread across 5 crates.
2025-02-08Rustfmtbjorn3-4/+7
2025-02-06Clean up trivial traversal/lift impl generator macro calls.Nicholas Nethercote-2/+0
We have four macros for generating trivial traversal (fold/visit) and lift impls. - `rustc_ir::TrivialTypeTraversalImpls` - `rustc_middle::TrivialTypeTraversalImpls` - `rustc_middle::TrivialLiftImpls` - `rustc_middle::TrivialTypeTraversalAndLiftImpls` The first two are very similar. The last one just combines the second and third one. The macros themselves are ok, but their use is a mess. This commit does the following. - Removes types that no longer need a lift and/or traversal impl from the macro calls. - Consolidates the macro calls into the smallest number of calls possible, with each one mentioning as many types as possible. - Orders the types within those macro calls alphabetically, and makes the module qualification more consistent. - Eliminates `rustc_middle::mir::type_foldable`, because the macro calls were merged and the manual `TypeFoldable` impls are better placed in `structural_impls.rs`, alongside all the other ones. This makes the code more concise. Moving forward, it also makes it more obvious where new types should be added.
2025-02-04Auto merge of #136115 - Mark-Simulacrum:shard-alloc-id, r=RalfJungbors-24/+42
Shard AllocMap Lock This improves performance on many-seed parallel (-Zthreads=32) miri executions from managing to use ~8 cores to using 27-28 cores, which is about the same as what I see with the data structure proposed in https://github.com/rust-lang/rust/pull/136105 - I haven't analyzed but I suspect the sharding might actually work out better if we commonly insert "densely" since sharding would split the cache lines and the OnceVec packs locks close together. Of course, we could do something similar with the bitset lock too. Either way, this seems like a very reasonable starting point that solves the problem ~equally well on what I can test locally. r? `@RalfJung`
2025-02-01Shard AllocMap LockMark Rousskov-24/+42
This improves performance on many-seed parallel (-Zthreads=32) miri executions from managing to use ~8 cores to using 27-28 cores. That's pretty reasonable scaling for the simplicity of this solution.
2025-02-01Rename `tcx.ensure()` to `tcx.ensure_ok()`Zalathar-2/+2
2025-01-28miri: optimize zeroed allocSpecificProtagonist-8/+22
Co-authored-by: Ralf Jung <post@ralfj.de>
2025-01-21Also generate undef scalars and scalar pairsOli Scherer-1/+1
2025-01-19Manual cleanup of some `is_{or_none|some_and}` usagesYotam Ofek-1/+1
2025-01-19Run `clippy --fix` for `unnecessary_map_or` lintYotam Ofek-2/+2
2025-01-09Remove the now-useless `Result` from `lit_to_const`Oli Scherer-9/+0
2025-01-09Use error constant instead of explicit error handlingOli Scherer-2/+0
2024-12-31Rollup merge of #134949 - compiler-errors:froms, r=jieyouxuStuart Cook-3/+3
Convert some `Into` impls into `From` impls From the [`From`](https://doc.rust-lang.org/std/convert/trait.From.html) docs: > One should always prefer implementing `From` over [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) because implementing `From` automatically provides one with an implementation of [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) thanks to the blanket implementation in the standard library. > > Only implement [`Into`](https://doc.rust-lang.org/std/convert/trait.Into.html) when targeting a version prior to Rust 1.41 and converting to a type outside the current crate. `From` was not able to do these types of conversions in earlier versions because of Rust’s orphaning rules. See [Into](https://doc.rust-lang.org/std/convert/trait.Into.html) for more details. Some of these impls are likely from before 1.41, and then some others were probably just mistakes. Building nightly rust is definitely not supported on 1.41, so let's modernize these impls :D
2024-12-31Convert some Into impls into From implsMichael Goulet-3/+3
2024-12-30Fix typosNoName-6/+6
2024-12-18Variants::Single: do not use invalid VariantIdx for uninhabited enumsRalf Jung-1/+1
2024-12-09fix ICE on type error in promotedRalf Jung-18/+24
2024-12-06Rollup merge of #133211 - Strophox:miri-correct-state-update-ffi, r=RalfJungMatthias Krüger-0/+50
Extend Miri to correctly pass mutable pointers through FFI Based off of https://github.com/rust-lang/rust/pull/129684, this PR further extends Miri to execute native calls that make use of pointers to *mutable* memory. We adapt Miri's bookkeeping of internal state upon any FFI call that gives external code permission to mutate memory. Native code may now possibly write and therefore initialize and change the pointer provenance of bytes it has access to: Such memory is assumed to be *initialized* afterwards and bytes are given *arbitrary (wildcard) provenance*. This enables programs that correctly use mutating FFI calls to run Miri without errors, at the cost of possibly missing Undefined Behaviour caused by incorrect usage of mutating FFI. > <details> > > <summary> Simple example </summary> > > ```rust > extern "C" { > fn init_int(ptr: *mut i32); > } > > fn main() { > let mut x = std::mem::MaybeUninit::<i32>::uninit(); > let x = unsafe { > init_int(x.as_mut_ptr()); > x.assume_init() > }; > > println!("C initialized my memory to: {x}"); > } > ``` > ```c > void init_int(int *ptr) { > *ptr = 42; > } > ``` > should now show `C initialized my memory to: 42`. > > </details> r? ``@RalfJung``
2024-12-05extend Miri to correctly pass mutable pointers through FFIStrophox-0/+50
Co-authored-by: Ralf Jung <post@ralfj.de>
2024-12-01fix ICE when promoted has layout size overflowRalf Jung-17/+9
2024-11-23no more Reveal :(lcnr-2/+2
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