Skip to content

Commit eb5fb21

Browse files
committed
Fix the test failure, add comment, and refactor a little bit
1 parent da88707 commit eb5fb21

File tree

5 files changed

+39
-104
lines changed

5 files changed

+39
-104
lines changed

src/libcore/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,6 @@ pub mod array;
160160
pub mod sync;
161161
pub mod cell;
162162
pub mod char;
163-
// FIXME: remove when SNAP
164-
#[cfg(stage0)]
165-
#[path = "panicking_stage0.rs"]
166-
pub mod panicking;
167-
#[cfg(not(stage0))]
168163
pub mod panicking;
169164
pub mod iter;
170165
pub mod option;

src/libcore/macros.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ macro_rules! panic {
1919
($msg:expr) => ({
2020
static _MSG_FILE_LINE_COL: (&'static str, &'static str, u32, u32) =
2121
($msg, file!(), line!(), column!());
22-
$crate::panicking::panic_new(&_MSG_FILE_LINE_COL)
22+
$crate::panicking::panic(&_MSG_FILE_LINE_COL)
2323
});
2424
($fmt:expr, $($arg:tt)*) => ({
2525
// The leading _'s are to avoid dead code warnings if this is
@@ -28,7 +28,7 @@ macro_rules! panic {
2828
// `#[forbid(dead_code)]` and which cannot be overridden.
2929
static _MSG_FILE_LINE_COL: (&'static str, u32, u32) =
3030
(file!(), line!(), column!());
31-
$crate::panicking::panic_fmt_new(format_args!($fmt, $($arg)*), &_MSG_FILE_LINE_COL)
31+
$crate::panicking::panic_fmt(format_args!($fmt, $($arg)*), &_MSG_FILE_LINE_COL)
3232
});
3333
}
3434

src/libcore/panicking.rs

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,8 @@
3838

3939
use fmt;
4040

41-
#[cold] #[inline(never)]
42-
pub fn panic_new(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
43-
panic(&expr_file_line_col)
44-
}
45-
4641
#[cold] #[inline(never)] // this is the slow path, always
47-
#[lang = "panic"]
42+
#[cfg_attr(not(stage0), lang = "panic")]
4843
pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
4944
// Use Arguments::new_v1 instead of format_args!("{}", expr) to potentially
5045
// reduce size overhead. The format_args! macro uses str's Display trait to
@@ -56,17 +51,33 @@ pub fn panic(expr_file_line_col: &(&'static str, &'static str, u32, u32)) -> ! {
5651
panic_fmt(fmt::Arguments::new_v1(&[expr], &[]), &(file, line, col))
5752
}
5853

54+
// FIXME: remove when SNAP
5955
#[cold] #[inline(never)]
60-
#[lang = "panic_bounds_check"]
56+
#[cfg(stage0)]
57+
#[lang = "panic"]
58+
pub fn panic_old(expr_file_line: &(&'static str, &'static str, u32)) -> ! {
59+
let (expr, file, line) = *expr_file_line;
60+
let expr_file_line_col = (expr, file, line, 0);
61+
panic(&expr_file_line_col)
62+
}
63+
64+
#[cold] #[inline(never)]
65+
#[cfg_attr(not(stage0), lang = "panic_bounds_check")]
6166
fn panic_bounds_check(file_line_col: &(&'static str, u32, u32),
6267
index: usize, len: usize) -> ! {
6368
panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
6469
len, index), file_line_col)
6570
}
6671

72+
// FIXME: remove when SNAP
6773
#[cold] #[inline(never)]
68-
pub fn panic_fmt_new(fmt: fmt::Arguments, file_line_col: &(&'static str, u32, u32)) -> ! {
69-
panic_fmt(fmt, &file_line_col)
74+
#[cfg(stage0)]
75+
#[lang = "panic_bounds_check"]
76+
fn panic_bounds_check_old(file_line: &(&'static str, u32),
77+
index: usize, len: usize) -> ! {
78+
let (file, line) = *file_line;
79+
panic_fmt(format_args!("index out of bounds: the len is {} but the index is {}",
80+
len, index), &(file, line, 0))
7081
}
7182

7283
#[cold] #[inline(never)]

src/libcore/panicking_stage0.rs

Lines changed: 0 additions & 86 deletions
This file was deleted.

src/libstd/panicking.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ impl<'a> Location<'a> {
315315
/// # Examples
316316
///
317317
/// ```should_panic
318+
/// #![feature(panic_col)]
318319
/// use std::panic;
319320
///
320321
/// panic::set_hook(Box::new(|panic_info| {
@@ -327,7 +328,7 @@ impl<'a> Location<'a> {
327328
///
328329
/// panic!("Normal panic");
329330
/// ```
330-
#[unstable(feature = "panic_col", issue = "42939")]
331+
#[unstable(feature = "panic_col", reason = "recently added", issue = "42939")]
331332
pub fn column(&self) -> u32 {
332333
self.col
333334
}
@@ -520,7 +521,21 @@ pub fn begin_panic_fmt(msg: &fmt::Arguments,
520521
begin_panic_new(s, file_line_col)
521522
}
522523

523-
// FIXME: remove begin_panic and rename begin_panic_new to begin_panic when SNAP
524+
// FIXME: In PR #42938, we have added the column as info passed to the panic
525+
// handling code. For this, we want to break the ABI of begin_panic.
526+
// This is not possible to do directly, as the stage0 compiler is hardcoded
527+
// to emit a call to begin_panic in src/libsyntax/ext/build.rs, only
528+
// with the file and line number being passed, but not the colum number.
529+
// By changing the compiler source, we can only affect behaviour of higher
530+
// stages. We need to perform the switch over two stage0 replacements, using
531+
// a temporary function begin_panic_new while performing the switch:
532+
// 0. Right now, we tell stage1 onward to emit a call to begin_panic_new.
533+
// 1. In the first SNAP, stage0 calls begin_panic_new with the new ABI,
534+
// begin_panic stops being used. Now we can change begin_panic to
535+
// the new ABI, and start emitting calls to begin_panic in higher
536+
// stages again, this time with the new ABI.
537+
// 2. After the second SNAP, stage0 calls begin_panic with the new ABI,
538+
// and we can remove the temporary begin_panic_new function.
524539

525540
/// This is the entry point of panicking for panic!() and assert!().
526541
#[unstable(feature = "libstd_sys_internals",

0 commit comments

Comments
 (0)