Skip to content

Commit 99abe39

Browse files
committed
Querify should_codegen_locally
1 parent 1e0df74 commit 99abe39

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
@@ -1635,6 +1635,11 @@ rustc_queries! {
16351635
separate_provide_extern
16361636
}
16371637

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

compiler/rustc_monomorphize/src/collector.rs

+24-20
Original file line numberDiff line numberDiff line change
@@ -955,26 +955,7 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -
955955
return true;
956956
}
957957

958-
if tcx.is_reachable_non_generic(def_id)
959-
|| instance.polymorphize(*tcx).upstream_monomorphization(*tcx).is_some()
960-
{
961-
// We can link to the item in question, no instance needed in this crate.
962-
return false;
963-
}
964-
965-
if let DefKind::Static { .. } = tcx.def_kind(def_id) {
966-
// We cannot monomorphize statics from upstream crates.
967-
return false;
968-
}
969-
970-
if !tcx.is_mir_available(def_id) {
971-
tcx.dcx().emit_fatal(NoOptimizedMir {
972-
span: tcx.def_span(def_id),
973-
crate_name: tcx.crate_name(def_id.krate),
974-
});
975-
}
976-
977-
true
958+
tcx.should_codegen_locally_slow(instance)
978959
}
979960

980961
/// For a given pair of source and target type that occur in an unsizing coercion,
@@ -1630,4 +1611,27 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
16301611
pub(crate) fn provide(providers: &mut Providers) {
16311612
providers.hooks.should_codegen_locally = should_codegen_locally;
16321613
providers.items_of_instance = items_of_instance;
1614+
providers.should_codegen_locally_slow = |tcx, instance| {
1615+
let def_id = instance.def_id();
1616+
if let DefKind::Static { .. } = tcx.def_kind(def_id) {
1617+
// We cannot monomorphize statics from upstream crates.
1618+
return false;
1619+
}
1620+
1621+
if tcx.is_reachable_non_generic(def_id)
1622+
|| instance.polymorphize(tcx).upstream_monomorphization(tcx).is_some()
1623+
{
1624+
// We can link to the item in question, no instance needed in this crate.
1625+
return false;
1626+
}
1627+
1628+
if !tcx.is_mir_available(def_id) {
1629+
tcx.dcx().emit_fatal(NoOptimizedMir {
1630+
span: tcx.def_span(def_id),
1631+
crate_name: tcx.crate_name(def_id.krate),
1632+
});
1633+
}
1634+
1635+
true
1636+
};
16331637
}

0 commit comments

Comments
 (0)