Skip to content

Commit bfcde30

Browse files
committed
auto merge of rust-lang#15876 : brson/rust/failfat, r=pcwalton
Adds a new runtime unwinding function that encapsulates the printing of the words "explicit failure" when `fail!()` is called w/o arguments. The before/after optimized assembly: ``` leaq "str\"str\"(1412)"(%rip), %rax movq %rax, 24(%rsp) movq $16, 32(%rsp) leaq "str\"str\"(1413)"(%rip), %rax movq %rax, 8(%rsp) movq $19, 16(%rsp) leaq 24(%rsp), %rdi leaq 8(%rsp), %rsi movl $11, %edx callq _ZN6unwind12begin_unwind21h15836560661922107792E ``` ``` leaq "str\"str\"(1369)"(%rip), %rax movq %rax, 8(%rsp) movq $19, 16(%rsp) leaq 8(%rsp), %rdi movl $11, %esi callq _ZN6unwind31begin_unwind_no_time_to_explain20hd1c720cdde6a116480dE@PLT ``` Before/after filesizes: rwxrwxr-x 1 brian brian 21479503 Jul 20 22:09 stage2-old/lib/librustc-4e7c5e5c.so rwxrwxr-x 1 brian brian 21475415 Jul 20 22:30 x86_64-unknown-linux-gnu/stage2/lib/librustc-4e7c5e5c.so This is the lowest-hanging fruit in the fail-bloat wars. Further fixes are going to require harder tradeoffs. r? @pcwalton
2 parents 62f1bb0 + c61f976 commit bfcde30

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

src/librustrt/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ extern crate collections;
3333
#[cfg(test)] #[phase(plugin, link)] extern crate std;
3434

3535
pub use self::util::{Stdio, Stdout, Stderr};
36-
pub use self::unwind::{begin_unwind, begin_unwind_fmt};
36+
pub use self::unwind::{begin_unwind, begin_unwind_fmt, begin_unwind_no_time_to_explain};
3737

3838
use core::prelude::*;
3939

src/librustrt/unwind.rs

+5
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,11 @@ pub fn begin_unwind<M: Any + Send>(msg: M, file: &'static str, line: uint) -> !
432432
begin_unwind_inner(box msg, file, line)
433433
}
434434

435+
/// Unwinding for `fail!()`. Saves passing a string.
436+
#[inline(never)] #[cold] #[experimental]
437+
pub fn begin_unwind_no_time_to_explain(file: &'static str, line: uint) -> ! {
438+
begin_unwind_inner(box () ("explicit failure"), file, line)
439+
}
435440

436441
/// The core of the unwinding.
437442
///

src/libstd/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#[macro_export]
4040
macro_rules! fail(
4141
() => (
42-
fail!("explicit failure")
42+
::std::rt::begin_unwind_no_time_to_explain(file!(), line!())
4343
);
4444
($msg:expr) => (
4545
::std::rt::begin_unwind($msg, file!(), line!())

src/libstd/rt/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ pub use self::util::{default_sched_threads, min_stack, running_on_valgrind};
6666
// standard library which work together to create the entire runtime.
6767
pub use alloc::{heap, libc_heap};
6868
pub use rustrt::{task, local, mutex, exclusive, stack, args, rtio, thread};
69-
pub use rustrt::{Stdio, Stdout, Stderr, begin_unwind, begin_unwind_fmt};
69+
pub use rustrt::{Stdio, Stdout, Stderr};
70+
pub use rustrt::{begin_unwind, begin_unwind_fmt, begin_unwind_no_time_to_explain};
7071
pub use rustrt::{bookkeeping, at_exit, unwind, DEFAULT_ERROR_CODE, Runtime};
7172

7273
// Simple backtrace functionality (to print on failure)

0 commit comments

Comments
 (0)