Add a public API to get all body locals

This is particularly helpful for the ui tests, but also could be helpful
for Stable MIR users who just want all the locals without needing to
concatenate responses
This commit is contained in:
Kirby Linvill 2023-10-25 22:09:12 +01:00
parent 372c533532
commit 39b293fb5a
No known key found for this signature in database
GPG Key ID: E304CE3F028E6E3F
2 changed files with 9 additions and 1 deletions

View File

@ -48,6 +48,14 @@ impl Body {
pub fn internal_locals(&self) -> &[LocalDecl] {
&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`,
/// `arg_locals`, and `internal_locals`.
pub fn locals(&self) -> &[LocalDecl] {
&self.locals
}
}
type LocalDecls = Vec<LocalDecl>;

View File

@ -59,7 +59,7 @@ fn test_body(body: mir::Body) {
for term in body.blocks.iter().map(|bb| &bb.terminator) {
match &term.kind {
Call { func, .. } => {
let TyKind::RigidTy(ty) = func.ty(&body.locals).kind() else { unreachable!() };
let TyKind::RigidTy(ty) = func.ty(&body.locals()).kind() else { unreachable!() };
let RigidTy::FnDef(def, args) = ty else { unreachable!() };
let result = Instance::resolve(def, &args);
assert!(result.is_ok());