Skip to content

Commit 9b86a67

Browse files
committed
Auto merge of #152096 - bjorn3:mir_encoding_cleanups, r=<try>
Couple of cleanups and optimizations around MIR encoding
2 parents 794495e + 5b63d3f commit 9b86a67

File tree

6 files changed

+5
-20
lines changed

6 files changed

+5
-20
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,10 +1298,6 @@ impl<'a> CrateMetadataRef<'a> {
12981298
}
12991299
}
13001300

1301-
fn is_ctfe_mir_available(self, tcx: TyCtxt<'_>, id: DefIndex) -> bool {
1302-
self.root.tables.mir_for_ctfe.get((self, tcx), id).is_some()
1303-
}
1304-
13051301
fn is_item_mir_available(self, tcx: TyCtxt<'_>, id: DefIndex) -> bool {
13061302
self.root.tables.optimized_mir.get((self, tcx), id).is_some()
13071303
}

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ provide! { tcx, def_id, other, cdata,
323323
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
324324
attrs_for_def => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(tcx, def_id.index)) }
325325
is_mir_available => { cdata.is_item_mir_available(tcx, def_id.index) }
326-
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(tcx, def_id.index) }
327326
cross_crate_inlinable => { table_direct }
328327

329328
dylib_dependency_formats => { cdata.get_dylib_dependency_formats(tcx) }

compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 3 additions & 8 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)
@@ -1117,11 +1113,10 @@ fn should_encode_mir(
11171113
DefKind::SyntheticCoroutineBody => (false, true),
11181114
// Full-fledged functions + closures
11191115
DefKind::AssocFn | DefKind::Fn | DefKind::Closure => {
1120-
let generics = tcx.generics_of(def_id);
11211116
let opt = tcx.sess.opts.unstable_opts.always_encode_mir
11221117
|| (tcx.sess.opts.output_types.should_codegen()
11231118
&& reachable_set.contains(&def_id)
1124-
&& (generics.requires_monomorphization(tcx)
1119+
&& (tcx.generics_of(def_id).requires_monomorphization(tcx)
11251120
|| tcx.cross_crate_inlinable(def_id)));
11261121
// The function has a `const` modifier or is in a `const trait`.
11271122
let is_const_fn = tcx.is_const_fn(def_id.to_def_id());

compiler/rustc_middle/src/query/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,11 +1598,6 @@ rustc_queries! {
15981598
separate_provide_extern
15991599
}
16001600

1601-
query is_ctfe_mir_available(key: DefId) -> bool {
1602-
desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1603-
cache_on_disk_if { key.is_local() }
1604-
separate_provide_extern
1605-
}
16061601
query is_mir_available(key: DefId) -> bool {
16071602
desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
16081603
cache_on_disk_if { key.is_local() }

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ pub fn provide(providers: &mut Providers) {
231231
optimized_mir,
232232
check_liveness: liveness::check_liveness,
233233
is_mir_available,
234-
is_ctfe_mir_available: is_mir_available,
235234
mir_callgraph_cyclic: inline::cycle::mir_callgraph_cyclic,
236235
mir_inliner_callees: inline::cycle::mir_inliner_callees,
237236
promoted_mir,

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)