about summary refs log tree commit diff
path: root/compiler/stable_mir/src/mir
AgeCommit message (Collapse)AuthorLines
2025-07-14rename `stable_mir` to `rustc_public`, and `rustc_smir` to `rustc_public_bridge`Makai-2579/+0
2025-07-09Add opaque TypeId handles for CTFEOli Scherer-0/+3
2025-07-06move `stable_mir` back to its own crate and move `rustc_internal` to ↵Makai-0/+2576
the`stable_mir` crate As part of this reorganization, some traits need to be moved from `rustc_smir::context::traits` to `stable_mir::unstable::internal_cx`. These traits are specifically designed for `InternalCx` to clarify the behavior of different functions that share the same name. This move is necessary to avoid orphan rule violations.
2025-04-05let `rustc_smir` host `stable_mir` for refactoringMakai-2550/+0
2025-04-05Rollup merge of #138826 - makai410:assoc-items, r=celinvalStuart Cook-1/+11
StableMIR: Add `associated_items`. Resolves: https://github.com/rust-lang/project-stable-mir/issues/87
2025-04-01Implement `associated_items` api.makai410-1/+11
2025-03-28use `try_fold` instead of `fold`Yotam Ofek-3/+2
2025-03-22Rollup merge of #138536 - makai410:mut-mir-visitor, r=celinvalMatthias Krüger-331/+427
stable_mir: Add `MutMirVisitor` Resolves: [rust-lang/project-stable-mir#81](https://github.com/rust-lang/project-stable-mir/issues/81). I am unsure if we should add a `MutableBody` like Kani did. Currently, I use `&mut Body` in `MutMirVisitor::visit_body()`. r? ``````@celinval``````
2025-03-18Add `MutMirVisitor`makai410-331/+427
Implement `make_mir_visitor` macro to generate `MirVisitor` and `MutMirVisitor`. Add `ret_local_mut()`, `arg_locals_mut()` and `inner_locals_mut()` to `Body`, specifically for `MutMirVisitor`.
2025-03-07compiler: Use size_of from the prelude instead of importedThalia Archibald-2/+2
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-02-22Greatly simplify lifetime captures in edition 2024Michael Goulet-1/+1
2025-02-08occured -> occurredMichael Goulet-2/+2
2025-02-03Contracts core intrinsics.Felix S. Klock II-1/+4
These are hooks to: 1. control whether contract checks are run 2. allow 3rd party tools to intercept and reintepret the results of running contracts.
2025-01-31Insert null checks for pointer dereferences when debug assertions are enabledBastian Kersting-1/+9
Similar to how the alignment is already checked, this adds a check for null pointer dereferences in debug mode. It is implemented similarly to the alignment check as a MirPass. This is related to a 2025H1 project goal for better UB checks in debug mode: https://github.com/rust-lang/rust-project-goals/pull/177.
2025-01-28Represent the raw pointer for a array length check as a new kind of fake borrowMichael Goulet-5/+33
2024-12-14Encode coroutine-closures in SMIRMichael Goulet-2/+10
2024-11-07[StableMIR] A few fixes to pretty printingCelina G. Val-25/+76
Improve identation, and a few other rvalue printing
2024-10-16Rollup merge of #131778 - practicalrs:fix_needless_lifetimes, r=jieyouxuMatthias Krüger-1/+1
Fix needless_lifetimes in stable_mir Hi, This PR fixes the following clippy warning ``` warning: the following explicit lifetimes could be elided: 'a --> compiler/stable_mir/src/mir/visit.rs:490:6 | 490 | impl<'a> PlaceRef<'a> { | ^^ ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes = note: `#[warn(clippy::needless_lifetimes)]` on by default help: elide the lifetimes | 490 - impl<'a> PlaceRef<'a> { 490 + impl PlaceRef<'_> { | ``` Best regards, Michal
2024-10-16Rollup merge of #131777 - practicalrs:fix_trivially_copy_pass_by_ref, r=jieyouxuMatthias Krüger-3/+3
Fix trivially_copy_pass_by_ref in stable_mir Hi, This PR fixes the following clippy warnings ``` warning: this argument (8 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> compiler/stable_mir/src/mir/body.rs:1042:34 | 1042 | fn subslice_ty(ty: Ty, from: &u64, to: &u64, from_end: &bool) -> Result<Ty, Error> { | ^^^^ help: consider passing by value instead: `u64` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref = note: requested on the command line with `-W clippy::trivially-copy-pass-by-ref` warning: this argument (8 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> compiler/stable_mir/src/mir/body.rs:1042:44 | 1042 | fn subslice_ty(ty: Ty, from: &u64, to: &u64, from_end: &bool) -> Result<Ty, Error> { | ^^^^ help: consider passing by value instead: `u64` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref warning: this argument (1 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte) --> compiler/stable_mir/src/mir/body.rs:1042:60 | 1042 | fn subslice_ty(ty: Ty, from: &u64, to: &u64, from_end: &bool) -> Result<Ty, Error> { | ^^^^^ help: consider passing by value instead: `bool` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#trivially_copy_pass_by_ref ``` Best regards, Michal
2024-10-16Fix needless_lifetimes in stable_mirMichal Piotrowski-1/+1
2024-10-16Fix trivially_copy_pass_by_ref in stable_mirMichal Piotrowski-3/+3
2024-10-16Rollup merge of #131700 - practicalrs:fix_match_same_arms, r=celinvalUrgau-29/+17
Fix match_same_arms in stable_mir Hi, This PR fixes some clippy warnings (Reopened https://github.com/rust-lang/rust/pull/131688) ``` warning: this match arm has an identical body to another arm --> compiler/stable_mir/src/mir/visit.rs:197:13 | 197 | / StatementKind::FakeRead(_, place) => { 198 | | self.visit_place(place, PlaceContext::NON_MUTATING, location); 199 | | } | |_____________^ | = help: try changing either arm body = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_same_arms help: or try merging the arm patterns | 197 | StatementKind::FakeRead(_, place) | StatementKind::PlaceMention(place) => { | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ help: and remove this obsolete arm | 209 - StatementKind::PlaceMention(place) => { 210 - self.visit_place(place, PlaceContext::NON_MUTATING, location); 211 - } | ``` Best regards, Michal
2024-10-15Fix uninlined_format_args in stable_mirMichal Piotrowski-12/+12
2024-10-14Fix match_same_arms in stable_mirMichal Piotrowski-29/+17
2024-10-05clarify semantics of ConstantIndex MIR projectionRalf Jung-2/+4
2024-10-04Rollup merge of #131194 - practicalrs:fix_needless_lifetimes, r=celinvalJubilee-2/+2
Fix needless_lifetimes in stable_mir Hi, This PR fixes the following clippy warning in stable_mir ``` warning: the following explicit lifetimes could be elided: 'a --> compiler/stable_mir/src/mir/visit.rs:79:30 | 79 | fn visit_projection_elem<'a>( | ^^ 80 | &mut self, 81 | place_ref: PlaceRef<'a>, | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_lifetimes = note: `#[warn(clippy::needless_lifetimes)]` on by default help: elide the lifetimes | 79 ~ fn visit_projection_elem( 80 | &mut self, 81 ~ place_ref: PlaceRef<'_>, | ``` Best regards, Michal
2024-10-04Use wide pointers consistenly across the compilerUrgau-3/+3
2024-10-03Fix needless_lifetimes in stable_mirMichal Piotrowski-2/+2
2024-09-24unify dyn* coercions with other pointer coercionsLukas Markeffsky-0/+1
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-3/+3
2024-08-23Introduce methods for obtaining `Location` for statements and terminatorsArtem Agvanian-4/+14
2024-08-16Add an ability to convert between `Span` and `visit::Location`Artem Agvanian-0/+6
2024-07-29Reformat `use` declarations.Nicholas Nethercote-13/+18
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-07-25Auto merge of #126963 - runtimeverification:smir_serde_derive, r=celinvalbors-46/+50
Add basic Serde serialization capabilities to Stable MIR This PR adds basic Serde serialization capabilities to Stable MIR. It is intentionally minimal (just wrapping all stable MIR types with a Serde `derive`), so that any important design decisions can be discussed before going further. A simple test is included with this PR to validate that JSON can actually be emitted. ## Notes When I wrapped the Stable MIR error types in `compiler/stable_mir/src/error.rs`, it caused test failures (though I'm not sure why) so I backed those out. ## Future Work So, this PR will support serializing basic stable MIR, but it _does not_ support serializing interned values beneath `Ty`s and `AllocId`s, etc... My current thinking about how to handle this is as follows: 1. Add new `visited_X` fields to the `Tables` struct for each interned category of interest. 2. As serialization is occuring, serialize interned values as usual _and_ also record the interned value we referenced in `visited_X`. (Possibly) In addition, if an interned value recursively references other interned values, record those interned values as well. 3. Teach the stable MIR `Context` how to access the `visited_X` values and expose them with wrappers in `stable_mir/src/lib.rs` to users (e.g. to serialize and/or further analyze them). ### Pros This approach does not commit to any specific serialization format regarding interned values or other more complex cases, which avoids us locking into any behaviors that may not be desired long-term. ### Cons The user will need to manually handle serializing interned values. ### Alternatives 1. We can directly provide access to the underlying `Tables` maps for interned values; the disadvantage of this approach is that it either requires extra processing for users to filter out to only use the values that they need _or_ users may serialize extra values that they don't need. The advantage is that the implementation is even simpler. The other pros/cons are similar to the above. 2. We can directly serialize interned values by expanding them in-place. The pro is that this may make some basic inputs easier to consume. However, the cons are that there will need to be special provisions for dealing with cyclical values on both the producer and consumer _and_ global values will possibly need to be de-duplicated on the consumer side.
2024-07-19Avoid ref when using format! in compilerYuri Astrakhan-5/+5
Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.
2024-06-26add serde derive Serialize to stable_mirStephen Skeirik-46/+50
2024-06-20Add blank lines after module-level `//!` comments.Nicholas Nethercote-0/+1
Most modules have such a blank line, but some don't. Inserting the blank line makes it clearer that the `//!` comments are describing the entire module, rather than the `use` declaration(s) that immediately follows.
2024-06-13smir: merge identical Constant and ConstOperand typesRalf Jung-24/+17
2024-06-04Split smir `Const` into `TyConst` and `MirConst`Boxy-19/+32
2024-05-30Apply x clippy --fix and x fmtr0cky-2/+2
2024-05-28Add an intrinsic for `ptr::metadata`Scott McMurray-1/+13
2024-05-23Rollup merge of #125336 - momvart:smir-77-intrinsic, r=celinvalLeón Orell Valerian Liehr-1/+3
Add dedicated definition for intrinsics Closes rust-lang/project-stable-mir#77
2024-05-20Add intrinsic definition and retrieval APIsMohammad Omidvar-1/+3
2024-05-17Rename Unsafe to SafetySantiago Pastorino-1/+1
2024-04-23Rollup merge of #122598 - Nadrieril:full-derefpats, r=matthewjasperLeón Orell Valerian Liehr-8/+18
deref patterns: lower deref patterns to MIR This lowers deref patterns to MIR. This is a bit tricky because this is the first kind of pattern that requires storing a value in a temporary. Thanks to https://github.com/rust-lang/rust/pull/123324 false edges are no longer a problem. The thing I'm not confident about is the handling of fake borrows. This PR ignores any fake borrows inside a deref pattern. We are guaranteed to at least fake borrow the place of the first pointer value, which could be enough, but I'm not certain.
2024-04-23Auto merge of #121801 - zetanumbers:async_drop_glue, r=oli-obkbors-1/+4
Add simple async drop glue generation This is a prototype of the async drop glue generation for some simple types. Async drop glue is intended to behave very similar to the regular drop glue except for being asynchronous. Currently it does not execute synchronous drops but only calls user implementations of `AsyncDrop::async_drop` associative function and awaits the returned future. It is not complete as it only recurses into arrays, slices, tuples, and structs and does not have same sensible restrictions as the old `Drop` trait implementation like having the same bounds as the type definition, while code assumes their existence (requires a future work). This current design uses a workaround as it does not create any custom async destructor state machine types for ADTs, but instead uses types defined in the std library called future combinators (deferred_async_drop, chain, ready_unit). Also I recommend reading my [explainer](https://zetanumbers.github.io/book/async-drop-design.html). This is a part of the [MCP: Low level components for async drop](https://github.com/rust-lang/compiler-team/issues/727) work. Feature completeness: - [x] `AsyncDrop` trait - [ ] `async_drop_in_place_raw`/async drop glue generation support for - [x] Trivially destructible types (integers, bools, floats, string slices, pointers, references, etc.) - [x] Arrays and slices (array pointer is unsized into slice pointer) - [x] ADTs (enums, structs, unions) - [x] tuple-like types (tuples, closures) - [ ] Dynamic types (`dyn Trait`, see explainer's [proposed design](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#async-drop-glue-for-dyn-trait)) - [ ] coroutines (https://github.com/rust-lang/rust/pull/123948) - [x] Async drop glue includes sync drop glue code - [x] Cleanup branch generation for `async_drop_in_place_raw` - [ ] Union rejects non-trivially async destructible fields - [ ] `AsyncDrop` implementation requires same bounds as type definition - [ ] Skip trivially destructible fields (optimization) - [ ] New [`TyKind::AdtAsyncDestructor`](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#adt-async-destructor-types) and get rid of combinators - [ ] [Synchronously undroppable types](https://github.com/zetanumbers/posts/blob/main/async-drop-design.md#exclusively-async-drop) - [ ] Automatic async drop at the end of the scope in async context
2024-04-21Add `AggregateKind::RawPtr` and enough support to compileScott McMurray-0/+2
2024-04-20Add a non-shallow fake borrowNadrieril-8/+18
2024-04-18Fix disabling the export of noop async_drop_in_place_rawDaria Sukhonina-1/+4
2024-04-10Rollup merge of #123659 - celinval:smir-fix-intrinsic, r=oli-obkGuillaume Gomez-1/+10
Add support to intrinsics fallback body Before this fix, the call to `body()` would crash, since `has_body()` would return true, but we would try to retrieve the body of an intrinsic which is not allowed. Instead, the `Instance::body()` function will now convert an Intrinsic into an Item before retrieving its body. Note: I also changed how we monomorphize the instance body. Unfortunately, the call still ICE for some shims. r? `@oli-obk`