Skip to content

Commit f889772

Browse files
committed
Auto merge of rust-lang#152096 - bjorn3:mir_encoding_cleanups, r=oli-obk
Couple of cleanups and optimizations around MIR encoding
2 parents 66daca1 + 05921d4 commit f889772

File tree

6 files changed

+6
-20
lines changed

6 files changed

+6
-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
@@ -324,7 +324,6 @@ provide! { tcx, def_id, other, cdata,
324324
inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) }
325325
attrs_for_def => { tcx.arena.alloc_from_iter(cdata.get_item_attrs(tcx, def_id.index)) }
326326
is_mir_available => { cdata.is_item_mir_available(tcx, def_id.index) }
327-
is_ctfe_mir_available => { cdata.is_ctfe_mir_available(tcx, def_id.index) }
328327
cross_crate_inlinable => { table_direct }
329328

330329
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/queries.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,11 +1588,6 @@ rustc_queries! {
15881588
separate_provide_extern
15891589
}
15901590

1591-
query is_ctfe_mir_available(key: DefId) -> bool {
1592-
desc { |tcx| "checking if item has CTFE MIR available: `{}`", tcx.def_path_str(key) }
1593-
cache_on_disk_if { key.is_local() }
1594-
separate_provide_extern
1595-
}
15961591
query is_mir_available(key: DefId) -> bool {
15971592
desc { |tcx| "checking if item has MIR available: `{}`", tcx.def_path_str(key) }
15981593
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
@@ -229,7 +229,6 @@ pub fn provide(providers: &mut Providers) {
229229
optimized_mir,
230230
check_liveness: liveness::check_liveness,
231231
is_mir_available,
232-
is_ctfe_mir_available: is_mir_available,
233232
mir_callgraph_cyclic: inline::cycle::mir_callgraph_cyclic,
234233
mir_inliner_callees: inline::cycle::mir_inliner_callees,
235234
promoted_mir,

compiler/rustc_monomorphize/src/collector.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,9 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) ->
10851085
return false;
10861086
}
10871087

1088-
if !tcx.is_mir_available(def_id) {
1088+
// See comment in should_encode_mir in rustc_metadata for why we don't report
1089+
// an error for constructors.
1090+
if !tcx.is_mir_available(def_id) && !matches!(tcx.def_kind(def_id), DefKind::Ctor(..)) {
10891091
tcx.dcx().emit_fatal(NoOptimizedMir {
10901092
span: tcx.def_span(def_id),
10911093
crate_name: tcx.crate_name(def_id.krate),

0 commit comments

Comments
 (0)