Skip to content

Commit ea37c63

Browse files
committed
Auto merge of rust-lang#123011 - scottmcm:inline-debuginfo-cost, r=<try>
[EXPERIMENT] Add a debug-info cost to MIR inlining Inspired by all the MIR I keep looking at that's inlined away like 7 different function calls so the body is 2 statements but 30 debug-infos. r? ghost
2 parents 0824b30 + 9bae087 commit ea37c63

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

compiler/rustc_mir_transform/src/cost_checker.rs

+12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@ const CALL_PENALTY: usize = 25;
77
const LANDINGPAD_PENALTY: usize = 50;
88
const RESUME_PENALTY: usize = 45;
99

10+
// While debug info has no runtime cost, when inlining we do need to copy it
11+
// into the caller MIR, which means we should give it a small cost to represent
12+
// the compile-time impact of doing that, since just because something has few
13+
// instructions doesn't necessarily mean it's cheap for us to inline.
14+
// The backend can, of course, still inline such things later should it so wish.
15+
const DEBUG_INFO_COST: usize = 4;
16+
1017
/// Verify that the callee body is compatible with the caller.
1118
#[derive(Clone)]
1219
pub(crate) struct CostChecker<'b, 'tcx> {
@@ -41,6 +48,11 @@ impl<'b, 'tcx> CostChecker<'b, 'tcx> {
4148
}
4249

4350
impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
51+
fn visit_body(&mut self, body: &Body<'tcx>) {
52+
self.cost += body.var_debug_info.len() * DEBUG_INFO_COST;
53+
self.super_body(body)
54+
}
55+
4456
fn visit_statement(&mut self, statement: &Statement<'tcx>, _: Location) {
4557
// Don't count StorageLive/StorageDead in the inlining cost.
4658
match statement.kind {

0 commit comments

Comments
 (0)