Skip to content

Commit

Permalink
Make most of std::rt private
Browse files Browse the repository at this point in the history
Previously, the entire runtime API surface was publicly exposed, but
that is neither necessary nor desirable. This commit hides most of the
module, using librustrt directly as needed. The arrangement will need to
be revisited when rustrt is pulled into std.

[breaking-change]
  • Loading branch information
aturon committed Nov 21, 2014
1 parent 40c78ab commit 6987ad2
Show file tree
Hide file tree
Showing 24 changed files with 64 additions and 81 deletions.
8 changes: 5 additions & 3 deletions src/libcollections/slice.rs
Expand Up @@ -666,6 +666,8 @@ pub mod raw {

#[cfg(test)]
mod tests {
extern crate rustrt;

use std::cell::Cell;
use std::default::Default;
use std::mem;
Expand Down Expand Up @@ -949,9 +951,9 @@ mod tests {
#[test]
fn test_swap_remove_noncopyable() {
// Tests that we don't accidentally run destructors twice.
let mut v = vec![rt::exclusive::Exclusive::new(()),
rt::exclusive::Exclusive::new(()),
rt::exclusive::Exclusive::new(())];
let mut v = vec![rustrt::exclusive::Exclusive::new(()),
rustrt::exclusive::Exclusive::new(()),
rustrt::exclusive::Exclusive::new(())];
let mut _e = v.swap_remove(0);
assert_eq!(v.len(), 2);
_e = v.swap_remove(1);
Expand Down
4 changes: 3 additions & 1 deletion src/librustrt/local.rs
Expand Up @@ -52,8 +52,10 @@ impl Local<local_ptr::Borrowed<Task>> for Task {

#[cfg(test)]
mod test {
extern crate rustrt;

use std::prelude::*;
use std::rt::thread::Thread;
use rustrt::thread::Thread;
use super::*;
use task::Task;

Expand Down
10 changes: 6 additions & 4 deletions src/librustrt/mutex.rs
Expand Up @@ -33,7 +33,7 @@
//! # Example
//!
//! ```rust
//! use std::rt::mutex::{NativeMutex, StaticNativeMutex, NATIVE_MUTEX_INIT};
//! use rustrt::mutex::{NativeMutex, StaticNativeMutex, NATIVE_MUTEX_INIT};
//!
//! // Use a statically initialized mutex
//! static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
Expand Down Expand Up @@ -108,7 +108,7 @@ impl StaticNativeMutex {
/// # Example
///
/// ```rust
/// use std::rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
/// use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
/// static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
/// unsafe {
/// let _guard = LOCK.lock();
Expand Down Expand Up @@ -225,7 +225,7 @@ impl NativeMutex {
/// # Example
///
/// ```rust
/// use std::rt::mutex::NativeMutex;
/// use rustrt::mutex::NativeMutex;
/// unsafe {
/// let mut lock = NativeMutex::new();
///
Expand Down Expand Up @@ -649,11 +649,13 @@ mod imp {

#[cfg(test)]
mod test {
extern crate rustrt;

use std::prelude::*;

use std::mem::drop;
use super::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use std::rt::thread::Thread;
use rustrt::thread::Thread;

#[test]
fn smoke_lock() {
Expand Down
4 changes: 3 additions & 1 deletion src/librustrt/task.rs
Expand Up @@ -544,6 +544,8 @@ impl Death {

#[cfg(test)]
mod test {
extern crate rustrt;

use super::*;
use std::prelude::*;
use std::task;
Expand Down Expand Up @@ -592,7 +594,7 @@ mod test {
#[test]
#[should_fail]
fn test_begin_unwind() {
use std::rt::unwind::begin_unwind;
use rustrt::unwind::begin_unwind;
begin_unwind("cause", &(file!(), line!()))
}

Expand Down
2 changes: 1 addition & 1 deletion src/libstd/dynamic_lib.rs
Expand Up @@ -229,7 +229,7 @@ pub mod dl {
}

pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, String> {
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
unsafe {
// dlerror isn't thread safe, so we need to lock around this entire
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/failure.rs
Expand Up @@ -18,7 +18,7 @@ use kinds::Send;
use option::{Some, None};
use result::Ok;
use rt::backtrace;
use rt::{Stderr, Stdio};
use rustrt::{Stderr, Stdio};
use rustrt::local::Local;
use rustrt::task::Task;
use str::Str;
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/io/stdio.rs
Expand Up @@ -40,9 +40,9 @@ use option::{Option, Some, None};
use boxed::Box;
use sys::{fs, tty};
use result::{Ok, Err};
use rt;
use rt::local::Local;
use rt::task::Task;
use rustrt;
use rustrt::local::Local;
use rustrt::task::Task;
use slice::SlicePrelude;
use str::StrPrelude;
use uint;
Expand Down Expand Up @@ -207,7 +207,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()>) {
local_stdout.replace(Some(my_stdout));
result
} else {
let mut io = rt::Stdout;
let mut io = rustrt::Stdout;
f(&mut io as &mut Writer)
};
match result {
Expand Down
3 changes: 1 addition & 2 deletions src/libstd/lib.rs
Expand Up @@ -162,7 +162,6 @@ pub use core::result;
pub use core::option;

pub use alloc::boxed;

pub use alloc::rc;

pub use core_collections::slice;
Expand Down Expand Up @@ -247,7 +246,7 @@ pub mod fmt;

#[path = "sys/common/mod.rs"] mod sys_common;

mod rt;
pub mod rt;
mod failure;

// A curious inner-module that's not exported that contains the binding
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/os.rs
Expand Up @@ -208,7 +208,7 @@ Accessing environment variables is not generally threadsafe.
Serialize access through a global lock.
*/
fn with_env_lock<T>(f: || -> T) -> T {
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};

static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;

Expand Down Expand Up @@ -1039,9 +1039,9 @@ fn real_args_as_bytes() -> Vec<Vec<u8>> {
target_os = "freebsd",
target_os = "dragonfly"))]
fn real_args_as_bytes() -> Vec<Vec<u8>> {
use rt;
use rustrt;

match rt::args::clone() {
match rustrt::args::clone() {
Some(args) => args,
None => panic!("process arguments not initialized")
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/rt/backtrace.rs
Expand Up @@ -238,7 +238,7 @@ mod imp {
use mem;
use option::{Some, None, Option};
use result::{Ok, Err};
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};

/// As always - iOS on arm uses SjLj exceptions and
/// _Unwind_Backtrace is even not available there. Still,
Expand Down Expand Up @@ -667,7 +667,7 @@ mod imp {
use option::{Some, None};
use path::Path;
use result::{Ok, Err};
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
use slice::SlicePrelude;
use str::StrPrelude;
use dynamic_lib::DynamicLibrary;
Expand Down
14 changes: 6 additions & 8 deletions src/libstd/rt/mod.rs
Expand Up @@ -66,9 +66,7 @@ pub use self::util::{default_sched_threads, min_stack, running_on_valgrind};
// Reexport functionality from librustrt and other crates underneath the
// standard library which work together to create the entire runtime.
pub use alloc::heap;
pub use rustrt::{task, local, mutex, exclusive, stack, args, thread};
pub use rustrt::{Stdio, Stdout, Stderr, begin_unwind, begin_unwind_fmt};
pub use rustrt::{at_exit, unwind, DEFAULT_ERROR_CODE};
pub use rustrt::{begin_unwind, begin_unwind_fmt, at_exit};

// Simple backtrace functionality (to print on panic)
pub mod backtrace;
Expand All @@ -84,7 +82,7 @@ mod util;
#[allow(experimental)]
pub fn init(argc: int, argv: *const *const u8) {
rustrt::init(argc, argv);
unsafe { unwind::register(failure::on_fail); }
unsafe { rustrt::unwind::register(failure::on_fail); }
}

#[cfg(any(windows, android))]
Expand Down Expand Up @@ -147,19 +145,19 @@ pub fn start(argc: int, argv: *const *const u8, main: proc()) -> int {
init(argc, argv);
let mut exit_code = None;
let mut main = Some(main);
let mut task = Task::new(Some((my_stack_bottom, my_stack_top)),
Some(rt::thread::main_guard_page()));
let mut task = box Task::new(Some((my_stack_bottom, my_stack_top)),
Some(rustrt::thread::main_guard_page()));
task.name = Some(str::Slice("<main>"));
drop(task.run(|| {
unsafe {
rt::stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top);
rustrt::stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top);
}
(main.take().unwrap())();
exit_code = Some(os::get_exit_status());
}).destroy());
unsafe { rt::cleanup(); }
// If the exit code wasn't set, then the task block must have panicked.
return exit_code.unwrap_or(rt::DEFAULT_ERROR_CODE);
return exit_code.unwrap_or(rustrt::DEFAULT_ERROR_CODE);
}

/// One-time runtime cleanup.
Expand Down
6 changes: 3 additions & 3 deletions src/libstd/sys/common/helper_thread.rs
Expand Up @@ -22,8 +22,8 @@

use mem;
use rustrt::bookkeeping;
use rt::mutex::StaticNativeMutex;
use rt;
use rustrt::mutex::StaticNativeMutex;
use rustrt;
use cell::UnsafeCell;
use sys::helper_signal;
use prelude::*;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<M: Send> Helper<M> {
self.lock.lock().signal()
});

rt::at_exit(proc() { self.shutdown() });
rustrt::at_exit(proc() { self.shutdown() });
*self.initialized.get() = true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/common/net.rs
Expand Up @@ -16,7 +16,7 @@ use libc::{mod, c_char, c_int};
use mem;
use num::Int;
use ptr::{mod, null, null_mut};
use rt::mutex;
use rustrt::mutex;
use io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr};
use io::net::addrinfo;
use io::{IoResult, IoError};
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/mod.rs
Expand Up @@ -25,7 +25,7 @@ use sys_common::mkerr_libc;

macro_rules! helper_init( (static $name:ident: Helper<$m:ty>) => (
static $name: Helper<$m> = Helper {
lock: ::rt::mutex::NATIVE_MUTEX_INIT,
lock: ::rustrt::mutex::NATIVE_MUTEX_INIT,
chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
signal: ::cell::UnsafeCell { value: 0 },
initialized: ::cell::UnsafeCell { value: false },
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/unix/pipe.rs
Expand Up @@ -12,7 +12,7 @@ use alloc::arc::Arc;
use libc;
use c_str::CString;
use mem;
use rt::mutex;
use rustrt::mutex;
use sync::atomic;
use io::{mod, IoResult, IoError};
use prelude::*;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/windows/mod.rs
Expand Up @@ -26,7 +26,7 @@ use sync::{Once, ONCE_INIT};

macro_rules! helper_init( (static $name:ident: Helper<$m:ty>) => (
static $name: Helper<$m> = Helper {
lock: ::rt::mutex::NATIVE_MUTEX_INIT,
lock: ::rustrt::mutex::NATIVE_MUTEX_INIT,
chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
signal: ::cell::UnsafeCell { value: 0 },
initialized: ::cell::UnsafeCell { value: false },
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/windows/pipe.rs
Expand Up @@ -90,7 +90,7 @@ use c_str::CString;
use mem;
use ptr;
use sync::atomic;
use rt::mutex;
use rustrt::mutex;
use io::{mod, IoError, IoResult};
use prelude::*;

Expand Down
16 changes: 8 additions & 8 deletions src/libstd/task.rs
Expand Up @@ -50,9 +50,9 @@ use kinds::{Send, marker};
use option::{None, Some, Option};
use boxed::Box;
use result::Result;
use rt::local::Local;
use rt::task;
use rt::task::Task;
use rustrt::local::Local;
use rustrt::task;
use rustrt::task::Task;
use str::{Str, SendStr, IntoMaybeOwned};
use string::{String, ToString};
use sync::Future;
Expand Down Expand Up @@ -142,13 +142,13 @@ impl TaskBuilder {
stack_size: stack_size,
};
if stdout.is_some() || stderr.is_some() {
spawner.spawn(opts, proc() {
Task::spawn(opts, proc() {
let _ = stdout.map(stdio::set_stdout);
let _ = stderr.map(stdio::set_stderr);
f();
})
} else {
spawner.spawn(opts, f)
Task::spawn(opts, f)
}
}

Expand Down Expand Up @@ -237,7 +237,7 @@ pub fn try_future<T:Send>(f: proc():Send -> T) -> Future<Result<T, Box<Any + Sen
/// Read the name of the current task.
#[stable]
pub fn name() -> Option<String> {
use rt::task::Task;
use rustrt::task::Task;

let task = Local::borrow(None::<Task>);
match task.name {
Expand All @@ -249,15 +249,15 @@ pub fn name() -> Option<String> {
/// Yield control to the task scheduler.
#[unstable = "Name will change."]
pub fn deschedule() {
use rt::task::Task;
use rustrt::task::Task;
Task::yield_now();
}

/// True if the running task is currently panicking (e.g. will return `true` inside a
/// destructor that is run while unwinding the stack after a call to `panic!()`).
#[unstable = "May move to a different module."]
pub fn failing() -> bool {
use rt::task::Task;
use rustrt::task::Task;
Local::borrow(None::<Task>).unwinder.unwinding()
}

Expand Down
8 changes: 5 additions & 3 deletions src/libsync/comm/mod.rs
Expand Up @@ -336,6 +336,8 @@ macro_rules! test (
mod $name {
#![allow(unused_imports)]

extern crate rustrt;

use std::prelude::*;

use comm::*;
Expand Down Expand Up @@ -1512,7 +1514,7 @@ mod test {
})

test!(fn sends_off_the_runtime() {
use std::rt::thread::Thread;
use rustrt::thread::Thread;

let (tx, rx) = channel();
let t = Thread::start(proc() {
Expand All @@ -1527,7 +1529,7 @@ mod test {
})

test!(fn try_recvs_off_the_runtime() {
use std::rt::thread::Thread;
use rustrt::thread::Thread;

let (tx, rx) = channel();
let (cdone, pdone) = channel();
Expand Down Expand Up @@ -1977,7 +1979,7 @@ mod sync_tests {
})

test!(fn try_recvs_off_the_runtime() {
use std::rt::thread::Thread;
use rustrt::thread::Thread;

let (tx, rx) = sync_channel::<()>(0);
let (cdone, pdone) = channel();
Expand Down
2 changes: 1 addition & 1 deletion src/libsync/deque.rs
Expand Up @@ -414,7 +414,7 @@ mod tests {
use super::{Data, BufferPool, Abort, Empty, Worker, Stealer};

use std::mem;
use std::rt::thread::Thread;
use rustrt::thread::Thread;
use std::rand;
use std::rand::Rng;
use atomic::{AtomicBool, INIT_ATOMIC_BOOL, SeqCst,
Expand Down

0 comments on commit 6987ad2

Please sign in to comment.