Skip to content

Remove the crate map #13117

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 3 commits into from
Mar 26, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ pub mod common;
pub mod errors;

#[start]
fn start(argc: int, argv: **u8) -> int { green::start(argc, argv, main) }
fn start(argc: int, argv: **u8) -> int {
green::start(argc, argv, rustuv::event_loop, main)
}

pub fn main() {
let args = os::args();
Expand Down
32 changes: 27 additions & 5 deletions src/doc/guide-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,27 +223,49 @@ Having a default decision made in the compiler is done out of necessity and
convenience. The compiler's decision of runtime to link to is *not* an
endorsement of one over the other. As always, this decision can be overridden.

For example, this program will be linked to "the default runtime"
For example, this program will be linked to "the default runtime". The current
default runtime is to use libnative.

~~~{.rust}
fn main() {}
~~~

Whereas this program explicitly opts into using a particular runtime
### Force booting with libgreen

In this example, the `main` function will be booted with I/O support powered by
libuv. This is done by linking to the `rustuv` crate and specifying the
`rustuv::event_loop` function as the event loop factory.

To create a pool of green tasks which have no I/O support, you may shed the
`rustuv` dependency and use the `green::basic::event_loop` function instead of
`rustuv::event_loop`. All tasks will have no I/O support, but they will still be
able to deschedule/reschedule (use channels, locks, etc).

~~~{.rust}
extern crate green;
extern crate rustuv;

#[start]
fn start(argc: int, argv: **u8) -> int {
green::start(argc, argv, main)
green::start(argc, argv, rustuv::event_loop, main)
}

fn main() {}
~~~

Both libgreen/libnative provide a top-level `start` function which is used to
boot an initial Rust task in that specified runtime.
### Force booting with libnative

This program's `main` function will always be booted with libnative, running
inside of an OS thread.

~~~{.rust}
extern crate native;

#[start]
fn start(argc: int, argv: **u8) -> int { native::start(argc, argv, main) }

fn main() {}
~~~

# Finding the runtime

Expand Down
4 changes: 2 additions & 2 deletions src/libgreen/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ mod test {
fn pool() -> SchedPool {
SchedPool::new(PoolConfig {
threads: 1,
event_loop_factory: Some(basic::event_loop),
event_loop_factory: basic::event_loop,
})
}

Expand Down Expand Up @@ -267,7 +267,7 @@ mod test {
fn multi_thread() {
let mut pool = SchedPool::new(PoolConfig {
threads: 2,
event_loop_factory: Some(basic::event_loop),
event_loop_factory: basic::event_loop,
});

for _ in range(0, 20) {
Expand Down
69 changes: 33 additions & 36 deletions src/libgreen/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,34 @@
//! extern crate green;
//!
//! #[start]
//! fn start(argc: int, argv: **u8) -> int { green::start(argc, argv, main) }
//! fn start(argc: int, argv: **u8) -> int {
//! green::start(argc, argv, green::basic::event_loop, main)
//! }
//!
//! fn main() {
//! // this code is running in a pool of schedulers
//! }
//! ```
//!
//! > **Note**: This `main` funciton in this example does *not* have I/O
//! > support. The basic event loop does not provide any support
//!
//! # Starting with I/O support in libgreen
//!
//! ```rust
//! extern crate green;
//! extern crate rustuv;
//!
//! #[start]
//! fn start(argc: int, argv: **u8) -> int {
//! green::start(argc, argv, rustuv::event_loop, main)
//! }
//!
//! fn main() {
//! // this code is running in a pool of schedulers all powered by libuv
//! }
//! ```
//!
//! # Using a scheduler pool
//!
//! ```rust
Expand Down Expand Up @@ -176,11 +197,11 @@
#[allow(visible_private_types)];

#[cfg(test)] #[phase(syntax, link)] extern crate log;
#[cfg(test)] extern crate rustuv;
extern crate rand;

use std::mem::replace;
use std::os;
use std::rt::crate_map;
use std::rt::rtio;
use std::rt::thread::Thread;
use std::rt;
Expand All @@ -207,16 +228,6 @@ pub mod sleeper_list;
pub mod stack;
pub mod task;

#[lang = "start"]
#[cfg(not(test), stage0)]
pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
use std::cast;
start(argc, argv, proc() {
let main: extern "Rust" fn() = unsafe { cast::transmute(main) };
main();
})
}

/// Set up a default runtime configuration, given compiler-supplied arguments.
///
/// This function will block until the entire pool of M:N schedulers have
Expand All @@ -235,12 +246,14 @@ pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
///
/// The return value is used as the process return code. 0 on success, 101 on
/// error.
pub fn start(argc: int, argv: **u8, main: proc()) -> int {
pub fn start(argc: int, argv: **u8,
event_loop_factory: fn() -> ~rtio::EventLoop,
main: proc()) -> int {
rt::init(argc, argv);
let mut main = Some(main);
let mut ret = None;
simple::task().run(|| {
ret = Some(run(main.take_unwrap()));
ret = Some(run(event_loop_factory, main.take_unwrap()));
});
// unsafe is ok b/c we're sure that the runtime is gone
unsafe { rt::cleanup() }
Expand All @@ -255,10 +268,12 @@ pub fn start(argc: int, argv: **u8, main: proc()) -> int {
///
/// This function will not return until all schedulers in the associated pool
/// have returned.
pub fn run(main: proc()) -> int {
pub fn run(event_loop_factory: fn() -> ~rtio::EventLoop, main: proc()) -> int {
// Create a scheduler pool and spawn the main task into this pool. We will
// get notified over a channel when the main task exits.
let mut pool = SchedPool::new(PoolConfig::new());
let mut cfg = PoolConfig::new();
cfg.event_loop_factory = event_loop_factory;
let mut pool = SchedPool::new(cfg);
let (tx, rx) = channel();
let mut opts = TaskOpts::new();
opts.notify_chan = Some(tx);
Expand All @@ -283,7 +298,7 @@ pub struct PoolConfig {
threads: uint,
/// A factory function used to create new event loops. If this is not
/// specified then the default event loop factory is used.
event_loop_factory: Option<fn() -> ~rtio::EventLoop>,
event_loop_factory: fn() -> ~rtio::EventLoop,
}

impl PoolConfig {
Expand All @@ -292,7 +307,7 @@ impl PoolConfig {
pub fn new() -> PoolConfig {
PoolConfig {
threads: rt::default_sched_threads(),
event_loop_factory: None,
event_loop_factory: basic::event_loop,
}
}
}
Expand Down Expand Up @@ -334,7 +349,6 @@ impl SchedPool {
threads: nscheds,
event_loop_factory: factory
} = config;
let factory = factory.unwrap_or(default_event_loop_factory());
assert!(nscheds > 0);

// The pool of schedulers that will be returned from this function
Expand Down Expand Up @@ -503,20 +517,3 @@ impl Drop for SchedPool {
}
}
}

fn default_event_loop_factory() -> fn() -> ~rtio::EventLoop {
match crate_map::get_crate_map() {
None => {}
Some(map) => {
match map.event_loop_factory {
None => {}
Some(factory) => return factory
}
}
}

// If the crate map didn't specify a factory to create an event loop, then
// instead just use a basic event loop missing all I/O services to at least
// get the scheduler running.
return basic::event_loop;
}
8 changes: 5 additions & 3 deletions src/libgreen/sched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,8 @@ fn new_sched_rng() -> XorShiftRng {

#[cfg(test)]
mod test {
use rustuv;

use std::comm;
use std::task::TaskOpts;
use std::rt::Runtime;
Expand All @@ -1017,7 +1019,7 @@ mod test {
fn pool() -> SchedPool {
SchedPool::new(PoolConfig {
threads: 1,
event_loop_factory: Some(basic::event_loop),
event_loop_factory: basic::event_loop,
})
}

Expand Down Expand Up @@ -1262,7 +1264,7 @@ mod test {

let mut pool = SchedPool::new(PoolConfig {
threads: 2,
event_loop_factory: None,
event_loop_factory: rustuv::event_loop,
});

// This is a regression test that when there are no schedulable tasks in
Expand Down Expand Up @@ -1413,7 +1415,7 @@ mod test {
fn dont_starve_1() {
let mut pool = SchedPool::new(PoolConfig {
threads: 2, // this must be > 1
event_loop_factory: Some(basic::event_loop),
event_loop_factory: basic::event_loop,
});
pool.spawn(TaskOpts::new(), proc() {
let (tx, rx) = channel();
Expand Down
2 changes: 1 addition & 1 deletion src/libgreen/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,7 @@ mod tests {
fn spawn_opts(opts: TaskOpts, f: proc()) {
let mut pool = SchedPool::new(PoolConfig {
threads: 1,
event_loop_factory: None,
event_loop_factory: ::rustuv::event_loop,
});
pool.spawn(opts, f);
pool.shutdown();
Expand Down
2 changes: 1 addition & 1 deletion src/libnative/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ static OS_DEFAULT_STACK_ESTIMATE: uint = 1 << 20;
static OS_DEFAULT_STACK_ESTIMATE: uint = 2 * (1 << 20);

#[lang = "start"]
#[cfg(not(test), not(stage0))]
#[cfg(not(test))]
pub fn lang_start(main: *u8, argc: int, argv: **u8) -> int {
use std::cast;
start(argc, argv, proc() {
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,6 @@ cgoptions!(
"don't run LLVM's SLP vectorization pass"),
soft_float: bool = (false, parse_bool,
"generate software floating point library calls"),
gen_crate_map: bool = (false, parse_bool,
"force generation of a toplevel crate map"),
prefer_dynamic: bool = (false, parse_bool,
"prefer dynamic linking to static linking"),
no_integrated_as: bool = (false, parse_bool,
Expand Down
2 changes: 0 additions & 2 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ lets_do_this! {
TyVisitorTraitLangItem, "ty_visitor", ty_visitor;
OpaqueStructLangItem, "opaque", opaque;

EventLoopFactoryLangItem, "event_loop_factory", event_loop_factory;

TypeIdLangItem, "type_id", type_id;

EhPersonalityLangItem, "eh_personality", eh_personality_fn;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ static other_attrs: &'static [&'static str] = &[
"thread_local", // for statics
"allow", "deny", "forbid", "warn", // lint options
"deprecated", "experimental", "unstable", "stable", "locked", "frozen", //item stability
"crate_map", "cfg", "doc", "export_name", "link_section",
"cfg", "doc", "export_name", "link_section",
"no_mangle", "static_assert", "unsafe_no_drop_flag", "packed",
"simd", "repr", "deriving", "unsafe_destructor", "link", "phase",
"macro_export", "must_use", "automatically_derived",
Expand Down
Loading