diff options
| author | Brian Anderson <banderson@mozilla.com> | 2014-07-28 21:26:21 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-07-31 07:30:17 -0700 |
| commit | 134946d06e6926e087a792ac13c7f4421591afed (patch) | |
| tree | f167e44b94f54bfb2f405d8a59a77352c9a894c6 /src/libstd/macros.rs | |
| parent | 571f6cf29ae181098e3aff43a5f8e345be6708e9 (diff) | |
| download | rust-134946d06e6926e087a792ac13c7f4421591afed.tar.gz rust-134946d06e6926e087a792ac13c7f4421591afed.zip | |
rustrt: Make begin_unwind take a single file/line pointer
Smaller text size.
Diffstat (limited to 'src/libstd/macros.rs')
| -rw-r--r-- | src/libstd/macros.rs | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs index f0732c7d508..e67329df7ae 100644 --- a/src/libstd/macros.rs +++ b/src/libstd/macros.rs @@ -37,6 +37,39 @@ /// fail!("this is a {} {message}", "fancy", message = "message"); /// ``` #[macro_export] +#[cfg(not(stage0))] +macro_rules! fail( + () => ({ + fail!("explicit failure") + }); + ($msg:expr) => ({ + // static requires less code at runtime, more constant data + static FILE_LINE: (&'static str, uint) = (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 + // file and line numbers right here; so an inner bare fn + // is our only choice. + // + // LLVM doesn't tend to inline this, presumably because begin_unwind_fmt + // is #[cold] and #[inline(never)] and because this is flagged as cold + // as returning !. We really do want this to be inlined, however, + // because it's just a tiny wrapper. Small wins (156K to 149K in size) + // were seen when forcing this to be inlined, and that number just goes + // up with the number of calls to fail!() + #[inline(always)] + fn run_fmt(fmt: &::std::fmt::Arguments) -> ! { + static FILE_LINE: (&'static str, uint) = (file!(), line!()); + ::std::rt::begin_unwind_fmt(fmt, &FILE_LINE) + } + format_args!(run_fmt, $fmt, $($arg)*) + }); +) + +#[macro_export] +#[cfg(stage0)] macro_rules! fail( () => ({ fail!("explicit failure") |
