Skip to content

Commit

Permalink
Unrolled build for rust-lang#116008
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#116008 - m-ou-se:boxmeup, r=oli-obk

Rename BoxMeUp to PanicPayload.

"BoxMeUp" is not very clear. Let's rename that to a description of what it actually represents: a panic payload.

This PR also renames the structs that implement this trait to have more descriptive names.

Part of rust-lang#116005

r? `@oli-obk`
  • Loading branch information
rust-timer authored Sep 21, 2023
2 parents 3223b0b + 76d9b36 commit 28cb203
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions library/core/src/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ pub macro unreachable_2021 {
/// use.
#[unstable(feature = "std_internals", issue = "none")]
#[doc(hidden)]
pub unsafe trait BoxMeUp {
pub unsafe trait PanicPayload {
/// Take full ownership of the contents.
/// The return type is actually `Box<dyn Any + Send>`, but we cannot use `Box` in core.
///
/// After this method got called, only some dummy default value is left in `self`.
/// Calling this method twice, or calling `get` after calling this method, is an error.
///
/// The argument is borrowed because the panic runtime (`__rust_start_panic`) only
/// gets a borrowed `dyn BoxMeUp`.
/// gets a borrowed `dyn PanicPayload`.
fn take_box(&mut self) -> *mut (dyn Any + Send);

/// Just borrow the contents.
Expand Down
4 changes: 2 additions & 2 deletions library/panic_abort/src/android.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use alloc::string::String;
use core::mem::transmute;
use core::panic::BoxMeUp;
use core::panic::PanicPayload;
use core::ptr::copy_nonoverlapping;

const ANDROID_SET_ABORT_MESSAGE: &[u8] = b"android_set_abort_message\0";
Expand All @@ -15,7 +15,7 @@ type SetAbortMessageType = unsafe extern "C" fn(*const libc::c_char) -> ();
//
// Weakly resolve the symbol for android_set_abort_message. This function is only available
// for API >= 21.
pub(crate) unsafe fn android_set_abort_message(payload: &mut dyn BoxMeUp) {
pub(crate) unsafe fn android_set_abort_message(payload: &mut dyn PanicPayload) {
let func_addr =
libc::dlsym(libc::RTLD_DEFAULT, ANDROID_SET_ABORT_MESSAGE.as_ptr() as *const libc::c_char)
as usize;
Expand Down
4 changes: 2 additions & 2 deletions library/panic_abort/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
mod android;

use core::any::Any;
use core::panic::BoxMeUp;
use core::panic::PanicPayload;

#[rustc_std_internal_symbol]
#[allow(improper_ctypes_definitions)]
Expand All @@ -30,7 +30,7 @@ pub unsafe extern "C" fn __rust_panic_cleanup(_: *mut u8) -> *mut (dyn Any + Sen

// "Leak" the payload and shim to the relevant abort on the platform in question.
#[rustc_std_internal_symbol]
pub unsafe fn __rust_start_panic(_payload: &mut dyn BoxMeUp) -> u32 {
pub unsafe fn __rust_start_panic(_payload: &mut dyn PanicPayload) -> u32 {
// Android has the ability to attach a message as part of the abort.
#[cfg(target_os = "android")]
android::android_set_abort_message(_payload);
Expand Down
4 changes: 2 additions & 2 deletions library/panic_unwind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

use alloc::boxed::Box;
use core::any::Any;
use core::panic::BoxMeUp;
use core::panic::PanicPayload;

cfg_if::cfg_if! {
if #[cfg(target_os = "emscripten")] {
Expand Down Expand Up @@ -99,7 +99,7 @@ pub unsafe extern "C" fn __rust_panic_cleanup(payload: *mut u8) -> *mut (dyn Any
// Entry point for raising an exception, just delegates to the platform-specific
// implementation.
#[rustc_std_internal_symbol]
pub unsafe fn __rust_start_panic(payload: &mut dyn BoxMeUp) -> u32 {
pub unsafe fn __rust_start_panic(payload: &mut dyn PanicPayload) -> u32 {
let payload = Box::from_raw(payload.take_box());

imp::panic(payload)
Expand Down
42 changes: 21 additions & 21 deletions library/std/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#![deny(unsafe_op_in_unsafe_fn)]

use crate::panic::BacktraceStyle;
use core::panic::{BoxMeUp, Location, PanicInfo};
use core::panic::{Location, PanicInfo, PanicPayload};

use crate::any::Any;
use crate::fmt;
Expand Down Expand Up @@ -47,9 +47,9 @@ extern "C" {
}

extern "Rust" {
/// `BoxMeUp` lazily performs allocation only when needed (this avoids
/// `PanicPayload` lazily performs allocation only when needed (this avoids
/// allocations when using the "abort" panic runtime).
fn __rust_start_panic(payload: &mut dyn BoxMeUp) -> u32;
fn __rust_start_panic(payload: &mut dyn PanicPayload) -> u32;
}

/// This function is called by the panic runtime if FFI code catches a Rust
Expand Down Expand Up @@ -543,14 +543,14 @@ pub fn panicking() -> bool {
#[cfg(not(test))]
#[panic_handler]
pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
struct PanicPayload<'a> {
struct FormatStringPayload<'a> {
inner: &'a fmt::Arguments<'a>,
string: Option<String>,
}

impl<'a> PanicPayload<'a> {
fn new(inner: &'a fmt::Arguments<'a>) -> PanicPayload<'a> {
PanicPayload { inner, string: None }
impl<'a> FormatStringPayload<'a> {
fn new(inner: &'a fmt::Arguments<'a>) -> Self {
Self { inner, string: None }
}

fn fill(&mut self) -> &mut String {
Expand All @@ -566,7 +566,7 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
}
}

unsafe impl<'a> BoxMeUp for PanicPayload<'a> {
unsafe impl<'a> PanicPayload for FormatStringPayload<'a> {
fn take_box(&mut self) -> *mut (dyn Any + Send) {
// We do two allocations here, unfortunately. But (a) they're required with the current
// scheme, and (b) we don't handle panic + OOM properly anyway (see comment in
Expand All @@ -580,9 +580,9 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
}
}

struct StrPanicPayload(&'static str);
struct StaticStrPayload(&'static str);

unsafe impl BoxMeUp for StrPanicPayload {
unsafe impl PanicPayload for StaticStrPayload {
fn take_box(&mut self) -> *mut (dyn Any + Send) {
Box::into_raw(Box::new(self.0))
}
Expand All @@ -599,15 +599,15 @@ pub fn begin_panic_handler(info: &PanicInfo<'_>) -> ! {
// `rust_panic_with_hook` construct a new `PanicInfo`?
if let Some(msg) = msg.as_str() {
rust_panic_with_hook(
&mut StrPanicPayload(msg),
&mut StaticStrPayload(msg),
info.message(),
loc,
info.can_unwind(),
info.force_no_backtrace(),
);
} else {
rust_panic_with_hook(
&mut PanicPayload::new(msg),
&mut FormatStringPayload::new(msg),
info.message(),
loc,
info.can_unwind(),
Expand Down Expand Up @@ -637,25 +637,25 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
let loc = Location::caller();
return crate::sys_common::backtrace::__rust_end_short_backtrace(move || {
rust_panic_with_hook(
&mut PanicPayload::new(msg),
&mut Payload::new(msg),
None,
loc,
/* can_unwind */ true,
/* force_no_backtrace */ false,
)
});

struct PanicPayload<A> {
struct Payload<A> {
inner: Option<A>,
}

impl<A: Send + 'static> PanicPayload<A> {
fn new(inner: A) -> PanicPayload<A> {
PanicPayload { inner: Some(inner) }
impl<A: Send + 'static> Payload<A> {
fn new(inner: A) -> Payload<A> {
Payload { inner: Some(inner) }
}
}

unsafe impl<A: Send + 'static> BoxMeUp for PanicPayload<A> {
unsafe impl<A: Send + 'static> PanicPayload for Payload<A> {
fn take_box(&mut self) -> *mut (dyn Any + Send) {
// Note that this should be the only allocation performed in this code path. Currently
// this means that panic!() on OOM will invoke this code path, but then again we're not
Expand Down Expand Up @@ -684,7 +684,7 @@ pub const fn begin_panic<M: Any + Send>(msg: M) -> ! {
/// panics, panic hooks, and finally dispatching to the panic runtime to either
/// abort or unwind.
fn rust_panic_with_hook(
payload: &mut dyn BoxMeUp,
payload: &mut dyn PanicPayload,
message: Option<&fmt::Arguments<'_>>,
location: &Location<'_>,
can_unwind: bool,
Expand Down Expand Up @@ -760,7 +760,7 @@ pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {

struct RewrapBox(Box<dyn Any + Send>);

unsafe impl BoxMeUp for RewrapBox {
unsafe impl PanicPayload for RewrapBox {
fn take_box(&mut self) -> *mut (dyn Any + Send) {
Box::into_raw(mem::replace(&mut self.0, Box::new(())))
}
Expand All @@ -777,7 +777,7 @@ pub fn rust_panic_without_hook(payload: Box<dyn Any + Send>) -> ! {
/// yer breakpoints.
#[inline(never)]
#[cfg_attr(not(test), rustc_std_internal_symbol)]
fn rust_panic(msg: &mut dyn BoxMeUp) -> ! {
fn rust_panic(msg: &mut dyn PanicPayload) -> ! {
let code = unsafe { __rust_start_panic(msg) };
rtabort!("failed to initiate panic, error {code}")
}

0 comments on commit 28cb203

Please sign in to comment.