@@ -36,6 +36,7 @@ use rt::logging::StdErrLogger;
3636use rt:: sched:: { Scheduler , SchedHandle } ;
3737use rt:: stack:: { StackSegment , StackPool } ;
3838use send_str:: SendStr ;
39+ use task:: LinkedFailure ;
3940use task:: spawn:: Taskgroup ;
4041use 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
102103impl 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-
140123pub struct Unwinder {
141124 unwinding : bool ,
142- cause : Option < UnwindMessage >
125+ cause : Option < ~ Any >
143126}
144127
145128impl 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!().
650633pub 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 ( ) {
0 commit comments