Skip to content

Add the function body span to StableMIR #119100

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

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions compiler/rustc_smir/src/rustc_smir/convert/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ impl<'tcx> Stable<'tcx> for mir::Body<'tcx> {
self.arg_count,
self.var_debug_info.iter().map(|info| info.stable(tables)).collect(),
self.spread_arg.stable(tables),
self.span.stable(tables),
)
}
}
Expand Down
6 changes: 5 additions & 1 deletion compiler/stable_mir/src/mir/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ pub struct Body {
///
/// This is used for the "rust-call" ABI such as closures.
pub(super) spread_arg: Option<Local>,

/// The span that covers the entire function body.
pub span: Span,
}

pub type BasicBlockIdx = usize;
Expand All @@ -42,14 +45,15 @@ impl Body {
arg_count: usize,
var_debug_info: Vec<VarDebugInfo>,
spread_arg: Option<Local>,
span: Span,
) -> Self {
// If locals doesn't contain enough entries, it can lead to panics in
// `ret_local`, `arg_locals`, and `inner_locals`.
assert!(
locals.len() > arg_count,
"A Body must contain at least a local for the return value and each of the function's arguments"
);
Self { blocks, locals, arg_count, var_debug_info, spread_arg }
Self { blocks, locals, arg_count, var_debug_info, spread_arg, span }
}

/// Return local that holds this function's return value.
Expand Down
4 changes: 3 additions & 1 deletion compiler/stable_mir/src/mir/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub trait MirVisitor {
}

fn super_body(&mut self, body: &Body) {
let Body { blocks, locals: _, arg_count, var_debug_info, spread_arg: _ } = body;
let Body { blocks, locals: _, arg_count, var_debug_info, spread_arg: _, span } = body;

for bb in blocks {
self.visit_basic_block(bb);
Expand All @@ -153,6 +153,8 @@ pub trait MirVisitor {
for info in var_debug_info.iter() {
self.visit_var_debug_info(info);
}

self.visit_span(span)
}

fn super_basic_block(&mut self, bb: &BasicBlock) {
Expand Down