-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Prepared std::sys
for removal, and made begin_unwind
simpler
#10120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,8 +95,8 @@ pub enum UnwindResult { | |
/// The task is ending successfully | ||
Success, | ||
|
||
/// The Task is failing with reason `UnwindReason` | ||
Failure(UnwindReason), | ||
/// The Task is failing with reason `UnwindMessage` | ||
Failure(UnwindMessage), | ||
} | ||
|
||
impl UnwindResult { | ||
|
@@ -121,20 +121,25 @@ impl UnwindResult { | |
|
||
/// Represents the cause of a task failure | ||
#[deriving(ToStr)] | ||
pub enum UnwindReason { | ||
/// Failed with a string message | ||
UnwindReasonStr(SendStr), | ||
pub enum UnwindMessage { | ||
// FIXME: #9913 - This variant is not neccessary once Any works properly | ||
/// Failed with a static string message | ||
UnwindMessageStrStatic(&'static str), | ||
|
||
// FIXME: #9913 - This variant is not neccessary once Any works properly | ||
/// Failed with a owned string message | ||
UnwindMessageStrOwned(~str), | ||
|
||
/// Failed with an `~Any` | ||
UnwindReasonAny(~Any), | ||
UnwindMessageAny(~Any), | ||
|
||
/// Failed because of linked failure | ||
UnwindReasonLinked | ||
UnwindMessageLinked | ||
} | ||
|
||
pub struct Unwinder { | ||
unwinding: bool, | ||
cause: Option<UnwindReason> | ||
cause: Option<UnwindMessage> | ||
} | ||
|
||
impl Unwinder { | ||
|
@@ -527,7 +532,7 @@ impl Unwinder { | |
} | ||
} | ||
|
||
pub fn begin_unwind(&mut self, cause: UnwindReason) -> ! { | ||
pub fn begin_unwind(&mut self, cause: UnwindMessage) -> ! { | ||
#[fixed_stack_segment]; #[inline(never)]; | ||
|
||
self.unwinding = true; | ||
|
@@ -622,7 +627,7 @@ pub extern "C" fn rust_stack_exhausted() { | |
/// This is the entry point of unwinding for things like lang items and such. | ||
/// The arguments are normally generated by the compiler, and need to | ||
/// have static lifetimes. | ||
pub fn begin_unwind(msg: *c_char, file: *c_char, line: size_t) -> ! { | ||
pub fn begin_unwind_raw(msg: *c_char, file: *c_char, line: size_t) -> ! { | ||
use c_str::CString; | ||
use cast::transmute; | ||
|
||
|
@@ -638,11 +643,33 @@ pub fn begin_unwind(msg: *c_char, file: *c_char, line: size_t) -> ! { | |
let msg = static_char_ptr(msg); | ||
let file = static_char_ptr(file); | ||
|
||
begin_unwind_reason(UnwindReasonStr(msg.into_send_str()), file, line as uint) | ||
begin_unwind(msg, file, line as uint) | ||
} | ||
|
||
/// This is the entry point of unwinding for fail!() and assert!(). | ||
pub fn begin_unwind_reason(reason: UnwindReason, file: &'static str, line: uint) -> ! { | ||
pub fn begin_unwind<M: Any + Send>(msg: M, file: &'static str, line: uint) -> ! { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because fn foo<T: Send>(t: T) -> ~Any { ~t as ~Any } Seems to compile for me, so I would hope that it could be removed. |
||
// Wrap the fail message in a `Any` box for uniform representation. | ||
let any = ~msg as ~Any; | ||
|
||
// FIXME: #9913 - This can be changed to be internal to begin_unwind_internal | ||
// once Any works properly. | ||
// As a workaround, string types need to be special cased right now | ||
// because `Any` does not support dynamically querying whether the | ||
// type implements a trait yet, so without requiring that every `Any` | ||
// also implements `ToStr` there is no way to get a failure message | ||
// out of it again during unwinding. | ||
let msg = if any.is::<&'static str>() { | ||
UnwindMessageStrStatic(*any.move::<&'static str>().unwrap()) | ||
} else if any.is::<~str>() { | ||
UnwindMessageStrOwned(*any.move::<~str>().unwrap()) | ||
} else { | ||
UnwindMessageAny(any) | ||
}; | ||
|
||
begin_unwind_internal(msg, file, line) | ||
} | ||
|
||
fn begin_unwind_internal(msg: UnwindMessage, file: &'static str, line: uint) -> ! { | ||
use rt::in_green_task_context; | ||
use rt::task::Task; | ||
use rt::local::Local; | ||
|
@@ -656,15 +683,16 @@ pub fn begin_unwind_reason(reason: UnwindReason, file: &'static str, line: uint) | |
let task: *mut Task; | ||
|
||
{ | ||
let msg = match reason { | ||
UnwindReasonStr(ref s) => s.as_slice(), | ||
UnwindReasonAny(_) => "~Any", | ||
UnwindReasonLinked => "linked failure", | ||
let msg_s = match msg { | ||
UnwindMessageAny(_) => "~Any", | ||
UnwindMessageLinked => "linked failure", | ||
UnwindMessageStrOwned(ref s) => s.as_slice(), | ||
UnwindMessageStrStatic(ref s) => s.as_slice(), | ||
}; | ||
|
||
if !in_green_task_context() { | ||
rterrln!("failed in non-task context at '{}', {}:{}", | ||
msg, file, line); | ||
msg_s, file, line); | ||
intrinsics::abort(); | ||
} | ||
|
||
|
@@ -679,19 +707,20 @@ pub fn begin_unwind_reason(reason: UnwindReason, file: &'static str, line: uint) | |
// due to mismanagment of its own kill flag, so calling our own | ||
// logger in its current state is a bit of a problem. | ||
|
||
rterrln!("task '{}' failed at '{}', {}:{}", n, msg, file, line); | ||
rterrln!("task '{}' failed at '{}', {}:{}", n, msg_s, file, line); | ||
|
||
if (*task).unwinder.unwinding { | ||
rtabort!("unwinding again"); | ||
} | ||
} | ||
|
||
(*task).unwinder.begin_unwind(reason); | ||
(*task).unwinder.begin_unwind(msg); | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use super::*; | ||
use rt::test::*; | ||
|
||
#[test] | ||
|
@@ -804,4 +833,8 @@ mod test { | |
a.next = Some(b); | ||
} | ||
} | ||
|
||
#[test] | ||
#[should_fail] | ||
fn test_begin_unwind() { begin_unwind("cause", file!(), line!()) } | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As below, can this be tagged as a FIXME pointing at 9913? It seems like this should be just
~Any