From 90ac6408baa80fcd7fa28bc98af6046dba8c4bbb Mon Sep 17 00:00:00 2001 From: est31 Date: Tue, 25 Jul 2017 22:10:10 +0200 Subject: [PATCH] Switch to begin_panic again In https://github.com/rust-lang/rust/pull/42938 we made the compiler emit a call to begin_panic_new in order to pass column info to it. Now with stage0 updated (https://github.com/rust-lang/rust/pull/43320), we can safely change begin_panic and start emitting calls for it again. --- src/libstd/macros.rs | 2 +- src/libstd/panicking.rs | 19 +++++++++---------- src/libstd/rt.rs | 4 +++- src/libsyntax/ext/build.rs | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index 6ad22820a7d90..44e8a23d35348 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -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 diff --git a/src/libstd/panicking.rs b/src/libstd/panicking.rs index 494376b831ed6..04e1a579decd4 100644 --- a/src/libstd/panicking.rs +++ b/src/libstd/panicking.rs @@ -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 @@ -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")] @@ -558,7 +560,7 @@ pub fn begin_panic_new(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(msg: M, file_line: &(&'static str, u32)) -> ! { +pub fn begin_panic(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 @@ -566,10 +568,7 @@ pub fn begin_panic(msg: M, file_line: &(&'static str, u32)) -> ! // 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 diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs index 2ee63527c147c..2aa23ea043b5b 100644 --- a/src/libstd/rt.rs +++ b/src/libstd/rt.rs @@ -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"] diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 2555bf6dea7ab..d81404172148c 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -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])