Skip to content

Commit 4636b32

Browse files
committed
Make most of the failure functions take &(&'static str, uint)
Passing one pointer takes less code than one pointer and an integer.
1 parent b9035c2 commit 4636b32

File tree

4 files changed

+54
-16
lines changed

4 files changed

+54
-16
lines changed

src/libcore/failure.rs

+42-3
Original file line numberDiff line numberDiff line change
@@ -33,33 +33,72 @@
3333
use fmt;
3434
use intrinsics;
3535

36+
#[cfg(stage0)]
3637
#[cold] #[inline(never)] // this is the slow path, always
3738
#[lang="fail_"]
3839
fn fail_(expr: &'static str, file: &'static str, line: uint) -> ! {
3940
format_args!(|args| -> () {
40-
begin_unwind(args, file, line);
41+
begin_unwind(args, &(file, line));
4142
}, "{}", expr);
4243

4344
unsafe { intrinsics::abort() }
4445
}
4546

47+
#[cfg(stage0)]
4648
#[cold]
4749
#[lang="fail_bounds_check"]
4850
fn fail_bounds_check(file: &'static str, line: uint,
4951
index: uint, len: uint) -> ! {
5052
format_args!(|args| -> () {
51-
begin_unwind(args, file, line);
53+
begin_unwind(args, &(file, line));
5254
}, "index out of bounds: the len is {} but the index is {}", len, index);
5355
unsafe { intrinsics::abort() }
5456
}
5557

58+
#[cfg(stage0)]
5659
#[cold]
57-
pub fn begin_unwind(fmt: &fmt::Arguments, file: &'static str, line: uint) -> ! {
60+
pub fn begin_unwind(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
5861
#[allow(ctypes)]
5962
extern {
6063
#[lang = "begin_unwind"]
6164
fn begin_unwind(fmt: &fmt::Arguments, file: &'static str,
6265
line: uint) -> !;
6366
}
67+
let (file, line) = *file_line;
68+
unsafe { begin_unwind(fmt, file, line) }
69+
}
70+
71+
#[cfg(not(stage0))]
72+
#[cold] #[inline(never)] // this is the slow path, always
73+
#[lang="fail_"]
74+
fn fail_(expr: &'static str, file: &'static str, line: uint) -> ! {
75+
format_args!(|args| -> () {
76+
begin_unwind(args, &(file, line));
77+
}, "{}", expr);
78+
79+
unsafe { intrinsics::abort() }
80+
}
81+
82+
#[cfg(not(stage0))]
83+
#[cold]
84+
#[lang="fail_bounds_check"]
85+
fn fail_bounds_check(file: &'static str, line: uint,
86+
index: uint, len: uint) -> ! {
87+
format_args!(|args| -> () {
88+
begin_unwind(args, &(file, line));
89+
}, "index out of bounds: the len is {} but the index is {}", len, index);
90+
unsafe { intrinsics::abort() }
91+
}
92+
93+
#[cfg(not(stage0))]
94+
#[cold]
95+
pub fn begin_unwind(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
96+
#[allow(ctypes)]
97+
extern {
98+
#[lang = "begin_unwind"]
99+
fn begin_unwind(fmt: &fmt::Arguments, file_line: &'static str,
100+
line: uint) -> !;
101+
}
102+
let (file, line) = *file_line;
64103
unsafe { begin_unwind(fmt, file, line) }
65104
}

src/libcore/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ 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+
::core::failure::begin_unwind(fmt, &(file!(), line!()))
3737
}
3838
format_args!(run_fmt, $fmt, $($arg)*)
3939
});

src/librustrt/unwind.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ pub mod eabi {
384384
#[lang = "begin_unwind"]
385385
pub extern fn rust_begin_unwind(msg: &fmt::Arguments,
386386
file: &'static str, line: uint) -> ! {
387-
begin_unwind_fmt(msg, file, line)
387+
begin_unwind_fmt(msg, &(file, line))
388388
}
389389

390390
/// The entry point for unwinding with a formatted message.
@@ -394,8 +394,7 @@ pub extern fn rust_begin_unwind(msg: &fmt::Arguments,
394394
/// on (e.g.) the inlining of other functions as possible), by moving
395395
/// the actual formatting into this shared place.
396396
#[inline(never)] #[cold]
397-
pub fn begin_unwind_fmt(msg: &fmt::Arguments, file: &'static str,
398-
line: uint) -> ! {
397+
pub fn begin_unwind_fmt(msg: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
399398
use core::fmt::FormatWriter;
400399

401400
// We do two allocations here, unfortunately. But (a) they're
@@ -415,9 +414,10 @@ pub fn begin_unwind_fmt(msg: &fmt::Arguments, file: &'static str,
415414
let mut v = Vec::new();
416415
let _ = write!(&mut VecWriter { v: &mut v }, "{}", msg);
417416

418-
begin_unwind_inner(box String::from_utf8(v).unwrap(), file, line)
417+
begin_unwind_inner(box String::from_utf8(v).unwrap(), file_line)
419418
}
420419

420+
// FIXME: Need to change expr_fail in AstBuilder to change this to &(str, uint)
421421
/// This is the entry point of unwinding for fail!() and assert!().
422422
#[inline(never)] #[cold] // avoid code bloat at the call sites as much as possible
423423
pub fn begin_unwind<M: Any + Send>(msg: M, file: &'static str, line: uint) -> ! {
@@ -429,13 +429,13 @@ pub fn begin_unwind<M: Any + Send>(msg: M, file: &'static str, line: uint) -> !
429429
// failing.
430430

431431
// see below for why we do the `Any` coercion here.
432-
begin_unwind_inner(box msg, file, line)
432+
begin_unwind_inner(box msg, &(file, line))
433433
}
434434

435435
/// Unwinding for `fail!()`. Saves passing a string.
436436
#[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)
437+
pub fn begin_unwind_no_time_to_explain(file_line: &(&'static str, uint)) -> ! {
438+
begin_unwind_inner(box () ("explicit failure"), file_line)
439439
}
440440

441441
/// The core of the unwinding.
@@ -448,9 +448,7 @@ pub fn begin_unwind_no_time_to_explain(file: &'static str, line: uint) -> ! {
448448
/// Do this split took the LLVM IR line counts of `fn main() { fail!()
449449
/// }` from ~1900/3700 (-O/no opts) to 180/590.
450450
#[inline(never)] #[cold] // this is the slow path, please never inline this
451-
fn begin_unwind_inner(msg: Box<Any + Send>,
452-
file: &'static str,
453-
line: uint) -> ! {
451+
fn begin_unwind_inner(msg: Box<Any + Send>, file_line: &(&'static str, uint)) -> ! {
454452
// First, invoke call the user-defined callbacks triggered on task failure.
455453
//
456454
// By the time that we see a callback has been registered (by reading
@@ -467,6 +465,7 @@ fn begin_unwind_inner(msg: Box<Any + Send>,
467465
0 => {}
468466
n => {
469467
let f: Callback = unsafe { mem::transmute(n) };
468+
let (file, line) = *file_line;
470469
f(msg, file, line);
471470
}
472471
}

src/libstd/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#[macro_export]
4040
macro_rules! fail(
4141
() => (
42-
::std::rt::begin_unwind_no_time_to_explain(file!(), line!())
42+
::std::rt::begin_unwind_no_time_to_explain(&(file!(), line!()))
4343
);
4444
($msg:expr) => (
4545
::std::rt::begin_unwind($msg, file!(), line!())
@@ -58,7 +58,7 @@ macro_rules! fail(
5858
// up with the number of calls to fail!()
5959
#[inline(always)]
6060
fn run_fmt(fmt: &::std::fmt::Arguments) -> ! {
61-
::std::rt::begin_unwind_fmt(fmt, file!(), line!())
61+
::std::rt::begin_unwind_fmt(fmt, &(file!(), line!()))
6262
}
6363
format_args!(run_fmt, $fmt, $($arg)*)
6464
});

0 commit comments

Comments
 (0)