Skip to content

Commit 1cb17dd

Browse files
authored
Rollup merge of rust-lang#138536 - makai410:mut-mir-visitor, r=celinval
stable_mir: Add `MutMirVisitor` Resolves: [rust-lang/project-stable-mir#81](rust-lang/project-stable-mir#81). I am unsure if we should add a `MutableBody` like Kani did. Currently, I use `&mut Body` in `MutMirVisitor::visit_body()`. r? ``````@celinval``````
2 parents e832680 + ad315f6 commit 1cb17dd

File tree

4 files changed

+508
-333
lines changed

4 files changed

+508
-333
lines changed

compiler/stable_mir/src/mir.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ pub mod pretty;
55
pub mod visit;
66

77
pub use body::*;
8-
pub use visit::MirVisitor;
8+
pub use visit::{MirVisitor, MutMirVisitor};

compiler/stable_mir/src/mir/body.rs

+16
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,22 @@ impl Body {
7777
&self.locals[self.arg_count + 1..]
7878
}
7979

80+
/// Returns a mutable reference to the local that holds this function's return value.
81+
pub(crate) fn ret_local_mut(&mut self) -> &mut LocalDecl {
82+
&mut self.locals[RETURN_LOCAL]
83+
}
84+
85+
/// Returns a mutable slice of locals corresponding to this function's arguments.
86+
pub(crate) fn arg_locals_mut(&mut self) -> &mut [LocalDecl] {
87+
&mut self.locals[1..][..self.arg_count]
88+
}
89+
90+
/// Returns a mutable slice of inner locals for this function.
91+
/// Inner locals are those that are neither the return local nor the argument locals.
92+
pub(crate) fn inner_locals_mut(&mut self) -> &mut [LocalDecl] {
93+
&mut self.locals[self.arg_count + 1..]
94+
}
95+
8096
/// Convenience function to get all the locals in this function.
8197
///
8298
/// Locals are typically accessed via the more specific methods `ret_local`,

0 commit comments

Comments
 (0)