Skip to content

Commit

Permalink
Put the struct passed to unwinding functions into a static
Browse files Browse the repository at this point in the history
Produces very clean asm, but makes bigger binaries.
  • Loading branch information
brson committed Jul 25, 2014
1 parent 4636b32 commit f7ab07c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
3 changes: 2 additions & 1 deletion src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ macro_rules! fail(
// up with the number of calls to fail!()
#[inline(always)]
fn run_fmt(fmt: &::std::fmt::Arguments) -> ! {
::core::failure::begin_unwind(fmt, &(file!(), line!()))
static file_line: (&'static str, uint) = (file!(), line!());
::core::failure::begin_unwind(fmt, &file_line)
}
format_args!(run_fmt, $fmt, $($arg)*)
});
Expand Down
19 changes: 12 additions & 7 deletions src/libstd/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,16 @@
/// ```
#[macro_export]
macro_rules! fail(
() => (
::std::rt::begin_unwind_no_time_to_explain(&(file!(), line!()))
);
($msg:expr) => (
::std::rt::begin_unwind($msg, file!(), line!())
);
() => ({
// static requires less code at runtime, more constant data
static file_line: (&'static str, uint) = (file!(), line!());
::std::rt::begin_unwind_no_time_to_explain(&file_line)
});
($msg:expr) => ({
static file_line: (&'static str, uint) = (file!(), line!());
let (file, line) = file_line;
::std::rt::begin_unwind($msg, file, line)
});
($fmt:expr, $($arg:tt)*) => ({
// a closure can't have return type !, so we need a full
// function to pass to format_args!, *and* we need the
Expand All @@ -58,7 +62,8 @@ macro_rules! fail(
// up with the number of calls to fail!()
#[inline(always)]
fn run_fmt(fmt: &::std::fmt::Arguments) -> ! {
::std::rt::begin_unwind_fmt(fmt, &(file!(), line!()))
static file_line: (&'static str, uint) = (file!(), line!());
::std::rt::begin_unwind_fmt(fmt, &file_line)
}
format_args!(run_fmt, $fmt, $($arg)*)
});
Expand Down

0 comments on commit f7ab07c

Please sign in to comment.