Skip to content

Commit 90bfcf5

Browse files
committed
Bit of cleanup
1 parent 92bd47c commit 90bfcf5

10 files changed

Lines changed: 15 additions & 17 deletions

File tree

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ fn process_builtin_attrs(
298298
codegen_fn_attrs.patchable_function_entry =
299299
Some(PatchableFunctionEntry::from_prefix_and_entry(*prefix, *entry));
300300
}
301+
AttributeKind::RustcPanicEntrypoint => {
302+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::PANIC_ENTRYPOINT
303+
}
301304
_ => {}
302305
}
303306
}
@@ -392,7 +395,7 @@ fn apply_overrides(tcx: TyCtxt<'_>, did: LocalDefId, codegen_fn_attrs: &mut Code
392395
}
393396
}
394397

395-
if tcx.is_panic_entrypoint(did) {
398+
if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::PANIC_ENTRYPOINT) {
396399
// Panic entrypoints are always cold.
397400
//
398401
// If we have immediate-abort enabled, we want panic entrypoints to be inlined. We have a

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'tcx> {
177177
if let Some(instance) = instance
178178
&& is_call_from_compiler_builtins_to_upstream_monomorphization(tcx, instance)
179179
{
180-
if tcx.is_panic_entrypoint(instance.def_id()) {
180+
if instance.def.is_panic_entrypoint(tcx) {
181181
info!(
182182
"compiler_builtins call to panic entrypoint {:?} replaced with abort",
183183
instance.def_id()

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ impl AttributeKind {
154154
RustcObjectLifetimeDefault => No,
155155
RustcOffloadKernel => Yes,
156156
RustcOutlives => No,
157-
RustcPanicEntrypoint => Yes,
157+
RustcPanicEntrypoint => No,
158158
RustcParenSugar(..) => No,
159159
RustcPassByValue(..) => Yes,
160160
RustcPassIndirectlyInNonRusticAbis(..) => No,

compiler/rustc_middle/src/middle/codegen_fn_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ bitflags::bitflags! {
210210
/// As such, we must make sure these symbols really do exist in the final binary/library.
211211
/// This flag is put on both the implementations of EIIs and the foreign item they implement.
212212
const EXTERNALLY_IMPLEMENTABLE_ITEM = 1 << 18;
213+
const PANIC_ENTRYPOINT = 1 << 19;
213214
}
214215
}
215216
rustc_data_structures::external_bitflags_debug! { CodegenFnAttrFlags }

compiler/rustc_middle/src/ty/context.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2791,10 +2791,6 @@ impl<'tcx> TyCtxt<'tcx> {
27912791
}
27922792
false
27932793
}
2794-
2795-
pub fn is_panic_entrypoint(self, def_id: impl Into<DefId>) -> bool {
2796-
find_attr!(self.get_all_attrs(def_id), AttributeKind::RustcPanicEntrypoint)
2797-
}
27982794
}
27992795

28002796
pub fn provide(providers: &mut Providers) {

compiler/rustc_middle/src/ty/instance.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ impl<'tcx> InstanceKind<'tcx> {
353353
| InstanceKind::VTableShim(..) => true,
354354
}
355355
}
356+
357+
pub fn is_panic_entrypoint(&self, tcx: TyCtxt<'_>) -> bool {
358+
tcx.codegen_instance_attrs(*self).flags.contains(CodegenFnAttrFlags::PANIC_ENTRYPOINT)
359+
}
356360
}
357361

358362
fn type_length<'tcx>(item: impl TypeVisitable<TyCtxt<'tcx>>) -> usize {

compiler/rustc_mir_transform/src/panic_entrypoints.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_hir::LangItem;
22
use rustc_middle::mir::{Const, ConstValue, UnwindAction, *};
3-
use rustc_middle::ty::{self, Ty, TyCtxt};
3+
use rustc_middle::ty::{self, InstanceKind, Ty, TyCtxt};
44
use rustc_span::Span;
55
use rustc_target::spec::PanicStrategy;
66
use tracing::{debug, instrument};
@@ -14,7 +14,7 @@ impl<'tcx> crate::MirPass<'tcx> for PanicEntrypoints {
1414

1515
#[instrument(level = "trace", skip(self, tcx, body))]
1616
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
17-
if tcx.is_panic_entrypoint(body.source.def_id()) {
17+
if body.source.instance.is_panic_entrypoint(tcx) {
1818
debug!("Replacing body of {:?}", body.source);
1919
let blocks = body.basic_blocks.as_mut();
2020
blocks.raw.clear();
@@ -27,13 +27,10 @@ impl<'tcx> crate::MirPass<'tcx> for PanicEntrypoints {
2727
let TerminatorKind::Call { func, .. } = &mut terminator.kind else {
2828
continue;
2929
};
30-
let Operand::Constant(box ConstOperand { const_, .. }) = &func else {
30+
let Some((def_id, _args)) = func.const_fn_def() else {
3131
continue;
3232
};
33-
let ty::FnDef(def_id, _) = *const_.ty().kind() else {
34-
continue;
35-
};
36-
if tcx.is_panic_entrypoint(def_id) {
33+
if InstanceKind::Item(def_id).is_panic_entrypoint(tcx) {
3734
debug!("Remapping call from {:?} to {:?}", body.source, def_id);
3835
*terminator = abort_terminator(tcx, terminator.source_info.span);
3936
}

library/alloc/src/vec/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2130,7 +2130,6 @@ impl<T, A: Allocator> Vec<T, A> {
21302130
#[inline]
21312131
#[stable(feature = "rust1", since = "1.0.0")]
21322132
pub fn swap_remove(&mut self, index: usize) -> T {
2133-
#[track_caller]
21342133
#[rustc_panic_entrypoint]
21352134
fn assert_failed(index: usize, len: usize) -> ! {
21362135
panic!("swap_remove index (is {index}) should be < len (is {len})");

library/core/src/slice/sort/shared/smallsort.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,6 @@ unsafe fn bidirectional_merge<T: FreezeMarker, F: FnMut(&T, &T) -> bool>(
840840
}
841841
}
842842

843-
#[track_caller]
844843
#[rustc_panic_entrypoint]
845844
fn panic_on_ord_violation() -> ! {
846845
// This is indicative of a logic bug in the user-provided comparison function or Ord

library/core/src/wtf8.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ unsafe fn slice_unchecked(s: &Wtf8, begin: usize, end: usize) -> &Wtf8 {
485485
}
486486

487487
/// Copied from core::str::raw::slice_error_fail
488-
#[track_caller]
489488
#[rustc_panic_entrypoint]
490489
fn slice_error_fail(s: &Wtf8, begin: usize, end: usize) -> ! {
491490
assert!(begin <= end);

0 commit comments

Comments
 (0)