Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stable_mir: Add MutMirVisitor #138536

Merged
merged 2 commits into from
Mar 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/stable_mir/src/mir.rs
Original file line number Diff line number Diff line change
@@ -5,4 +5,4 @@ pub mod pretty;
pub mod visit;

pub use body::*;
pub use visit::MirVisitor;
pub use visit::{MirVisitor, MutMirVisitor};
16 changes: 16 additions & 0 deletions compiler/stable_mir/src/mir/body.rs
Original file line number Diff line number Diff line change
@@ -77,6 +77,22 @@ impl Body {
&self.locals[self.arg_count + 1..]
}

/// Returns a mutable reference to the local that holds this function's return value.
pub(crate) fn ret_local_mut(&mut self) -> &mut LocalDecl {
&mut self.locals[RETURN_LOCAL]
}

/// Returns a mutable slice of locals corresponding to this function's arguments.
pub(crate) fn arg_locals_mut(&mut self) -> &mut [LocalDecl] {
&mut self.locals[1..][..self.arg_count]
}

/// Returns a mutable slice of inner locals for this function.
/// Inner locals are those that are neither the return local nor the argument locals.
pub(crate) fn inner_locals_mut(&mut self) -> &mut [LocalDecl] {
&mut self.locals[self.arg_count + 1..]
}

/// Convenience function to get all the locals in this function.
///
/// Locals are typically accessed via the more specific methods `ret_local`,
Loading
Loading