Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6d11a59

Browse files
committedDec 8, 2024
Auto merge of rust-lang#133016 - saethlin:querify-should-codegen-locally, r=<try>
Querify should_codegen_locally I think this has a very strong interaction with rust-lang#132566, and may not be justifiable without that PR, so marking this as blocked until that is merged.
2 parents f415c07 + 60962ec commit 6d11a59

File tree

2 files changed

+28
-18
lines changed

2 files changed

+28
-18
lines changed
 

‎compiler/rustc_middle/src/query/mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,11 @@ rustc_queries! {
16621662
separate_provide_extern
16631663
}
16641664

1665+
query should_codegen_locally_slow(key: ty::Instance<'tcx>) -> bool {
1666+
desc { "checking whether `{}` should be linked to or lowered", key }
1667+
cache_on_disk_if { true }
1668+
}
1669+
16651670
/// Returns the upstream crate that exports drop-glue for the given
16661671
/// type (`args` is expected to be a single-item list containing the
16671672
/// type one wants drop-glue for).

‎compiler/rustc_monomorphize/src/collector.rs

+23-18
Original file line numberDiff line numberDiff line change
@@ -965,24 +965,7 @@ fn should_codegen_locally<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -
965965
return true;
966966
}
967967

968-
if tcx.is_reachable_non_generic(def_id) || instance.upstream_monomorphization(*tcx).is_some() {
969-
// We can link to the item in question, no instance needed in this crate.
970-
return false;
971-
}
972-
973-
if let DefKind::Static { .. } = tcx.def_kind(def_id) {
974-
// We cannot monomorphize statics from upstream crates.
975-
return false;
976-
}
977-
978-
if !tcx.is_mir_available(def_id) {
979-
tcx.dcx().emit_fatal(NoOptimizedMir {
980-
span: tcx.def_span(def_id),
981-
crate_name: tcx.crate_name(def_id.krate),
982-
});
983-
}
984-
985-
true
968+
tcx.should_codegen_locally_slow(instance)
986969
}
987970

988971
/// For a given pair of source and target type that occur in an unsizing coercion,
@@ -1643,4 +1626,26 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
16431626
pub(crate) fn provide(providers: &mut Providers) {
16441627
providers.hooks.should_codegen_locally = should_codegen_locally;
16451628
providers.items_of_instance = items_of_instance;
1629+
providers.should_codegen_locally_slow = |tcx, instance| {
1630+
let def_id = instance.def_id();
1631+
if let DefKind::Static { .. } = tcx.def_kind(def_id) {
1632+
// We cannot monomorphize statics from upstream crates.
1633+
return false;
1634+
}
1635+
1636+
if tcx.is_reachable_non_generic(def_id) || instance.upstream_monomorphization(tcx).is_some()
1637+
{
1638+
// We can link to the item in question, no instance needed in this crate.
1639+
return false;
1640+
}
1641+
1642+
if !tcx.is_mir_available(def_id) {
1643+
tcx.dcx().emit_fatal(NoOptimizedMir {
1644+
span: tcx.def_span(def_id),
1645+
crate_name: tcx.crate_name(def_id.krate),
1646+
});
1647+
}
1648+
1649+
true
1650+
};
16461651
}

0 commit comments

Comments
 (0)
Failed to load comments.