Skip to content

Commit 821f92b

Browse files
authored
Rollup merge of rust-lang#78771 - tmiasko:inline-consts, r=oli-obk
inliner: Copy unevaluated constants only after successful inlining Inliner copies the unevaluated constants from the callee body to the caller at the point where decision to inline is yet to be made. The constants will be unnecessary if inlining were to fail. Organize the code moving items from callee to the caller together in one place to avoid the issue.
2 parents 4651507 + 6ca43ac commit 821f92b

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

compiler/rustc_mir/src/transform/inline.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,6 @@ impl Inliner<'tcx> {
140140
continue;
141141
};
142142

143-
// Copy only unevaluated constants from the callee_body into the caller_body.
144-
// Although we are only pushing `ConstKind::Unevaluated` consts to
145-
// `required_consts`, here we may not only have `ConstKind::Unevaluated`
146-
// because we are calling `subst_and_normalize_erasing_regions`.
147-
caller_body.required_consts.extend(callee_body.required_consts.iter().copied().filter(
148-
|&constant| matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _)),
149-
));
150-
151143
let start = caller_body.basic_blocks().len();
152144
debug!("attempting to inline callsite {:?} - body={:?}", callsite, callee_body);
153145
if !self.inline_call(callsite, caller_body, callee_body) {
@@ -522,6 +514,16 @@ impl Inliner<'tcx> {
522514
kind: TerminatorKind::Goto { target: integrator.map_block(START_BLOCK) },
523515
});
524516

517+
// Copy only unevaluated constants from the callee_body into the caller_body.
518+
// Although we are only pushing `ConstKind::Unevaluated` consts to
519+
// `required_consts`, here we may not only have `ConstKind::Unevaluated`
520+
// because we are calling `subst_and_normalize_erasing_regions`.
521+
caller_body.required_consts.extend(
522+
callee_body.required_consts.iter().copied().filter(|&constant| {
523+
matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _))
524+
}),
525+
);
526+
525527
true
526528
}
527529
kind => {

0 commit comments

Comments
 (0)