Skip to content

Commit 0844b06

Browse files
committed
Querify should_codegen_locally
1 parent a00df61 commit 0844b06

File tree

2 files changed

+29
-20
lines changed

2 files changed

+29
-20
lines changed

compiler/rustc_middle/src/query/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,11 @@ rustc_queries! {
16341634
separate_provide_extern
16351635
}
16361636

1637+
query should_codegen_locally_slow(key: ty::Instance<'tcx>) -> bool {
1638+
desc { "checking whether `{}` should be linked to or lowered", key }
1639+
cache_on_disk_if { true }
1640+
}
1641+
16371642
/// Returns the upstream crate that exports drop-glue for the given
16381643
/// type (`args` is expected to be a single-item list containing the
16391644
/// type one wants drop-glue for).

compiler/rustc_monomorphize/src/collector.rs

+24-20
Original file line numberDiff line numberDiff line change
@@ -936,26 +936,7 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -
936936
return true;
937937
}
938938

939-
if tcx.is_reachable_non_generic(def_id)
940-
|| instance.polymorphize(*tcx).upstream_monomorphization(*tcx).is_some()
941-
{
942-
// We can link to the item in question, no instance needed in this crate.
943-
return false;
944-
}
945-
946-
if let DefKind::Static { .. } = tcx.def_kind(def_id) {
947-
// We cannot monomorphize statics from upstream crates.
948-
return false;
949-
}
950-
951-
if !tcx.is_mir_available(def_id) {
952-
tcx.dcx().emit_fatal(NoOptimizedMir {
953-
span: tcx.def_span(def_id),
954-
crate_name: tcx.crate_name(def_id.krate),
955-
});
956-
}
957-
958-
true
939+
tcx.should_codegen_locally_slow(instance)
959940
}
960941

961942
/// For a given pair of source and target type that occur in an unsizing coercion,
@@ -1596,4 +1577,27 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
15961577

15971578
pub(crate) fn provide(providers: &mut Providers) {
15981579
providers.hooks.should_codegen_locally = should_codegen_locally;
1580+
providers.should_codegen_locally_slow = |tcx, instance| {
1581+
let def_id = instance.def_id();
1582+
if let DefKind::Static { .. } = tcx.def_kind(def_id) {
1583+
// We cannot monomorphize statics from upstream crates.
1584+
return false;
1585+
}
1586+
1587+
if tcx.is_reachable_non_generic(def_id)
1588+
|| instance.polymorphize(tcx).upstream_monomorphization(tcx).is_some()
1589+
{
1590+
// We can link to the item in question, no instance needed in this crate.
1591+
return false;
1592+
}
1593+
1594+
if !tcx.is_mir_available(def_id) {
1595+
tcx.dcx().emit_fatal(NoOptimizedMir {
1596+
span: tcx.def_span(def_id),
1597+
crate_name: tcx.crate_name(def_id.krate),
1598+
});
1599+
}
1600+
1601+
true
1602+
};
15991603
}

0 commit comments

Comments
 (0)