about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2014-07-24 21:33:46 -0700
committerBrian Anderson <banderson@mozilla.com>2014-07-25 00:02:29 -0700
commit4636b32a42ea3111f53048197092e7ac08e6f792 (patch)
tree3801e7d70873d01f567f3eda119cc12c3a59cb5a
parentb9035c26e2c4368b39c8daa979f669d10d484825 (diff)
downloadrust-4636b32a42ea3111f53048197092e7ac08e6f792.tar.gz
rust-4636b32a42ea3111f53048197092e7ac08e6f792.zip
Make most of the failure functions take &(&'static str, uint)
Passing one pointer takes less code than one pointer and an integer.
-rw-r--r--src/libcore/failure.rs45
-rw-r--r--src/libcore/macros.rs2
-rw-r--r--src/librustrt/unwind.rs19
-rw-r--r--src/libstd/macros.rs4
4 files changed, 54 insertions, 16 deletions
diff --git a/src/libcore/failure.rs b/src/libcore/failure.rs
index 4bc39db8ecf..022258911f1 100644
--- a/src/libcore/failure.rs
+++ b/src/libcore/failure.rs
@@ -33,33 +33,72 @@
 use fmt;
 use intrinsics;
 
+#[cfg(stage0)]
 #[cold] #[inline(never)] // this is the slow path, always
 #[lang="fail_"]
 fn fail_(expr: &'static str, file: &'static str, line: uint) -> ! {
     format_args!(|args| -> () {
-        begin_unwind(args, file, line);
+        begin_unwind(args, &(file, line));
     }, "{}", expr);
 
     unsafe { intrinsics::abort() }
 }
 
+#[cfg(stage0)]
 #[cold]
 #[lang="fail_bounds_check"]
 fn fail_bounds_check(file: &'static str, line: uint,
                      index: uint, len: uint) -> ! {
     format_args!(|args| -> () {
-        begin_unwind(args, file, line);
+        begin_unwind(args, &(file, line));
     }, "index out of bounds: the len is {} but the index is {}", len, index);
     unsafe { intrinsics::abort() }
 }
 
+#[cfg(stage0)]
 #[cold]
-pub fn begin_unwind(fmt: &fmt::Arguments, file: &'static str, line: uint) -> ! {
+pub fn begin_unwind(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
     #[allow(ctypes)]
     extern {
         #[lang = "begin_unwind"]
         fn begin_unwind(fmt: &fmt::Arguments, file: &'static str,
                         line: uint) -> !;
     }
+    let (file, line) = *file_line;
+    unsafe { begin_unwind(fmt, file, line) }
+}
+
+#[cfg(not(stage0))]
+#[cold] #[inline(never)] // this is the slow path, always
+#[lang="fail_"]
+fn fail_(expr: &'static str, file: &'static str, line: uint) -> ! {
+    format_args!(|args| -> () {
+        begin_unwind(args, &(file, line));
+    }, "{}", expr);
+
+    unsafe { intrinsics::abort() }
+}
+
+#[cfg(not(stage0))]
+#[cold]
+#[lang="fail_bounds_check"]
+fn fail_bounds_check(file: &'static str, line: uint,
+                     index: uint, len: uint) -> ! {
+    format_args!(|args| -> () {
+        begin_unwind(args, &(file, line));
+    }, "index out of bounds: the len is {} but the index is {}", len, index);
+    unsafe { intrinsics::abort() }
+}
+
+#[cfg(not(stage0))]
+#[cold]
+pub fn begin_unwind(fmt: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
+    #[allow(ctypes)]
+    extern {
+        #[lang = "begin_unwind"]
+        fn begin_unwind(fmt: &fmt::Arguments, file_line: &'static str,
+                        line: uint) -> !;
+    }
+    let (file, line) = *file_line;
     unsafe { begin_unwind(fmt, file, line) }
 }
diff --git a/src/libcore/macros.rs b/src/libcore/macros.rs
index 93c838198c5..e2709c4edde 100644
--- a/src/libcore/macros.rs
+++ b/src/libcore/macros.rs
@@ -33,7 +33,7 @@ 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!())
+            ::core::failure::begin_unwind(fmt, &(file!(), line!()))
         }
         format_args!(run_fmt, $fmt, $($arg)*)
     });
diff --git a/src/librustrt/unwind.rs b/src/librustrt/unwind.rs
index cb1b6f46afe..db2cae23718 100644
--- a/src/librustrt/unwind.rs
+++ b/src/librustrt/unwind.rs
@@ -384,7 +384,7 @@ pub mod eabi {
 #[lang = "begin_unwind"]
 pub extern fn rust_begin_unwind(msg: &fmt::Arguments,
                                 file: &'static str, line: uint) -> ! {
-    begin_unwind_fmt(msg, file, line)
+    begin_unwind_fmt(msg, &(file, line))
 }
 
 /// The entry point for unwinding with a formatted message.
@@ -394,8 +394,7 @@ pub extern fn rust_begin_unwind(msg: &fmt::Arguments,
 /// on (e.g.) the inlining of other functions as possible), by moving
 /// the actual formatting into this shared place.
 #[inline(never)] #[cold]
-pub fn begin_unwind_fmt(msg: &fmt::Arguments, file: &'static str,
-                        line: uint) -> ! {
+pub fn begin_unwind_fmt(msg: &fmt::Arguments, file_line: &(&'static str, uint)) -> ! {
     use core::fmt::FormatWriter;
 
     // 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,
     let mut v = Vec::new();
     let _ = write!(&mut VecWriter { v: &mut v }, "{}", msg);
 
-    begin_unwind_inner(box String::from_utf8(v).unwrap(), file, line)
+    begin_unwind_inner(box String::from_utf8(v).unwrap(), file_line)
 }
 
+// FIXME: Need to change expr_fail in AstBuilder to change this to &(str, uint)
 /// This is the entry point of unwinding for fail!() and assert!().
 #[inline(never)] #[cold] // avoid code bloat at the call sites as much as possible
 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) -> !
     // failing.
 
     // see below for why we do the `Any` coercion here.
-    begin_unwind_inner(box msg, file, line)
+    begin_unwind_inner(box msg, &(file, line))
 }
 
 /// Unwinding for `fail!()`. Saves passing a string.
 #[inline(never)] #[cold] #[experimental]
-pub fn begin_unwind_no_time_to_explain(file: &'static str, line: uint) -> ! {
-    begin_unwind_inner(box () ("explicit failure"), file, line)
+pub fn begin_unwind_no_time_to_explain(file_line: &(&'static str, uint)) -> ! {
+    begin_unwind_inner(box () ("explicit failure"), file_line)
 }
 
 /// The core of the unwinding.
@@ -448,9 +448,7 @@ pub fn begin_unwind_no_time_to_explain(file: &'static str, line: uint) -> ! {
 /// Do this split took the LLVM IR line counts of `fn main() { fail!()
 /// }` from ~1900/3700 (-O/no opts) to 180/590.
 #[inline(never)] #[cold] // this is the slow path, please never inline this
-fn begin_unwind_inner(msg: Box<Any + Send>,
-                      file: &'static str,
-                      line: uint) -> ! {
+fn begin_unwind_inner(msg: Box<Any + Send>, file_line: &(&'static str, uint)) -> ! {
     // First, invoke call the user-defined callbacks triggered on task failure.
     //
     // 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>,
             0 => {}
             n => {
                 let f: Callback = unsafe { mem::transmute(n) };
+                let (file, line) = *file_line;
                 f(msg, file, line);
             }
         }
diff --git a/src/libstd/macros.rs b/src/libstd/macros.rs
index 3c6c860f516..fd0c72ce313 100644
--- a/src/libstd/macros.rs
+++ b/src/libstd/macros.rs
@@ -39,7 +39,7 @@
 #[macro_export]
 macro_rules! fail(
     () => (
-        ::std::rt::begin_unwind_no_time_to_explain(file!(), line!())
+        ::std::rt::begin_unwind_no_time_to_explain(&(file!(), line!()))
     );
     ($msg:expr) => (
         ::std::rt::begin_unwind($msg, file!(), line!())
@@ -58,7 +58,7 @@ 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!())
+            ::std::rt::begin_unwind_fmt(fmt, &(file!(), line!()))
         }
         format_args!(run_fmt, $fmt, $($arg)*)
     });