Commit graph

24632 commits

Author SHA1 Message Date
Alex Crichton
39dbcd7b01 rustc: Temporarily inject libgreen with librustuv
This measure is simply to allow programs to continue compiling as they once did.
In the future, this needs a more robust solution to choose how to start with
libgreen or libnative.
2013-12-24 19:59:53 -08:00
Alex Crichton
aad9fbf6b6 green: Fixing all tests from previous refactorings 2013-12-24 19:59:53 -08:00
Alex Crichton
1a6d920e3d green: Allow specifying an IoFactory for pools
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-24 19:59:53 -08:00
Alex Crichton
8be66e212b std: Implement yields on receives for channels
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-24 19:59:53 -08:00
Alex Crichton
14caf00c92 rustuv: Write homing tests with SchedPool
Use the previous commit's new scheduler pool abstraction in libgreen to write
some homing tests which force an I/O handle to be homed from one event loop to
another.
2013-12-24 19:59:53 -08:00
Alex Crichton
3893716390 Finalize the green::Pool type
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-24 19:59:53 -08:00
Alex Crichton
afd4e2ad8d rustuv: Get all tests passing again after refactor
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-24 19:59:53 -08:00
Alex Crichton
f5d9b2ca6d native: Add tests and cleanup entry points
This adds a few smoke tests associated with libnative tasks (not much code to
test here anyway), and cleans up the entry points a little bit to be a little
more like libgreen.

The I/O code doesn't need much testing because that's all tested in libstd (with
the iotest! macro).
2013-12-24 19:59:53 -08:00
Alex Crichton
018d60509c std: Get stdtest all passing again
This commit brings the library up-to-date in order to get all tests passing
again
2013-12-24 19:59:52 -08:00
Alex Crichton
d830fcc6eb make: Add all the make support for lib{native,green}
This should now begin distribution of lib{green,native} in rlib/dylib format as
well as building them as part of the normal build process.
2013-12-24 19:59:52 -08:00
Alex Crichton
780afeaf0a std: Update std::rt::thread to specify stack sizes
It's now possible to spawn an OS thread with a stack that has a specific size.
2013-12-24 19:59:52 -08:00
Alex Crichton
7554f5c58f std: Fix a bug where Local::take() didn't zero out
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-24 19:59:52 -08:00
Alex Crichton
51abdee5f1 green: Rip the bandaid off, introduce libgreen
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-24 19:59:52 -08:00
Alex Crichton
6aadc9d188 native: Introduce libnative
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-24 14:42:00 -08:00
Alex Crichton
49e5493587 std: Reimplement std::comm without the scheduler
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-24 14:42:00 -08:00
Alex Crichton
daaec28c6f std: Move management of the exit code to std::os
Previously this functionality was located in std::rt::util, but there's no real
reason for it to be located in there.
2013-12-24 14:42:00 -08:00
Alex Crichton
429313de69 rustuv: Reimplement without using std::rt::sched
This reimplements librustuv without using the interfaces provided by the
scheduler in libstd. This solely uses the new Runtime trait in order to
interface with the local task and perform the necessary scheduling operations.

The largest snag in this refactoring is reimplementing homing. The new runtime
trait exposes no concept of "homing" a task or forcibly sending a task to a
remote scheduler (there is no concept of a scheduler). In order to reimplement
homing, the transferrence of tasks is now done at the librustuv level instead of
the scheduler level. This means that all I/O loops now have a concurrent queue
which receives homing messages and requests.

This allows the entire implementation of librustuv to be only dependent on the
runtime trait, severing all dependence of librustuv on the scheduler and related
green-thread functions.

This is all in preparation of the introduction of libgreen and libnative.

At the same time, I also took the liberty of removing all glob imports from
librustuv.
2013-12-24 14:42:00 -08:00
Alex Crichton
1ca77268d9 std: Change Any::move to never consume the object
If the dynamic cast fails, this now returns the ~Any instance back to the
caller.
2013-12-24 14:42:00 -08:00
Alex Crichton
76270816d5 std: Make logging safely implemented
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-24 14:42:00 -08:00
Alex Crichton
dd19785f96 std: Handle prints with literally no context
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-24 14:42:00 -08:00
Alex Crichton
4538369566 std: Expose that LocalIo may not always be available
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-24 14:42:00 -08:00
Alex Crichton
a55c57284d std: Introduce std::sync
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-24 14:42:00 -08:00
Alex Crichton
dafb310ba1 std: Delete rt::test
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-24 14:42:00 -08:00
Alex Crichton
1815aea368 std: Introduce an unstable::stack module
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-24 14:41:59 -08:00
Alex Crichton
cab44fb076 std: Introduce a Runtime trait
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-24 14:41:59 -08:00
bors
32e730f122 auto merge of #11121 : vadimcn/rust/no-c++2, r=alexcrichton
This PR removes Rust's dependency on C++ for exception handling. Instead, it will use the unwind library API directly.

closes #10469
2013-12-24 12:46:32 -08:00
Vadim Chugunov
e3b37154b0 Stop using C++ exceptions for stack unwinding. 2013-12-24 12:13:42 -08:00
bors
b8c87fd9fe auto merge of #11130 : olsonjeffery/rust/master, r=alexcrichton
So that `Uuid` can be used as the key in a `HashMap` or in a `HashSet`, etc

The only question I have about this is: Is endianness an issue, here? If so, what's the correct way to proceed?
2013-12-24 01:56:30 -08:00
bors
e09a8e8923 auto merge of #11091 : brson/rust/cratelinkattr, r=brson
This is set to *forbid* and prints a note explaining how to fix the problem.
2013-12-24 00:41:33 -08:00
Jeff Olson
41cbbb656a extra: impl IterBytes for uuid::Uuid 2013-12-23 23:44:58 -08:00
Brian Anderson
26f1b4db11 rustc: Add a lint for the obsolete crate-level link attribute 2013-12-23 21:04:01 -08:00
bors
619c4fce89 auto merge of #11022 : spaolacci/rust/0read, r=alexcrichton
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 11:26:34 -08:00
bors
d9c06586f2 auto merge of #11120 : alexcrichton/rust/rustdoc-test, r=brson
This commit adds a `--test` flag to rustdoc to expose the ability to test code examples in doc strings. This work by using sundown's `lang` attribute to figure out how a code block should be tested. The format for this is:

```
1. ```rust
2. ```rust,ignore
3. ```rust,notest
4. ```rust,should_fail
```

Where `rust` means that rustdoc will attempt to test is, `ignore` means that it will not execute the test but it will compile it, `notest` means that rustdoc completely ignores it, and `should_fail` means that the test should fail. This commit also leverages `extra::test` for the testing harness in order to allow parallelization and whatnot.

I have fixed all existing code examples in libstd and libextra, but I have not made a pass through the crates in order to change code blocks to testable code blocks.

It may also be a questionable decision to require opting-in to a testable code block.

Finally, I kept our sugar in the doc suite to omit lines starting with `#` in documentation but still process them during tests.

Closes #2925
2013-12-23 09:16:37 -08:00
Alex Crichton
f9b231cd08 Fixing more doc tests 2013-12-23 09:10:37 -08:00
Alex Crichton
316345610a doc: Expand rustdoc's documentation for testing 2013-12-23 09:10:37 -08:00
Alex Crichton
fe8b360c9d mk: Run doc tests as part of 'make check'
Don't run doc tests during make check-fast because it involves spawning lots of
processes.
2013-12-23 09:10:37 -08:00
Alex Crichton
d882b1d4f9 extra: Fix all code examples 2013-12-23 09:10:36 -08:00
Alex Crichton
9f1739a8e1 std: Fix all code examples 2013-12-23 09:10:36 -08:00
Alex Crichton
6c9c045064 rustdoc: Add the ability to test code in comments
This adds support for the `--test` flag to rustdoc which will parse a crate,
extract all code examples in doc comments, and then run each test in the
extra::test driver.
2013-12-23 09:10:36 -08:00
Sébastien Paolacci
ee887d7078 Add tests for 0-byte read propagation.
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-23 09:35:52 +01:00
bors
f71c0dc2cd auto merge of #11069 : alexcrichton/rust/issue-11067, r=brson
Turns out libuv's build system doesn't like us telling them that the build
directory is a relative location, as it always spits out a warning about a
circular dependency being dropped. By using an absolute path, turns out the
warnings isn't spit out, who knew?

Closes #11067
2013-12-22 22:36:30 -08:00
Alex Crichton
9d59e358d9 uv: Suppress a warning by using an absolute path
Turns out libuv's build system doesn't like us telling them that the build
directory is a relative location, as it always spits out a warning about a
circular dependency being dropped. By using an absolute path, turns out the
warnings isn't spit out, who knew?

Closes #11067
2013-12-22 22:30:51 -08:00
bors
57724012ff auto merge of #11111 : alexcrichton/rust/issue-11039, r=brson
None of these primitives should be Freeze because sharing them in an Arc is a
very bad idea.

Closes #11039
2013-12-22 18:21:34 -08:00
bors
1b4bbc89b3 auto merge of #11109 : sfackler/rust/arc, r=alexcrichton
Closes #11097
2013-12-22 16:56:31 -08:00
bors
9e00272441 auto merge of #11046 : zargony/rust/dep-info, r=alexcrichton
Using --dep-info writes Makefile-compatible dependency info to a file that is by default named based on the crate source filename. This adds an optional string argument to the --dep-info option which allows to write dependency info to an arbitrary filename.

cc #10698
2013-12-22 15:06:32 -08:00
bors
0c0c492101 auto merge of #11101 : jhasse/rust/patch-msys-quickfix, r=luqmana
I had this fixed but somehow forgot to commit it in my final patch. Sorry!
2013-12-22 13:51:35 -08:00
Andreas Neuhaus
66e3fbebd9 Allow optional filename argument for --dep-info 2013-12-22 21:38:55 +01:00
Andreas Neuhaus
5d0fea1441 Use --crate-file-name to find out the library filename in dep-info test 2013-12-22 21:37:33 +01:00
bors
0478142b5f auto merge of #11096 : brson/rust/pp, r=alexcrichton 2013-12-22 12:36:35 -08:00
bors
2e4cd83a0a auto merge of #11082 : brson/rust/noat, r=alexcrichton 2013-12-22 11:21:36 -08:00