Skip to content

Commit b004493

Browse files
committed
Remove unnecessary unwind messages
Now that the type_id intrinsic is working across crates, all of these unnecessary messages can be removed to have the failure type for a task truly be ~Any and only ~Any
1 parent 6163743 commit b004493

File tree

5 files changed

+41
-76
lines changed

5 files changed

+41
-76
lines changed

src/libstd/any.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use util::Void;
2020

2121
///////////////////////////////////////////////////////////////////////////////
2222
// TypeId
23-
// FIXME: #9913 - Needs proper intrinsic support to work reliably cross crate
2423
///////////////////////////////////////////////////////////////////////////////
2524

2625
/// `TypeId` represents a globally unique identifier for a type
@@ -199,8 +198,10 @@ mod tests {
199198

200199
#[test]
201200
fn type_id() {
202-
let (a, b, c) = (TypeId::of::<uint>(), TypeId::of::<&str>(), TypeId::of::<Test>());
203-
let (d, e, f) = (TypeId::of::<uint>(), TypeId::of::<&str>(), TypeId::of::<Test>());
201+
let (a, b, c) = (TypeId::of::<uint>(), TypeId::of::<&'static str>(),
202+
TypeId::of::<Test>());
203+
let (d, e, f) = (TypeId::of::<uint>(), TypeId::of::<&'static str>(),
204+
TypeId::of::<Test>());
204205

205206
assert!(a != b);
206207
assert!(a != c);

src/libstd/rt/kill.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ use cell::Cell;
155155
use option::{Option, Some, None};
156156
use prelude::*;
157157
use rt::task::Task;
158-
use rt::task::UnwindMessageLinked;
159158
use rt::task::{UnwindResult, Failure};
160159
use task::spawn::Taskgroup;
160+
use task::LinkedFailure;
161161
use to_bytes::IterBytes;
162162
use unstable::atomics::{AtomicUint, Relaxed};
163163
use unstable::sync::{UnsafeArc, UnsafeArcSelf, UnsafeArcT, LittleLock};
@@ -597,7 +597,7 @@ impl Death {
597597
}
598598

599599
if !success {
600-
result = Cell::new(Failure(UnwindMessageLinked));
600+
result = Cell::new(Failure(~LinkedFailure as ~Any));
601601
}
602602
}
603603
on_exit(result.take());

src/libstd/rt/task.rs

+24-53
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ use rt::logging::StdErrLogger;
3636
use rt::sched::{Scheduler, SchedHandle};
3737
use rt::stack::{StackSegment, StackPool};
3838
use send_str::SendStr;
39+
use task::LinkedFailure;
3940
use task::spawn::Taskgroup;
4041
use unstable::finally::Finally;
4142

@@ -95,8 +96,8 @@ pub enum UnwindResult {
9596
/// The task is ending successfully
9697
Success,
9798

98-
/// The Task is failing with reason `UnwindMessage`
99-
Failure(UnwindMessage),
99+
/// The Task is failing with reason `~Any`
100+
Failure(~Any),
100101
}
101102

102103
impl UnwindResult {
@@ -119,27 +120,9 @@ impl UnwindResult {
119120
}
120121
}
121122

122-
/// Represents the cause of a task failure
123-
#[deriving(ToStr)]
124-
pub enum UnwindMessage {
125-
// FIXME: #9913 - This variant is not neccessary once Any works properly
126-
/// Failed with a static string message
127-
UnwindMessageStrStatic(&'static str),
128-
129-
// FIXME: #9913 - This variant is not neccessary once Any works properly
130-
/// Failed with a owned string message
131-
UnwindMessageStrOwned(~str),
132-
133-
/// Failed with an `~Any`
134-
UnwindMessageAny(~Any),
135-
136-
/// Failed because of linked failure
137-
UnwindMessageLinked
138-
}
139-
140123
pub struct Unwinder {
141124
unwinding: bool,
142-
cause: Option<UnwindMessage>
125+
cause: Option<~Any>
143126
}
144127

145128
impl Unwinder {
@@ -532,7 +515,7 @@ impl Unwinder {
532515
}
533516
}
534517

535-
pub fn begin_unwind(&mut self, cause: UnwindMessage) -> ! {
518+
pub fn begin_unwind(&mut self, cause: ~Any) -> ! {
536519
#[fixed_stack_segment]; #[inline(never)];
537520

538521
self.unwinding = true;
@@ -648,46 +631,34 @@ pub fn begin_unwind_raw(msg: *c_char, file: *c_char, line: size_t) -> ! {
648631

649632
/// This is the entry point of unwinding for fail!() and assert!().
650633
pub fn begin_unwind<M: Any + Send>(msg: M, file: &'static str, line: uint) -> ! {
651-
// Wrap the fail message in a `Any` box for uniform representation.
652-
let any = ~msg as ~Any;
653-
654-
// FIXME: #9913 - This can be changed to be internal to begin_unwind_internal
655-
// once Any works properly.
656-
// As a workaround, string types need to be special cased right now
657-
// because `Any` does not support dynamically querying whether the
658-
// type implements a trait yet, so without requiring that every `Any`
659-
// also implements `ToStr` there is no way to get a failure message
660-
// out of it again during unwinding.
661-
let msg = if any.is::<&'static str>() {
662-
UnwindMessageStrStatic(*any.move::<&'static str>().unwrap())
663-
} else if any.is::<~str>() {
664-
UnwindMessageStrOwned(*any.move::<~str>().unwrap())
665-
} else {
666-
UnwindMessageAny(any)
667-
};
668-
669-
begin_unwind_internal(msg, file, line)
670-
}
671-
672-
fn begin_unwind_internal(msg: UnwindMessage, file: &'static str, line: uint) -> ! {
634+
use any::AnyRefExt;
673635
use rt::in_green_task_context;
674-
use rt::task::Task;
675636
use rt::local::Local;
637+
use rt::task::Task;
676638
use str::Str;
677639
use unstable::intrinsics;
678640

679641
unsafe {
680-
// Be careful not to allocate in this block, if we're failing we may
681-
// have been failing due to a lack of memory in the first place...
682-
683642
let task: *mut Task;
643+
// Note that this should be the only allocation performed in this block.
644+
// Currently this means that fail!() on OOM will invoke this code path,
645+
// but then again we're not really ready for failing on OOM anyway. If
646+
// we do start doing this, then we should propagate this allocation to
647+
// be performed in the parent of this task instead of the task that's
648+
// failing.
649+
let msg = ~msg as ~Any;
684650

685651
{
686-
let msg_s = match msg {
687-
UnwindMessageAny(_) => "~Any",
688-
UnwindMessageLinked => "linked failure",
689-
UnwindMessageStrOwned(ref s) => s.as_slice(),
690-
UnwindMessageStrStatic(ref s) => s.as_slice(),
652+
//let msg: &Any = msg;
653+
let msg_s = match msg.as_ref::<&'static str>() {
654+
Some(s) => *s,
655+
None => match msg.as_ref::<~str>() {
656+
Some(s) => s.as_slice(),
657+
None => match msg.as_ref::<LinkedFailure>() {
658+
Some(*) => "linked failure",
659+
None => "~Any",
660+
}
661+
}
691662
};
692663

693664
if !in_green_task_context() {

src/libstd/task/mod.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ use comm::{stream, Chan, GenericChan, GenericPort, Port, Peekable};
6060
use result::{Result, Ok, Err};
6161
use rt::in_green_task_context;
6262
use rt::local::Local;
63-
use rt::task::{UnwindMessageAny, UnwindMessageLinked};
64-
use rt::task::{UnwindMessageStrStatic, UnwindMessageStrOwned};
6563
use rt::task::{UnwindResult, Success, Failure};
6664
use send_str::{SendStr, IntoSendStr};
6765
use unstable::finally::Finally;
@@ -90,30 +88,25 @@ pub type TaskResult = Result<(), ~Any>;
9088

9189
pub struct LinkedFailure;
9290

93-
#[inline]
94-
fn wrap_as_any(res: UnwindResult) -> TaskResult {
95-
match res {
96-
Success => Ok(()),
97-
Failure(UnwindMessageAny(a)) => Err(a),
98-
Failure(UnwindMessageLinked) => Err(~LinkedFailure as ~Any),
99-
Failure(UnwindMessageStrOwned(s)) => Err(~s as ~Any),
100-
Failure(UnwindMessageStrStatic(s)) => Err(~s as ~Any),
101-
}
102-
}
103-
10491
pub struct TaskResultPort {
10592
priv port: Port<UnwindResult>
10693
}
10794

95+
fn to_task_result(res: UnwindResult) -> TaskResult {
96+
match res {
97+
Success => Ok(()), Failure(a) => Err(a),
98+
}
99+
}
100+
108101
impl GenericPort<TaskResult> for TaskResultPort {
109102
#[inline]
110103
fn recv(&self) -> TaskResult {
111-
wrap_as_any(self.port.recv())
104+
to_task_result(self.port.recv())
112105
}
113106

114107
#[inline]
115108
fn try_recv(&self) -> Option<TaskResult> {
116-
self.port.try_recv().map(wrap_as_any)
109+
self.port.try_recv().map(to_task_result)
117110
}
118111
}
119112

src/libstd/task/spawn.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ use local_data;
8383
use rt::local::Local;
8484
use rt::sched::{Scheduler, Shutdown, TaskFromFriend};
8585
use rt::task::{Task, Sched};
86-
use rt::task::{UnwindMessageLinked, UnwindMessageStrStatic};
8786
use rt::task::{UnwindResult, Success, Failure};
8887
use rt::thread::Thread;
8988
use rt::work_queue::WorkQueue;
9089
use rt::{in_green_task_context, new_event_loop, KillHandle};
90+
use task::LinkedFailure;
9191
use task::SingleThreaded;
9292
use task::TaskOpts;
9393
use task::unkillable;
@@ -324,7 +324,7 @@ impl Drop for Taskgroup {
324324
do RuntimeGlue::with_task_handle_and_failing |me, failing| {
325325
if failing {
326326
for x in self.notifier.mut_iter() {
327-
x.task_result = Some(Failure(UnwindMessageLinked));
327+
x.task_result = Some(Failure(~LinkedFailure as ~Any));
328328
}
329329
// Take everybody down with us. After this point, every
330330
// other task in the group will see 'tg' as none, which
@@ -379,7 +379,7 @@ impl AutoNotify {
379379
notify_chan: chan,
380380

381381
// Un-set above when taskgroup successfully made.
382-
task_result: Some(Failure(UnwindMessageStrStatic("AutoNotify::new()")))
382+
task_result: Some(Failure(~("AutoNotify::new()") as ~Any))
383383
}
384384
}
385385
}

0 commit comments

Comments
 (0)