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:
parent
ef00ebfdec
commit
1e6f7845ed
2 changed files with 5 additions and 7 deletions
|
|
@ -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),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue