mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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.
This commit is contained in:
@@ -1102,12 +1102,8 @@ fn should_encode_mir(
|
||||
def_id: LocalDefId,
|
||||
) -> (bool, bool) {
|
||||
match tcx.def_kind(def_id) {
|
||||
// Constructors
|
||||
DefKind::Ctor(_, _) => {
|
||||
let mir_opt_base = tcx.sess.opts.output_types.should_codegen()
|
||||
|| tcx.sess.opts.unstable_opts.always_encode_mir;
|
||||
(true, mir_opt_base)
|
||||
}
|
||||
// instance_mir uses mir_for_ctfe rather than optimized_mir for constructors
|
||||
DefKind::Ctor(_, _) => (true, false),
|
||||
// Constants
|
||||
DefKind::AnonConst | DefKind::InlineConst | DefKind::AssocConst | DefKind::Const => {
|
||||
(true, false)
|
||||
|
||||
@@ -1084,7 +1084,9 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) ->
|
||||
return false;
|
||||
}
|
||||
|
||||
if !tcx.is_mir_available(def_id) {
|
||||
// See comment in should_encode_mir in rustc_metadata for why we don't report
|
||||
// an error for constructors.
|
||||
if !tcx.is_mir_available(def_id) && !matches!(tcx.def_kind(def_id), DefKind::Ctor(..)) {
|
||||
tcx.dcx().emit_fatal(NoOptimizedMir {
|
||||
span: tcx.def_span(def_id),
|
||||
crate_name: tcx.crate_name(def_id.krate),
|
||||
|
||||
Reference in New Issue
Block a user