summary refs log tree commit diff
path: root/src/libstd
AgeCommit message (Collapse)AuthorLines
2013-12-27auto merge of #11098 : erickt/rust/collect, r=alexcrichtonbors-31/+98
This patch changes `result::collect` (and adds a new `option::collect`) from creating a `~[T]` to take an `Iterator`. This makes the function much more flexible, and may replace the need for #10989. This patch is a little more complicated than it needs to be because of #11084. Once that is fixed we can replace the `CollectIterator` with a `Scan` iterator. It also fixes a test warning.
2013-12-27Renamed ClonableIterator to CloneableIteratorAlexandros Tasos-5/+5
2013-12-27std: uniform modules titles for docLuca Bruno-42/+50
This commit uniforms the short title of modules provided by libstd, in order to make their roles more explicit when glancing at the index. Signed-off-by: Luca Bruno <lucab@debian.org>
2013-12-26libstd: Make a temporary separate `stage0` implementation for `Cell` toPatrick Walton-0/+27
avoid a crash in later stages
2013-12-26std: result::collect to take an iterator, add option::collectErick Tryzelaar-29/+97
2013-12-26std: remove some test warningsErick Tryzelaar-2/+1
2013-12-26Register new snapshotsAlex Crichton-27/+0
2013-12-27std::hashmap: add an example to mangle.Huon Wilson-0/+37
2013-12-26std::rand: remove the `fn main()` from the examples.Huon Wilson-174/+113
2013-12-26auto merge of #11127 : huonw/rust/vec-docs, r=alexcrichtonbors-27/+115
2013-12-25Test fixes and rebase conflictsAlex Crichton-109/+144
* vec::raw::to_ptr is gone * Pausible => Pausable * Removing @ * Calling the main task "<main>" * Removing unused imports * Removing unused mut * Bringing some libextra tests up to date * Allowing compiletest to work at stage0 * Fixing the bootstrap-from-c rmake tests * assert => rtassert in a few cases * printing to stderr instead of stdout in fail!()
2013-12-24green: Move a scheduler test inside libgreenAlex Crichton-60/+0
This test also had a race condition in using the cvar/lock, so I fixed that up as well. The race originated from one half trying to destroy the lock when another half was using it.
2013-12-24std: Remove must deferred sending functionsAlex Crichton-34/+5
These functions are all unnecessary now, and they only have meaning in the M:N context. Removing these functions uncovered a bug in the librustuv timer bindings, but it was fairly easy to cover (and the test is already committed). These cannot be completely removed just yet due to their usage in the WaitQueue of extra::sync, and until the mutex in libextra is rewritten it will not be possible to remove the deferred sends for channels.
2013-12-24rustuv: Remove the id() function from IoFactoryAlex Crichton-2/+0
The only user of this was the homing code in librustuv, and it just manually does the cast from a pointer to a uint now.
2013-12-24std: Stop reexporting the contents of 'mod consts'Alex Crichton-3/+1
This prevents usage of the win32 utf-16 helper functions from outside of libstd. Closes #9053
2013-12-24native: Protect against spurious wakeups on cvarsAlex Crichton-1/+1
This is a very real problem with cvars on normal systems, and all of channels will not work if spurious wakeups are accepted. This problem is just solved with a synchronized flag (accessed in the cvar's lock) to see whether a signal() actually happened or whether it's spurious.
2013-12-24green: Properly wait for main before shutdownAlex Crichton-12/+15
There was a race in the code previously where schedulers would *immediately* shut down after spawning the main task (because the global task count would still be 0). This fixes the logic by blocking the sched pool task in receving on a port instead of spawning a task into the pool to receive on a port. The modifications necessary were to have a "simple task" running by the time the code is executing, but this is a simple enough thing to implement and I forsee this being necessary to have implemented in the future anyway.
2013-12-24Test fixes and rebase problemsAlex Crichton-3/+96
Note that this removes a number of run-pass tests which are exercising behavior of the old runtime. This functionality no longer exists and is thoroughly tested inside of libgreen and libnative. There isn't really the notion of "starting the runtime" any more. The major notion now is "bootstrapping the initial task".
2013-12-24green: Allow specifying an IoFactory for poolsAlex Crichton-1/+1
This allows creation of different sched pools with different io factories. Namely, this will be used to test the basic I/O loop in the green crate. This can also be used to override the global default.
2013-12-24std: Implement yields on receives for channelsAlex Crichton-5/+20
This will prevent a deadlock when a task spins in a try_recv when using channel communication routines is a clear location for a M:N scheduling to happen.
2013-12-24Finalize the green::Pool typeAlex Crichton-16/+35
The scheduler pool now has a much more simplified interface. There is now a clear distinction between creating the pool and then interacting the pool. When a pool is created, all schedulers are not active, and only later if a spawn is done does activity occur. There are four operations that you can do on a pool: 1. Create a new pool. The only argument to this function is the configuration for the scheduler pool. Currently the only configuration parameter is the number of threads to initially spawn. 2. Spawn a task into this pool. This takes a procedure and task configuration options and spawns a new task into the pool of schedulers. 3. Spawn a new scheduler into the pool. This will return a handle on which to communicate with the scheduler in order to do something like a pinned task. 4. Shut down the scheduler pool. This will consume the scheduler pool, request all of the schedulers to shut down, and then wait on all the scheduler threads. Currently this will block the invoking OS thread, but I plan on making 'Thread::join' not a thread-blocking call. These operations can be used to encode all current usage of M:N schedulers, as well as providing a simple interface through which a pool can be modified. There is currently no way to remove a scheduler from a pool of scheduler, as there's no way to guarantee that a scheduler has exited. This may be added in the future, however (as necessary).
2013-12-24rustuv: Get all tests passing again after refactorAlex Crichton-3/+2
All tests except for the homing tests are now working again with the librustuv/libgreen refactoring. The homing-related tests are currently commented out and now placed in the rustuv::homing module. I plan on refactoring scheduler pool spawning in order to enable more homing tests in a future commit.
2013-12-24std: Get stdtest all passing againAlex Crichton-584/+436
This commit brings the library up-to-date in order to get all tests passing again
2013-12-24std: Update std::rt::thread to specify stack sizesAlex Crichton-8/+16
It's now possible to spawn an OS thread with a stack that has a specific size.
2013-12-24std: Fix a bug where Local::take() didn't zero outAlex Crichton-1/+3
In the compiled version of local_ptr (that with #[thread_local]), the take() funciton didn't zero-out the previous pointer, allowing for multiple takes (with fewer runtime assertions being tripped).
2013-12-24green: Rip the bandaid off, introduce libgreenAlex Crichton-3765/+350
This extracts everything related to green scheduling from libstd and introduces a new libgreen crate. This mostly involves deleting most of std::rt and moving it to libgreen. Along with the movement of code, this commit rearchitects many functions in the scheduler in order to adapt to the fact that Local::take now *only* works on a Task, not a scheduler. This mostly just involved threading the current green task through in a few locations, but there were one or two spots where things got hairy. There are a few repercussions of this commit: * tube/rc have been removed (the runtime implementation of rc) * There is no longer a "single threaded" spawning mode for tasks. This is now encompassed by 1:1 scheduling + communication. Convenience methods have been introduced that are specific to libgreen to assist in the spawning of pools of schedulers.
2013-12-24native: Introduce libnativeAlex Crichton-1852/+0
This commit introduces a new crate called "native" which will be the crate that implements the 1:1 runtime of rust. This currently entails having an implementation of std::rt::Runtime inside of libnative as well as moving all of the native I/O implementations to libnative. The current snag is that the start lang item must currently be defined in libnative in order to start running, but this will change in the future. Cool fact about this crate, there are no extra features that are enabled. Note that this commit does not include any makefile support necessary for building libnative, that's all coming in a later commit.
2013-12-24std: Reimplement std::comm without the schedulerAlex Crichton-362/+40
Like the librustuv refactoring, this refactors std::comm to sever all ties with the scheduler. This means that the entire `comm::imp` module can be deleted in favor of implementations outside of libstd.
2013-12-24std: Move management of the exit code to std::osAlex Crichton-5/+15
Previously this functionality was located in std::rt::util, but there's no real reason for it to be located in there.
2013-12-24std: Change Any::move to never consume the objectAlex Crichton-9/+10
If the dynamic cast fails, this now returns the ~Any instance back to the caller.
2013-12-24std: Make logging safely implementedAlex Crichton-21/+11
This commit fixes the logging function to be safely implemented, as well as forcibly requiring a task to be present to use logging macros. This is safely implemented by transferring ownership of the logger from the task to the local stack frame in order to perform the print. This means that if a logger does more logging while logging a new one will be initialized and then will get overwritten once the initial logging function returns. Without a scheme such as this, it is possible to unsafely alias two loggers by logging twice (unsafely borrows from the task twice).
2013-12-24std: Handle prints with literally no contextAlex Crichton-4/+25
Printing is an incredibly useful debugging utility, and it's not much help if your debugging prints just trigger an obscure abort when you need them most. In order to handle this case, forcibly fall back to a libc::write implementation of printing whenever a local task is not available. Note that this is *not* a 1:1 fallback. All 1:1 rust tasks will still have a local Task that it can go through (and stdio will be created through the local IO factory), this is only a fallback for "no context" rust code (such as that setting up the context).
2013-12-24std: Expose that LocalIo may not always be availableAlex Crichton-176/+118
It is not the case that all programs will always be able to acquire an instance of the LocalIo borrow, so this commit exposes this limitation by returning Option<LocalIo> from LocalIo::borrow(). At the same time, a helper method LocalIo::maybe_raise() has been added in order to encapsulate the functionality of raising on io_error if there is on local I/O available.
2013-12-24std: Introduce std::syncAlex Crichton-511/+283
For now, this moves the following modules to std::sync * UnsafeArc (also removed unwrap method) * mpsc_queue * spsc_queue * atomics * mpmc_bounded_queue * deque We may want to remove some of the queues, but for now this moves things out of std::rt into std::sync
2013-12-24std: Delete rt::testAlex Crichton-1030/+583
This module contains many M:N specific concepts. This will no longer be available with libgreen, and most functions aren't really that necessary today anyway. New testing primitives will be introduced as they become available for 1:1 and M:N. A new io::test module is introduced with the new ip4/ip6 address helpers to continue usage in io tests.
2013-12-24std: Introduce an unstable::stack moduleAlex Crichton-2/+276
This module will be used to manage the OS-specific TLS registers used to specify the bounds of the current rust stack (useful in 1:1 and M:N)
2013-12-24std: Introduce a Runtime traitAlex Crichton-269/+25
This trait is used to abstract the differences between 1:1 and M:N scheduling and is the sole dispatch point for the differences between these two scheduling modes. This, and the following series of commits, is not intended to compile. Only after the entire transition is complete are programs expected to compile.
2013-12-25std::vec: clarify & examplify more docs.Huon Wilson-16/+79
2013-12-25std::vec: correct .sort()'s doc-string and add someHuon Wilson-11/+36
examples/clarification to others.
2013-12-24Stop using C++ exceptions for stack unwinding.Vadim Chugunov-70/+286
2013-12-23auto merge of #11022 : spaolacci/rust/0read, r=alexcrichtonbors-3/+31
Could prevent callers from catching the situation and lead to e.g early iterator terminations (cf. `Reader::read_byte`) since `None` is only to be returned only on EOF.
2013-12-23[std::ascii] Add .to_ascii_opt() and .into_ascii_opt() returning OptionSimon Sapin-36/+70
… instead of failing. Make them default methods on the trait, and also make .to_ascii() a default method while we’re at it. Conflicts: src/libstd/ascii.rs
2013-12-23Fixing more doc testsAlex Crichton-4/+10
2013-12-23std: Fix all code examplesAlex Crichton-90/+147
2013-12-23Add tests for 0-byte read propagation.Sébastien Paolacci-0/+28
The two `Some(0)' used to be `None' before the patch, a zero-byte long read exhausting a reader (and thereafter) still produce a `None'.
2013-12-22auto merge of #11111 : alexcrichton/rust/issue-11039, r=brsonbors-0/+4
None of these primitives should be Freeze because sharing them in an Arc is a very bad idea. Closes #11039
2013-12-22auto merge of #11082 : brson/rust/noat, r=alexcrichtonbors-76/+89
2013-12-22auto merge of #11064 : huonw/rust/vec-sort, r=alexcrichtonbors-2/+297
This uses quite a bit of unsafe code for speed and failure safety, and allocates `2*n` temporary storage. [Performance](https://gist.github.com/huonw/5547f2478380288a28c2): | n | new | priority_queue | quick3 | |-------:|---------:|---------------:|---------:| | 5 | 200 | 155 | 106 | | 100 | 6490 | 8750 | 5810 | | 10000 | 1300000 | 1790000 | 1060000 | | 100000 | 16700000 | 23600000 | 12700000 | | sorted | 520000 | 1380000 | 53900000 | | trend | 1310000 | 1690000 | 1100000 | (The times are in nanoseconds, having subtracted the set-up time (i.e. the `just_generate` bench target).) I imagine that there is still significant room for improvement, particularly because both priority_queue and quick3 are doing a static call via `Ord` or `TotalOrd` for the comparisons, while this is using a (boxed) closure. Also, this code does not `clone`, unlike `quick_sort3`; and is stable, unlike both of the others.
2013-12-22std::vec: make the sorting closure use `Ordering` rather than just beingHuon Wilson-55/+34
(implicitly) less_eq.
2013-12-21Guarantee comm primitives are not FreezeAlex Crichton-0/+4
None of these primitives should be Freeze because sharing them in an Arc is a very bad idea. Closes #11039