Skip to content

Commit f7ab07c

Browse files
committed
Put the struct passed to unwinding functions into a static
Produces very clean asm, but makes bigger binaries.
1 parent 4636b32 commit f7ab07c

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/libcore/macros.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ macro_rules! fail(
3333
// up with the number of calls to fail!()
3434
#[inline(always)]
3535
fn run_fmt(fmt: &::std::fmt::Arguments) -> ! {
36-
::core::failure::begin_unwind(fmt, &(file!(), line!()))
36+
static file_line: (&'static str, uint) = (file!(), line!());
37+
::core::failure::begin_unwind(fmt, &file_line)
3738
}
3839
format_args!(run_fmt, $fmt, $($arg)*)
3940
});

src/libstd/macros.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,16 @@
3838
/// ```
3939
#[macro_export]
4040
macro_rules! fail(
41-
() => (
42-
::std::rt::begin_unwind_no_time_to_explain(&(file!(), line!()))
43-
);
44-
($msg:expr) => (
45-
::std::rt::begin_unwind($msg, file!(), line!())
46-
);
41+
() => ({
42+
// static requires less code at runtime, more constant data
43+
static file_line: (&'static str, uint) = (file!(), line!());
44+
::std::rt::begin_unwind_no_time_to_explain(&file_line)
45+
});
46+
($msg:expr) => ({
47+
static file_line: (&'static str, uint) = (file!(), line!());
48+
let (file, line) = file_line;
49+
::std::rt::begin_unwind($msg, file, line)
50+
});
4751
($fmt:expr, $($arg:tt)*) => ({
4852
// a closure can't have return type !, so we need a full
4953
// function to pass to format_args!, *and* we need the
@@ -58,7 +62,8 @@ macro_rules! fail(
5862
// up with the number of calls to fail!()
5963
#[inline(always)]
6064
fn run_fmt(fmt: &::std::fmt::Arguments) -> ! {
61-
::std::rt::begin_unwind_fmt(fmt, &(file!(), line!()))
65+
static file_line: (&'static str, uint) = (file!(), line!());
66+
::std::rt::begin_unwind_fmt(fmt, &file_line)
6267
}
6368
format_args!(run_fmt, $fmt, $($arg)*)
6469
});

0 commit comments

Comments
 (0)