Commit Graph

23866 Commits

Author SHA1 Message Date
Huon Wilson
17b87d2030 syntax: remove dead @mut Visitor impl (only used in tests).
Also, move some code only uses in the tests into the test module, and
replace some needless @mut ~[] with plain ~[].
2013-10-28 22:39:08 +11:00
bors
de3d36a763 auto merge of #10083 : alexcrichton/rust/timer-port, r=pcwalton
In addition to being able to sleep the current task, timers should be able to
create ports which get notified after a period of time.

Closes #10014
2013-10-28 02:41:18 -07:00
bors
9ef23e9060 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.
2013-10-28 01:26:16 -07:00
Marvin Löbel
fa8e71a825 Allow fail messages to be caught, and introduce the Any trait
Some code cleanup, sorting of import blocks

Removed std::unstable::UnsafeArc's use of Either

Added run-fail tests for the new FailWithCause impls

Changed future_result and try to return Result<(), ~Any>.

- Internally, there is an enum of possible fail messages passend around.
- In case of linked failure or a string message, the ~Any gets
  lazyly allocated in future_results recv method.
- For that, future result now returns a wrapper around a Port.
- Moved and renamed task::TaskResult into rt::task::UnwindResult
  and made it an internal enum.
- Introduced a replacement typedef `type TaskResult = Result<(), ~Any>`.
2013-10-28 08:50:32 +01:00
bors
cb5b21eba7 auto merge of #10050 : gifnksm/rust/ratio-methods, r=pcwalton
After merging 0ada7c7, user code have not been able to access to `Ratio`'s numerator and denominator fields.
In some algorithms, it is needed to get an rational number's numerator or denominator, but keeping these fields private is necessary for guaranteeing that `Ratio` numbers are irreducible.
So, I added the getter methods `numer()` and `denom()`.

As a bonus, this commit adds utility methods relating to the ratio-integer conversion.
2013-10-27 22:41:18 -07:00
bors
9293a4127b auto merge of #9744 : DaGenix/rust/remove-crypto, r=alexcrichton
Remove the Sha1, Sha2, MD5, and MD4 algorithms. SipHash is also cryptographically secure hash function and IsaacRng is a cryptographically secure RNG - I left those alone but removed comments that implied they were suitable for cryptographic use. I thought that MD4 was used for something by the compiler, but everything still seems to work with it removed, so, I guess not.

One thing that I'm not sure about - workcache.rs and workcache_support.rs (in librustpkg) both depend on Sha1. Without Sha1, the only hash function left is SipHash, so I switched that code over to use SipHash. The output size of SipHash is only 64-bits, however - much less than 160 for Sha1. I'm not sure this is a problem. Without other cryptographic hashes in the tree, I'm not sure what else to do. I considered moved Sha1 into librustpkg, but I don't know if that makes sense.

If merged, this closes #9300.
2013-10-27 21:36:31 -07:00
bors
d664ca2635 auto merge of #10080 : brson/rust/sched_queue, r=brson
Rebase and update of #9710
2013-10-27 20:21:29 -07:00
bors
a120011827 auto merge of #10098 : alexcrichton/rust/attempts, r=alexcrichton
It was pretty much a miracle that these tests were ever passing. They would
never have passed in the single threaded case because only one sigint in the
tests is ever generated, but when run in parallel two sigints will be generated.
2013-10-27 18:41:25 -07:00
Palmer Cox
2d5cb5d99a Integrate the code in the digest and cryptoutil modules directly into the sha1 module. 2013-10-27 21:25:19 -04:00
Palmer Cox
ff9e573a67 Remove MD4. 2013-10-27 21:25:19 -04:00
Palmer Cox
ca132006a0 Remove dead code from cryptoutil.rs and remove macro_rules feature flag. 2013-10-27 21:25:19 -04:00
Palmer Cox
72a9482b3f Add a comment to Sha1 that its not suitable for cryptogrpahic uses. 2013-10-27 21:25:19 -04:00
Palmer Cox
653ee13839 Remove MD5 and Sha2. Move Sha1 and support code into librustpkg. 2013-10-27 21:25:19 -04:00
Palmer Cox
c5f10b47f3 Update workcache to no longer use Sha1. 2013-10-27 21:25:19 -04:00
Daniel Micay
dde8be6ad0 mark bounds check failures as the cold path
LLVM is unable to determine this for most cases.

http://llvm-reviews.chandlerc.com/D2034 needs to land upstream before
this is going to have an effect. It's harmless to start generating the
expect hint now.
2013-10-27 20:53:12 -04:00
Palmer Cox
2c30fcea82 Clarify that the SipHash implementation has not be validated for cryptographic purposes. 2013-10-27 19:51:19 -04:00
Tim Chevalier
0e6a575635 rustpkg: Build dependencies into the correct workspace when using --rust-path-hack
When invoked with the --rust-path-hack flag, rustpkg was correctly building
the package into the default workspace (and not into the build/ subdirectory of the
parent directory of the source directory), but not correctly putting the output
for any dependencies into the default workspace as well.

Spotted by Jack.
2013-10-27 16:31:55 -07:00
Daniel Micay
1e4986ce56 make the bottom type immediate
Before:

    define void @_ZN3bar19h9d9b965357abc043af4v0.0E({}* noalias nocapture readnone sret, { i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone)

After:

    define void @_ZN3bar19h9d9b965357abc043af4v0.0E({ i64, %tydesc*, i8*, i8*, i8 }* nocapture readnone)
2013-10-27 16:48:48 -04:00
Alex Crichton
8455ad898c Ignore a test which never completes on windows
I'm not entirely sure why this is happening, but the server task is never seeing
the second send of the client task, and this test will very reliably fail to
complete on windows.
2013-10-27 10:58:32 -07:00
bors
16b8a41531 auto merge of #10026 : luqmana/rust/mut-pat, r=pcwalton
Fixes #9792.
2013-10-27 09:51:21 -07:00
Alex Crichton
28f4f65d0c Fix a typo in a rt::io::signal test
It was pretty much a miracle that these tests were ever passing. They would
never have passed in the single threaded case because only one sigint in the
tests is ever generated, but when run in parallel two sigints will be generated.
2013-10-26 23:34:43 -07:00
Huon Wilson
436d874410 Make the documentation for std::task::spawn_sched render correctly.
Currently each line is a separate bullet point in a list: http://static.rust-lang.org/doc/master/std/task/fn.spawn_sched.html
2013-10-27 11:05:55 +11:00
Alex Crichton
651f5db462 Implement another error code found on windows.
Closes #8811
2013-10-26 16:04:05 -07:00
Joshua Yanovski
a239c0ed66 Make addl_lib_search_paths a HashSet (Closes #7718). 2013-10-26 10:46:38 -07:00
bors
950add4e49 auto merge of #10072 : brson/rust/modelines, r=thestinger
These are relics that serve no purpose.
2013-10-26 02:16:08 -07:00
bors
f1b87726b7 auto merge of #10048 : ibukanov/rust/mkdir-fix, r=brson
The patch replaces mkdir -p dir with (umask 022 && mkdir -p dir). Sadly mkdir -m 755 -p dir does not work if it creates parent directories as those parents will have umask permissions, not the one passed with -m option.   

Closes #10046
2013-10-26 01:11:11 -07:00
Alex Crichton
357ef1f69c Rewrite boxed_region/memory_region in Rust
This drops more of the old C++ runtime to rather be written in rust. A few
features were lost along the way, but hopefully not too many. The main loss is
that there are no longer backtraces associated with allocations (rust doesn't
have a way of acquiring those just yet). Other than that though, I believe that
the rest of the debugging utilities made their way over into rust.

Closes #8704
2013-10-26 01:10:39 -07:00
bors
d53159a643 auto merge of #10070 : alexcrichton/rust/fewer-missiles, r=brson
This optimizes the `home_for_io` code path by requiring fewer scheduler
operations in some situtations.

When moving to your home scheduler, this no longer forces a context switch if
you're already on the home scheduler. Instead, the homing code now simply pins
you to your current scheduler (making it so you can't be stolen away). If you're
not on your home scheduler, then we context switch away, sending you to your
home scheduler.

When the I/O operation is done, then we also no longer forcibly trigger a
context switch. Instead, the action is cased on whether the task is homed or
not. If a task does not have a home, then the task is re-flagged as not having a
home and no context switch is performed. If a task is homed to the current
scheduler, then we don't do anything, and if the task is homed to a foreign
scheduler, then it's sent along its merry way.

I verified that there are about a third as many `write` syscalls done in print
operations now. Libuv uses write to implement async handles, and the homing
before and after each I/O operation was triggering a write on these async
handles. Additionally, using the terrible benchmark of printing 10k times in a
loop, this drives the runtime from 0.6s down to 0.3s (yay!).
2013-10-26 00:06:09 -07:00
Alex Crichton
7a1d97e62c Enhance timers to create ports
In addition to being able to sleep the current task, timers should be able to
create ports which get notified after a period of time.

Closes #10014
2013-10-25 22:12:55 -07:00
bors
c5074ae646 auto merge of #10082 : brson/rust/gyp, r=huonw
The upstream repo has been offline for hours. A single point of failure is plenty.
2013-10-25 21:09:37 -07:00
Brian Anderson
b4dabd4094 Point gyp submodule toward github 2013-10-25 20:23:53 -07:00
Brian Anderson
a849c476f5 Encapsulate the lock-free mpsc queue in the MessageQueue type 2013-10-25 19:56:49 -07:00
Brian Anderson
1ce5081f4d Add links to original mpmc and mpsc implementations 2013-10-25 19:46:35 -07:00
Brian Anderson
49d9135eea Tidy 2013-10-25 18:33:05 -07:00
Jason Toffaletti
5e91ac10b6 minor 2013-10-25 18:27:46 -07:00
Jason Toffaletti
8c95f558d0 minor 2013-10-25 18:27:46 -07:00
Jason Toffaletti
1916732cfd fix bug introduced by previous clean up. more clean up. 2013-10-25 18:27:45 -07:00
Jason Toffaletti
89c91208a7 clean up 2013-10-25 18:27:45 -07:00
Jason Toffaletti
c372fa5556 add padding to prevent false sharing 2013-10-25 18:27:45 -07:00
Jason Toffaletti
5876e21225 add multi-producer multi-consumer bounded queue to use for sleeper list 2013-10-25 18:27:45 -07:00
Jason Toffaletti
bf0e6eb346 add cache line padding 2013-10-25 18:27:45 -07:00
Jason Toffaletti
c62d604531 lock-free queue for scheduler message queue 2013-10-25 18:27:45 -07:00
Brian Anderson
9a773da681 Remove ancient emacs mode lines from test cases
These are relics that serve no purpose.
2013-10-25 17:41:54 -07:00
Alex Crichton
e4c6523c65 Fire fewer homing missiles
This optimizes the `home_for_io` code path by requiring fewer scheduler
operations in some situtations.

When moving to your home scheduler, this no longer forces a context switch if
you're already on the home scheduler. Instead, the homing code now simply pins
you to your current scheduler (making it so you can't be stolen away). If you're
not on your home scheduler, then we context switch away, sending you to your
home scheduler.

When the I/O operation is done, then we also no longer forcibly trigger a
context switch. Instead, the action is cased on whether the task is homed or
not. If a task does not have a home, then the task is re-flagged as not having a
home and no context switch is performed. If a task is homed to the current
scheduler, then we don't do anything, and if the task is homed to a foreign
scheduler, then it's sent along its merry way.

I verified that there are about a third as many `write` syscalls done in print
operations now. Libuv uses write to implement async handles, and the homing
before and after each I/O operation was triggering a write on these async
handles. Additionally, using the terrible benchmark of printing 10k times in a
loop, this drives the runtime from 0.6s down to 0.3s (yay!).
2013-10-25 16:18:01 -07:00
bors
dcdcd309fb auto merge of #10067 : sanxiyn/rust/addr-of-bot, r=thestinger
Fix #5500.
2013-10-25 12:56:20 -07:00
bors
953e56052f auto merge of #10066 : sanxiyn/rust/mut-ptr-clone, r=thestinger 2013-10-25 11:46:11 -07:00
bors
baeed886aa auto merge of #10060 : alexcrichton/rust/cached-stdout, r=brson
Almost all languages provide some form of buffering of the stdout stream, and
this commit adds this feature for rust. A handle to stdout is lazily initialized
in the Task structure as a buffered owned Writer trait object. The buffer
behavior depends on where stdout is directed to. Like C, this line-buffers the
stream when the output goes to a terminal (flushes on newlines), and also like C
this uses a fixed-size buffer when output is not directed at a terminal.

We may decide the fixed-size buffering is overkill, but it certainly does reduce
write syscall counts when piping output elsewhere. This is a *huge* benefit to
any code using logging macros or the printing macros. Formatting emits calls to
`write` very frequently, and to have each of them backed by a write syscall was
very expensive.

In a local benchmark of printing 10000 lines of "what" to stdout, I got the
following timings:

  when |  terminal   |  redirected
----------|---------------|--------
before |  0.575s     |   0.525s
after  |  0.197s     |   0.013s
  C    |  0.019s     |   0.004s

I can also confirm that we're buffering the output appropriately in both
situtations. We're still far slower than C, but I believe much of that has to do
with the "homing" that all tasks due, we're still performing an order of
magnitude more write syscalls than C does.
2013-10-25 10:36:09 -07:00
Alex Crichton
e8f72c38f4 Cache and buffer stdout per-task for printing
Almost all languages provide some form of buffering of the stdout stream, and
this commit adds this feature for rust. A handle to stdout is lazily initialized
in the Task structure as a buffered owned Writer trait object. The buffer
behavior depends on where stdout is directed to. Like C, this line-buffers the
stream when the output goes to a terminal (flushes on newlines), and also like C
this uses a fixed-size buffer when output is not directed at a terminal.

We may decide the fixed-size buffering is overkill, but it certainly does reduce
write syscall counts when piping output elsewhere. This is a *huge* benefit to
any code using logging macros or the printing macros. Formatting emits calls to
`write` very frequently, and to have each of them backed by a write syscall was
very expensive.

In a local benchmark of printing 10000 lines of "what" to stdout, I got the
following timings:

  when |  terminal   |  redirected
----------------------------------
before |  0.575s     |   0.525s
after  |  0.197s     |   0.013s
  C    |  0.019s     |   0.004s

I can also confirm that we're buffering the output appropriately in both
situtations. We're still far slower than C, but I believe much of that has to do
with the "homing" that all tasks due, we're still performing an order of
magnitude more write syscalls than C does.
2013-10-25 10:31:57 -07:00
Seo Sanghyeon
f04886b6bf Allow taking address of bottom 2013-10-25 19:15:29 +09:00
Seo Sanghyeon
568576bab0 Implement Clone trait for mutable unsafe pointers 2013-10-25 18:43:55 +09:00