about summary refs log tree commit diff
path: root/src/rt/sync/rust_thread.cpp
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-10-28 01:26:16 -0700
committerbors <bors@rust-lang.org>2013-10-28 01:26:16 -0700
commit9ef23e9060d60189894f6d725e6c1c73b887c802 (patch)
tree0b8051814dd8a5ef08e663c172e2b456065d625d /src/rt/sync/rust_thread.cpp
parentcb5b21eba713ff3888b2741db4c9e7d841cfde02 (diff)
parentfa8e71a8257f4226ab532d4bf268d3ecbfa98eb4 (diff)
downloadrust-9ef23e9060d60189894f6d725e6c1c73b887c802.tar.gz
rust-9ef23e9060d60189894f6d725e6c1c73b887c802.zip
auto merge of #9967 : Kimundi/rust/fail_cause_two, r=huonw
# Summary

This PR allows the cause of a failure to be received in a task's future result and as the `Err` case of `task::try`, and also implements dynamic typing in form of an `Any` trait.

# Task failure

- `fail!` and related macros now accept 5 kinds of types: `~str`, `&'static str`, `std::send_str::SendStr`, `~std::any::Any` and `~T` where `T: Any + Send + 'static`
- `std::task::TaskResult` got transformed into an internal enum `std::rt::task::UnwindResult`,  and it's `Failure` variant now contains a value of enum type `UnwindReason`:
  - `UnwindReasonStr(SendStr)` maps to failing with a value of type `~str`, `&'static str` or `SendStr`.
  - `UnwindReasonAny(~Any)` maps to failing with an `~Any` or `~T` with `T: Send + 'static`.
  - `UnwindReasonLinked` maps to failing because the task got killed by linked failure.
- Instead, `std::task::TaskResult` is now a typedef for `Result<(), ~Any>`, and both `TaskBuilder`'s `future_result()` and `task::try` now work with a value of this type.
- `future_result()` no longer returns a `Port<TaskResult>`, instead it returns a wrapper `TaskResultPort` that implements `GenericPort` and `Peekable`, and which lazily allocates a `~` box and casts to `~Any` in case of failure with a `SendStr` or linked failure (for the latter case a unit struct `LinkedFailure` got added.)
- Because `fail!` collapses both `~str` and `&'static str` into a `SendStr`, checking if a task error value is a string will just require a `.is::<SendStr>()` check, with `~str` and `&'static str` only being possible in case of an explicit `fail!(~~"...")` or `fail!(~ (&"...") as ~Any)`:

# Any

- In order to allow failing with arbitrary data, the `Any` trait got implemented.
- It is being used in form of a trait object, usually `~Any` or `&Any`.
- `&Any`, `~Any` and `&mut Any` have a few extension methods implemented on them:
  - `is<T>(self) -> bool` returns true if the `Any` object contains type `T`
  - `as_ref<T>(self) -> Option<&T>` returns a reference to the contained type, if it is `T`
  - `as_mut<T>(self) -> Option<&mut T>` returns a mutable reference to the contained type, if it is `T`
  - `move<T>(self) -> Option<~T>` allows to get the `~T` out of an `~Any` again.
- `Any` currently uses type descriptors as a type id for comparisons, which is 
    - not reliable, as it is not guaranteed that every type has only one type descriptor.
    - But safe, as no two types share the same type descriptor.
- The implementation also a few `transmute`s, mostly to cast a `*Void` of the wrapped type into it's actual type `&T`, `&mut T` or `~T`.

# Other changes

- `std::unstable::UnsafeArc::try_unwrap` no longer uses `Either`, bringing us one step closer to removing that type.
- A few of the touched modules got their import lines sorted.
- A few stylistic cleanups here and there.

Diffstat (limited to 'src/rt/sync/rust_thread.cpp')
0 files changed, 0 insertions, 0 deletions