Skip to content

Commit 2d8caf9

Browse files
committed
Make MIR inlining costs in build-std independent of config.toml
1 parent 49d353b commit 2d8caf9

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

compiler/rustc_mir_transform/src/cost_checker.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,20 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
6060

6161
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, _location: Location) {
6262
match rvalue {
63-
Rvalue::NullaryOp(NullOp::UbChecks, ..) if !self.tcx.sess.ub_checks() => {
63+
Rvalue::NullaryOp(NullOp::UbChecks, ..)
64+
if self
65+
.tcx
66+
.sess
67+
.opts
68+
.unstable_opts
69+
.inline_mir_preserve_debug
70+
.unwrap_or(!self.tcx.sess.ub_checks()) =>
71+
{
6472
// If this is in optimized MIR it's because it's used later,
6573
// so if we don't need UB checks this session, give a bonus
6674
// here to offset the cost of the call later.
75+
// But if we're building std, give it the bonus regardless of the
76+
// current configuration so we get consistent inlining.
6777
self.bonus += CALL_PENALTY;
6878
}
6979
// These are essentially constants that didn't end up in an Operand,
@@ -111,12 +121,19 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> {
111121
}
112122
}
113123
TerminatorKind::Assert { unwind, msg, .. } => {
114-
self.penalty +=
115-
if msg.is_optional_overflow_check() && !self.tcx.sess.overflow_checks() {
116-
INSTR_COST
117-
} else {
118-
CALL_PENALTY
119-
};
124+
self.penalty += if msg.is_optional_overflow_check()
125+
&& self
126+
.tcx
127+
.sess
128+
.opts
129+
.unstable_opts
130+
.inline_mir_preserve_debug
131+
.unwrap_or(!self.tcx.sess.overflow_checks())
132+
{
133+
INSTR_COST
134+
} else {
135+
CALL_PENALTY
136+
};
120137
if let UnwindAction::Cleanup(_) = unwind {
121138
self.penalty += LANDINGPAD_PENALTY;
122139
}

0 commit comments

Comments
 (0)