Skip to content

Commit 1e6f784

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 ef00ebf commit 1e6f784

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

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: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,9 @@ 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 in rustc_metadata for why we don't report
1088+
// an error for constructors.
1089+
if !tcx.is_mir_available(def_id) && !matches!(tcx.def_kind(def_id), DefKind::Ctor(..)) {
10881090
tcx.dcx().emit_fatal(NoOptimizedMir {
10891091
span: tcx.def_span(def_id),
10901092
crate_name: tcx.crate_name(def_id.krate),

0 commit comments

Comments
 (0)