Auto merge of #152096 - bjorn3:mir_encoding_cleanups, r=oli-obk
Couple of cleanups and optimizations around MIR encoding
This commit is contained in:
commit
f889772d65
6 changed files with 6 additions and 20 deletions
|
|
@ -1298,10 +1298,6 @@ impl<'a> CrateMetadataRef<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_ctfe_mir_available(self, tcx: TyCtxt<'_>, id: DefIndex) -> bool {
|
|
||||||
self.root.tables.mir_for_ctfe.get((self, tcx), id).is_some()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn is_item_mir_available(self, tcx: TyCtxt<'_>, id: DefIndex) -> bool {
|
fn is_item_mir_available(self, tcx: TyCtxt<'_>, id: DefIndex) -> bool {
|
||||||
self.root.tables.optimized_mir.get((self, tcx), id).is_some()
|
self.root.tables.optimized_mir.get((self, tcx), id).is_some()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -324,7 +324,6 @@ provide! { tcx, def_id, other, cdata,
|
||||||
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
|
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
|
||||||
attrs_for_def => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(tcx, def_id.index)) }
|
attrs_for_def => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(tcx, def_id.index)) }
|
||||||
is_mir_available => { cdata.is_item_mir_available(tcx, def_id.index) }
|
is_mir_available => { cdata.is_item_mir_available(tcx, def_id.index) }
|
||||||
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(tcx, def_id.index) }
|
|
||||||
cross_crate_inlinable => { table_direct }
|
cross_crate_inlinable => { table_direct }
|
||||||
|
|
||||||
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
|
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }
|
||||||
|
|
|
||||||
|
|
@ -1102,12 +1102,8 @@ fn should_encode_mir(
|
||||||
def_id: LocalDefId,
|
def_id: LocalDefId,
|
||||||
) -> (bool, bool) {
|
) -> (bool, bool) {
|
||||||
match tcx.def_kind(def_id) {
|
match tcx.def_kind(def_id) {
|
||||||
// Constructors
|
// instance_mir uses mir_for_ctfe rather than optimized_mir for constructors
|
||||||
DefKind::Ctor(_, _) => {
|
DefKind::Ctor(_, _) => (true, false),
|
||||||
let mir_opt_base = tcx.sess.opts.output_types.should_codegen()
|
|
||||||
|| tcx.sess.opts.unstable_opts.always_encode_mir;
|
|
||||||
(true, mir_opt_base)
|
|
||||||
}
|
|
||||||
// Constants
|
// Constants
|
||||||
DefKind::AnonConst | DefKind::InlineConst | DefKind::AssocConst | DefKind::Const => {
|
DefKind::AnonConst | DefKind::InlineConst | DefKind::AssocConst | DefKind::Const => {
|
||||||
(true, false)
|
(true, false)
|
||||||
|
|
@ -1117,11 +1113,10 @@ fn should_encode_mir(
|
||||||
DefKind::SyntheticCoroutineBody => (false, true),
|
DefKind::SyntheticCoroutineBody => (false, true),
|
||||||
// Full-fledged functions + closures
|
// Full-fledged functions + closures
|
||||||
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
|
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
|
||||||
let generics = tcx.generics_of(def_id);
|
|
||||||
let opt = tcx.sess.opts.unstable_opts.always_encode_mir
|
let opt = tcx.sess.opts.unstable_opts.always_encode_mir
|
||||||
|| (tcx.sess.opts.output_types.should_codegen()
|
|| (tcx.sess.opts.output_types.should_codegen()
|
||||||
&& reachable_set.contains(&def_id)
|
&& reachable_set.contains(&def_id)
|
||||||
&& (generics.requires_monomorphization(tcx)
|
&& (tcx.generics_of(def_id).requires_monomorphization(tcx)
|
||||||
|| tcx.cross_crate_inlinable(def_id)));
|
|| tcx.cross_crate_inlinable(def_id)));
|
||||||
// The function has a `const` modifier or is in a `const trait`.
|
// The function has a `const` modifier or is in a `const trait`.
|
||||||
let is_const_fn = tcx.is_const_fn(def_id.to_def_id());
|
let is_const_fn = tcx.is_const_fn(def_id.to_def_id());
|
||||||
|
|
|
||||||
|
|
@ -1588,11 +1588,6 @@ rustc_queries! {
|
||||||
separate_provide_extern
|
separate_provide_extern
|
||||||
}
|
}
|
||||||
|
|
||||||
query is_ctfe_mir_available(key: DefId) -> bool {
|
|
||||||
desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
|
|
||||||
cache_on_disk_if { key.is_local() }
|
|
||||||
separate_provide_extern
|
|
||||||
}
|
|
||||||
query is_mir_available(key: DefId) -> bool {
|
query is_mir_available(key: DefId) -> bool {
|
||||||
desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
|
desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
|
||||||
cache_on_disk_if { key.is_local() }
|
cache_on_disk_if { key.is_local() }
|
||||||
|
|
|
||||||
|
|
@ -229,7 +229,6 @@ pub fn provide(providers: &mut Providers) {
|
||||||
optimized_mir,
|
optimized_mir,
|
||||||
check_liveness: liveness::check_liveness,
|
check_liveness: liveness::check_liveness,
|
||||||
is_mir_available,
|
is_mir_available,
|
||||||
is_ctfe_mir_available: is_mir_available,
|
|
||||||
mir_callgraph_cyclic: inline::cycle::mir_callgraph_cyclic,
|
mir_callgraph_cyclic: inline::cycle::mir_callgraph_cyclic,
|
||||||
mir_inliner_callees: inline::cycle::mir_inliner_callees,
|
mir_inliner_callees: inline::cycle::mir_inliner_callees,
|
||||||
promoted_mir,
|
promoted_mir,
|
||||||
|
|
|
||||||
|
|
@ -1085,7 +1085,9 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) ->
|
||||||
return false;
|
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 {
|
tcx.dcx().emit_fatal(NoOptimizedMir {
|
||||||
span: tcx.def_span(def_id),
|
span: tcx.def_span(def_id),
|
||||||
crate_name: tcx.crate_name(def_id.krate),
|
crate_name: tcx.crate_name(def_id.krate),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue