Skip to content

Commit

Permalink
Auto merge of #43477 - est31:master, r=alexcrichton
Browse files Browse the repository at this point in the history
Switch to begin_panic again

In #42938 we made the compiler
emit a call to begin_panic_new in order to pass column info to it. Now
with stage0 updated (#43320),
we can safely change begin_panic and start emitting calls for it again.
  • Loading branch information
bors committed Jul 27, 2017
2 parents 4a42ff4 + 90ac640 commit e574ba4
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ macro_rules! panic {
panic!("explicit panic")
});
($msg:expr) => ({
$crate::rt::begin_panic_new($msg, {
$crate::rt::begin_panic($msg, {
// static requires less code at runtime, more constant data
static _FILE_LINE_COL: (&'static str, u32, u32) = (file!(), line!(), column!());
&_FILE_LINE_COL
Expand Down
19 changes: 9 additions & 10 deletions src/libstd/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments,

let mut s = String::new();
let _ = s.write_fmt(*msg);
begin_panic_new(s, file_line_col)
begin_panic(s, file_line_col)
}

// FIXME: In PR #42938, we have added the column as info passed to the panic
Expand All @@ -529,15 +529,17 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments,
// By changing the compiler source, we can only affect behaviour of higher
// stages. We need to perform the switch over two stage0 replacements, using
// a temporary function begin_panic_new while performing the switch:
// 0. Right now, we tell stage1 onward to emit a call to begin_panic_new.
// 1. In the first SNAP, stage0 calls begin_panic_new with the new ABI,
// begin_panic stops being used. Now we can change begin_panic to
// the new ABI, and start emitting calls to begin_panic in higher
// 0. Before the current switch, we told stage1 onward to emit a call
// to begin_panic_new.
// 1. Right now, stage0 calls begin_panic_new with the new ABI,
// begin_panic stops being used. We have changed begin_panic to
// the new ABI, and started to emit calls to begin_panic in higher
// stages again, this time with the new ABI.
// 2. After the second SNAP, stage0 calls begin_panic with the new ABI,
// and we can remove the temporary begin_panic_new function.

/// This is the entry point of panicking for panic!() and assert!().
#[cfg(stage0)]
#[unstable(feature = "libstd_sys_internals",
reason = "used by the panic! macro",
issue = "0")]
Expand All @@ -558,18 +560,15 @@ pub fn begin_panic_new<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32
reason = "used by the panic! macro",
issue = "0")]
#[inline(never)] #[cold] // avoid code bloat at the call sites as much as possible
pub fn begin_panic<M: Any + Send>(msg: M, file_line: &(&'static str, u32)) -> ! {
pub fn begin_panic<M: Any + Send>(msg: M, file_line_col: &(&'static str, u32, u32)) -> ! {
// 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 really ready for panic on OOM anyway. If
// we do start doing this, then we should propagate this allocation to
// be performed in the parent of this thread instead of the thread that's
// panicking.

let (file, line) = *file_line;
let file_line_col = (file, line, 0);

rust_panic_with_hook(Box::new(msg), &file_line_col)
rust_panic_with_hook(Box::new(msg), file_line_col)
}

/// Executes the primary logic for a panic, including checking for recursive
Expand Down
4 changes: 3 additions & 1 deletion src/libstd/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@


// Reexport some of our utilities which are expected by other crates.
pub use panicking::{begin_panic_new, begin_panic, begin_panic_fmt, update_panic_count};
#[cfg(stage0)]
pub use panicking::begin_panic_new;
pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count};

#[cfg(not(test))]
#[lang = "start"]
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -774,7 +774,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
let expr_loc_ptr = self.expr_addr_of(span, expr_loc_tuple);
self.expr_call_global(
span,
self.std_path(&["rt", "begin_panic_new"]),
self.std_path(&["rt", "begin_panic"]),
vec![
self.expr_str(span, msg),
expr_loc_ptr])
Expand Down

0 comments on commit e574ba4

Please sign in to comment.