Skip to content

Commit e0d89e5

Browse files
committed
Avoid encoding optimized MIR for constructors
We only use mir_for_ctfe for them anyway in instance_mir. This does prevent MIR inlining of constructor calls, but constructor calls that are inlinable during MIR optimizations are rare anyway given that MIR building already inlines all direct calls to constructors.
1 parent ceb77ce commit e0d89e5

File tree

2 files changed

+4
-7
lines changed

2 files changed

+4
-7
lines changed

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,12 +1102,8 @@ fn should_encode_mir(
11021102
def_id: LocalDefId,
11031103
) -> (bool, bool) {
11041104
match tcx.def_kind(def_id) {
1105-
// Constructors
1106-
DefKind::Ctor(_, _) => {
1107-
let mir_opt_base = tcx.sess.opts.output_types.should_codegen()
1108-
|| tcx.sess.opts.unstable_opts.always_encode_mir;
1109-
(true, mir_opt_base)
1110-
}
1105+
// instance_mir uses mir_for_ctfe rather than optimized_mir for constructors
1106+
DefKind::Ctor(_, _) => (true, false),
11111107
// Constants
11121108
DefKind::AnonConst | DefKind::InlineConst | DefKind::AssocConst | DefKind::Const => {
11131109
(true, false)

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,8 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) ->
10841084
return false;
10851085
}
10861086

1087-
if !tcx.is_mir_available(def_id) {
1087+
// See comment in should_encode_mir for why we don't report an error for constructors.
1088+
if !tcx.is_mir_available(def_id) && !matches!(tcx.def_kind(def_id), DefKind::Ctor(..)) {
10881089
tcx.dcx().emit_fatal(NoOptimizedMir {
10891090
span: tcx.def_span(def_id),
10901091
crate_name: tcx.crate_name(def_id.krate),

0 commit comments

Comments
 (0)