Skip to content

Commit 48d78c9

Browse files
brsonalexcrichton
authored andcommitted
---
yaml --- r: 125533 b: refs/heads/auto c: 134946d h: refs/heads/master i: 125531: 86accdc v: v3
1 parent 32815c4 commit 48d78c9

File tree

4 files changed

+58
-7
lines changed

4 files changed

+58
-7
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: 571f6cf29ae181098e3aff43a5f8e345be6708e9
16+
refs/heads/auto: 134946d06e6926e087a792ac13c7f4421591afed
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/librustrt/unwind.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,8 +417,8 @@ pub fn begin_unwind_fmt(msg: &fmt::Arguments, file_line: &(&'static str, uint))
417417
begin_unwind_inner(box String::from_utf8(v).unwrap(), file_line)
418418
}
419419

420-
// FIXME: Need to change expr_fail in AstBuilder to change this to &(str, uint)
421420
/// This is the entry point of unwinding for fail!() and assert!().
421+
#[cfg(stage0)]
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) -> ! {
424424
// Note that this should be the only allocation performed in this code path.
@@ -432,6 +432,21 @@ 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+
/// This is the entry point of unwinding for fail!() and assert!().
436+
#[cfg(not(stage0))]
437+
#[inline(never)] #[cold] // avoid code bloat at the call sites as much as possible
438+
pub fn begin_unwind<M: Any + Send>(msg: M, file_line: &(&'static str, uint)) -> ! {
439+
// Note that this should be the only allocation performed in this code path.
440+
// Currently this means that fail!() on OOM will invoke this code path,
441+
// but then again we're not really ready for failing on OOM anyway. If
442+
// we do start doing this, then we should propagate this allocation to
443+
// be performed in the parent of this task instead of the task that's
444+
// failing.
445+
446+
// see below for why we do the `Any` coercion here.
447+
begin_unwind_inner(box msg, file_line)
448+
}
449+
435450
/// The core of the unwinding.
436451
///
437452
/// This is non-generic to avoid instantiation bloat in other crates

branches/auto/src/libstd/macros.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,39 @@
3737
/// fail!("this is a {} {message}", "fancy", message = "message");
3838
/// ```
3939
#[macro_export]
40+
#[cfg(not(stage0))]
41+
macro_rules! fail(
42+
() => ({
43+
fail!("explicit failure")
44+
});
45+
($msg:expr) => ({
46+
// static requires less code at runtime, more constant data
47+
static FILE_LINE: (&'static str, uint) = (file!(), line!());
48+
::std::rt::begin_unwind($msg, &FILE_LINE)
49+
});
50+
($fmt:expr, $($arg:tt)*) => ({
51+
// a closure can't have return type !, so we need a full
52+
// function to pass to format_args!, *and* we need the
53+
// file and line numbers right here; so an inner bare fn
54+
// is our only choice.
55+
//
56+
// LLVM doesn't tend to inline this, presumably because begin_unwind_fmt
57+
// is #[cold] and #[inline(never)] and because this is flagged as cold
58+
// as returning !. We really do want this to be inlined, however,
59+
// because it's just a tiny wrapper. Small wins (156K to 149K in size)
60+
// were seen when forcing this to be inlined, and that number just goes
61+
// up with the number of calls to fail!()
62+
#[inline(always)]
63+
fn run_fmt(fmt: &::std::fmt::Arguments) -> ! {
64+
static FILE_LINE: (&'static str, uint) = (file!(), line!());
65+
::std::rt::begin_unwind_fmt(fmt, &FILE_LINE)
66+
}
67+
format_args!(run_fmt, $fmt, $($arg)*)
68+
});
69+
)
70+
71+
#[macro_export]
72+
#[cfg(stage0)]
4073
macro_rules! fail(
4174
() => ({
4275
fail!("explicit failure")

branches/auto/src/libsyntax/ext/build.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,13 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
690690

691691
fn expr_fail(&self, span: Span, msg: InternedString) -> Gc<ast::Expr> {
692692
let loc = self.codemap().lookup_char_pos(span.lo);
693+
let expr_file = self.expr_str(span,
694+
token::intern_and_get_ident(loc.file
695+
.name
696+
.as_slice()));
697+
let expr_line = self.expr_uint(span, loc.line);
698+
let expr_file_line_tuple = self.expr_tuple(span, vec!(expr_file, expr_line));
699+
let expr_file_line_ptr = self.expr_addr_of(span, expr_file_line_tuple);
693700
self.expr_call_global(
694701
span,
695702
vec!(
@@ -698,11 +705,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> {
698705
self.ident_of("begin_unwind")),
699706
vec!(
700707
self.expr_str(span, msg),
701-
self.expr_str(span,
702-
token::intern_and_get_ident(loc.file
703-
.name
704-
.as_slice())),
705-
self.expr_uint(span, loc.line)))
708+
expr_file_line_ptr))
706709
}
707710

708711
fn expr_unreachable(&self, span: Span) -> Gc<ast::Expr> {

0 commit comments

Comments
 (0)