Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0d508bb
Introduce and provide a hook for `should_codegen_locally`
momvart Jul 15, 2024
14430e6
Use the hook on tcx instead of the local function
momvart Jul 15, 2024
9b80250
Move compiler_builtin check to the use case
momvart Jul 15, 2024
2b5a982
abstract merge-base commit logic
onur-ozkan Jul 17, 2024
9e354da
unix: Unsafe-wrap stack_overflow::signal_handler
workingjubilee Jul 17, 2024
357ba1f
unix: lift init of sigaltstack before sigaction
workingjubilee Jul 17, 2024
fa628ce
unix: Unsafe-wrap stack_overflow::cleanup
workingjubilee Jul 17, 2024
c1740ee
unix: Unsafe-wrap stack_overflow::{drop,make}_handler
workingjubilee Jul 17, 2024
529fcbc
unix: acquire-load NEED_ALTSTACK
workingjubilee Jul 18, 2024
ead6aad
Make command output capturing more explicit
Kobzol Jul 7, 2024
1984a46
Make it easier to detect when bootstrap tries to read uncaptured stdo…
Kobzol Jul 7, 2024
36ebf7a
run_make_support: skip rustfmt for lib.rs to preserve use ordering
jieyouxu Jul 19, 2024
5b1860a
rewrite return-non-c-like-enum-from-c to rmake
Oneirical Jul 12, 2024
5e55f07
rewrite and rename issue-28595 to rmake
Oneirical Jul 12, 2024
1ae1ab8
rewrite c-static-dylib to rmake
Oneirical Jul 12, 2024
1a4fba5
rewrite c-static-rlib to rmake
Oneirical Jul 12, 2024
8a09f22
rewrite extern-fn-generic to rmake
Oneirical Jul 12, 2024
01c7118
rewrite extern-fn-with-union to rmake
Oneirical Jul 12, 2024
db8398d
rewrite lto-no-link-whole-rlib to rmake
Oneirical Jul 12, 2024
1f976b4
rewrite linkage-attr-on-static to rmake
Oneirical Jul 12, 2024
fdc8d62
rewrite pass-non-c-like-enum-to-c to rmake
Oneirical Jul 17, 2024
1d83da8
kmc-solid: forbid(unsafe_op_in_unsafe_fn)
workingjubilee Jul 17, 2024
e9b3e9c
std: forbid unwrapped unsafe in unsupported_backslash
workingjubilee Jul 17, 2024
3b7e4bc
Split out `remove_never_subcandidates`
Zalathar Jul 18, 2024
e091c35
Improve `merge_trivial_subcandidates`
Zalathar Jul 18, 2024
e60c5c1
Split out `test_remaining_match_pairs_after_or`
Zalathar Jul 18, 2024
886668c
Improve `test_remaining_match_pairs_after_or`
Zalathar Jul 18, 2024
239037e
Inline `finalize_or_candidate`
Zalathar Jul 18, 2024
0636293
use precompiled rustdoc with CI rustc
onur-ozkan Jul 7, 2024
a40b294
Rollup merge of #127463 - onur-ozkan:precompiled-rustdoc, r=Kobzol
tgross35 Jul 20, 2024
27690c5
Rollup merge of #127663 - Oneirical:fuzzy-testure, r=jieyouxu
tgross35 Jul 20, 2024
2624e4f
Rollup merge of #127779 - momvart:should_codegen_hook, r=cjgillot
tgross35 Jul 20, 2024
ba33385
Rollup merge of #127799 - Kobzol:bootstrap-cmd-refactor-7, r=onur-ozkan
tgross35 Jul 20, 2024
ff9ed81
Rollup merge of #127843 - workingjubilee:break-up-big-ass-stack-overf…
tgross35 Jul 20, 2024
fa28851
Rollup merge of #127873 - workingjubilee:forbid-unsafe-ops-for-kmc-so…
tgross35 Jul 20, 2024
0ab64f9
Rollup merge of #127917 - Zalathar:after-or, r=Nadrieril
tgross35 Jul 20, 2024
bf972c7
Rollup merge of #127964 - jieyouxu:rmake-rustfmt-skip, r=nnethercote
tgross35 Jul 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use the hook on tcx instead of the local function
  • Loading branch information
momvart committed Jul 15, 2024
commit 14430e66be02266ca59bdddd38d88a27f2e02917
40 changes: 17 additions & 23 deletions compiler/rustc_monomorphize/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ fn collect_items_rec<'tcx>(
let instance = Instance::mono(tcx, def_id);

// Sanity check whether this ended up being collected accidentally
debug_assert!(should_codegen_locally(tcx, instance));
debug_assert!(tcx.should_codegen_locally(instance));

let DefKind::Static { nested, .. } = tcx.def_kind(def_id) else { bug!() };
// Nested statics have no type.
Expand Down Expand Up @@ -432,7 +432,7 @@ fn collect_items_rec<'tcx>(
}
MonoItem::Fn(instance) => {
// Sanity check whether this ended up being collected accidentally
debug_assert!(should_codegen_locally(tcx, instance));
debug_assert!(tcx.should_codegen_locally(instance));

// Keep track of the monomorphization recursion depth
recursion_depth_reset = Some(check_recursion_limit(
Expand Down Expand Up @@ -476,7 +476,7 @@ fn collect_items_rec<'tcx>(
}
hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
let instance = Instance::mono(tcx, *def_id);
if should_codegen_locally(tcx, instance) {
if tcx.should_codegen_locally(instance) {
trace!("collecting static {:?}", def_id);
used_items.push(dummy_spanned(MonoItem::Static(*def_id)));
}
Expand Down Expand Up @@ -713,7 +713,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
if let ty::Closure(def_id, args) = *source_ty.kind() {
let instance =
Instance::resolve_closure(self.tcx, def_id, args, ty::ClosureKind::FnOnce);
if should_codegen_locally(self.tcx, instance) {
if self.tcx.should_codegen_locally(instance) {
self.used_items.push(create_fn_mono_item(self.tcx, instance, span));
}
} else {
Expand All @@ -723,7 +723,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
mir::Rvalue::ThreadLocalRef(def_id) => {
assert!(self.tcx.is_thread_local_static(def_id));
let instance = Instance::mono(self.tcx, def_id);
if should_codegen_locally(self.tcx, instance) {
if self.tcx.should_codegen_locally(instance) {
trace!("collecting thread-local static {:?}", def_id);
self.used_items.push(respan(span, MonoItem::Static(def_id)));
}
Expand All @@ -750,7 +750,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
let tcx = self.tcx;
let push_mono_lang_item = |this: &mut Self, lang_item: LangItem| {
let instance = Instance::mono(tcx, tcx.require_lang_item(lang_item, Some(source)));
if should_codegen_locally(tcx, instance) {
if tcx.should_codegen_locally(instance) {
this.used_items.push(create_fn_mono_item(tcx, instance, source));
}
};
Expand Down Expand Up @@ -784,7 +784,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> {
}
mir::InlineAsmOperand::SymStatic { def_id } => {
let instance = Instance::mono(self.tcx, def_id);
if should_codegen_locally(self.tcx, instance) {
if self.tcx.should_codegen_locally(instance) {
trace!("collecting asm sym static {:?}", def_id);
self.used_items.push(respan(source, MonoItem::Static(def_id)));
}
Expand Down Expand Up @@ -874,7 +874,7 @@ fn visit_instance_use<'tcx>(
output: &mut MonoItems<'tcx>,
) {
debug!("visit_item_use({:?}, is_direct_call={:?})", instance, is_direct_call);
if !should_codegen_locally(tcx, instance) {
if !tcx.should_codegen_locally(instance) {
return;
}
if let ty::InstanceKind::Intrinsic(def_id) = instance.def {
Expand All @@ -886,13 +886,13 @@ fn visit_instance_use<'tcx>(
// codegen a call to that function without generating code for the function itself.
let def_id = tcx.require_lang_item(LangItem::PanicNounwind, None);
let panic_instance = Instance::mono(tcx, def_id);
if should_codegen_locally(tcx, panic_instance) {
if tcx.should_codegen_locally(panic_instance) {
output.push(create_fn_mono_item(tcx, panic_instance, source));
}
} else if tcx.has_attr(def_id, sym::rustc_intrinsic) {
// Codegen the fallback body of intrinsics with fallback bodies
let instance = ty::Instance::new(def_id, instance.args);
if should_codegen_locally(tcx, instance) {
if tcx.should_codegen_locally(instance) {
output.push(create_fn_mono_item(tcx, instance, source));
}
}
Expand Down Expand Up @@ -931,7 +931,7 @@ fn visit_instance_use<'tcx>(

/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
/// can just link to the upstream crate and therefore don't need a mono item.
pub(crate) fn should_codegen_locally_hook<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -> bool {
fn should_codegen_locally<'tcx>(tcx: TyCtxtAt<'tcx>, instance: Instance<'tcx>) -> bool {
let Some(def_id) = instance.def.def_id_if_not_guaranteed_local_codegen() else {
return true;
};
Expand Down Expand Up @@ -968,12 +968,6 @@ pub(crate) fn should_codegen_locally_hook<'tcx>(tcx: TyCtxtAt<'tcx>, instance: I
true
}

/// Returns `true` if we should codegen an instance in the local crate, or returns `false` if we
/// can just link to the upstream crate and therefore don't need a mono item.
pub(crate) fn should_codegen_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool {
tcx.should_codegen_locally(instance)
}

/// For a given pair of source and target type that occur in an unsizing coercion,
/// this function finds the pair of types that determines the vtable linking
/// them.
Expand Down Expand Up @@ -1134,7 +1128,7 @@ fn create_mono_items_for_vtable_methods<'tcx>(
None
}
VtblEntry::Method(instance) => {
Some(*instance).filter(|instance| should_codegen_locally(tcx, *instance))
Some(*instance).filter(|instance| tcx.should_codegen_locally(*instance))
}
})
.map(|item| create_fn_mono_item(tcx, item, source));
Expand All @@ -1151,7 +1145,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
GlobalAlloc::Static(def_id) => {
assert!(!tcx.is_thread_local_static(def_id));
let instance = Instance::mono(tcx, def_id);
if should_codegen_locally(tcx, instance) {
if tcx.should_codegen_locally(instance) {
trace!("collecting static {:?}", def_id);
output.push(dummy_spanned(MonoItem::Static(def_id)));
}
Expand All @@ -1169,7 +1163,7 @@ fn collect_alloc<'tcx>(tcx: TyCtxt<'tcx>, alloc_id: AllocId, output: &mut MonoIt
}
}
GlobalAlloc::Function { instance, .. } => {
if should_codegen_locally(tcx, instance) {
if tcx.should_codegen_locally(instance) {
trace!("collecting {:?} with {:#?}", alloc_id, instance);
output.push(create_fn_mono_item(tcx, instance, DUMMY_SP));
}
Expand Down Expand Up @@ -1291,7 +1285,7 @@ fn visit_mentioned_item<'tcx>(
if let ty::Closure(def_id, args) = *source_ty.kind() {
let instance =
Instance::resolve_closure(tcx, def_id, args, ty::ClosureKind::FnOnce);
if should_codegen_locally(tcx, instance) {
if tcx.should_codegen_locally(instance) {
output.push(create_fn_mono_item(tcx, instance, span));
}
} else {
Expand Down Expand Up @@ -1564,7 +1558,7 @@ fn create_mono_items_for_default_impls<'tcx>(
let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args, DUMMY_SP);

let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP);
if mono_item.node.is_instantiable(tcx) && should_codegen_locally(tcx, instance) {
if mono_item.node.is_instantiable(tcx) && tcx.should_codegen_locally(instance) {
output.push(mono_item);
}
}
Expand Down Expand Up @@ -1622,5 +1616,5 @@ pub(crate) fn collect_crate_mono_items<'tcx>(
}

pub fn provide(providers: &mut Providers) {
providers.hooks.should_codegen_locally = should_codegen_locally_hook;
providers.hooks.should_codegen_locally = should_codegen_locally;
}
4 changes: 1 addition & 3 deletions compiler/rustc_monomorphize/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ mod partitioning;
mod polymorphize;
mod util;

use collector::should_codegen_locally;

rustc_fluent_macro::fluent_messages! { "../messages.ftl" }

fn custom_coerce_unsize_info<'tcx>(
Expand Down Expand Up @@ -73,7 +71,7 @@ pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
!def_id.is_local()
&& tcx.is_compiler_builtins(LOCAL_CRATE)
&& !is_llvm_intrinsic(tcx, def_id)
&& !should_codegen_locally(tcx, instance)
&& !tcx.should_codegen_locally(instance)
}

pub fn provide(providers: &mut Providers) {
Expand Down