Skip to content

Commit 6987ad2

Browse files
committed
Make most of std::rt private
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]
1 parent 40c78ab commit 6987ad2

File tree

24 files changed

+64
-81
lines changed

24 files changed

+64
-81
lines changed

src/libcollections/slice.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,8 @@ pub mod raw {
666666

667667
#[cfg(test)]
668668
mod tests {
669+
extern crate rustrt;
670+
669671
use std::cell::Cell;
670672
use std::default::Default;
671673
use std::mem;
@@ -949,9 +951,9 @@ mod tests {
949951
#[test]
950952
fn test_swap_remove_noncopyable() {
951953
// Tests that we don't accidentally run destructors twice.
952-
let mut v = vec![rt::exclusive::Exclusive::new(()),
953-
rt::exclusive::Exclusive::new(()),
954-
rt::exclusive::Exclusive::new(())];
954+
let mut v = vec![rustrt::exclusive::Exclusive::new(()),
955+
rustrt::exclusive::Exclusive::new(()),
956+
rustrt::exclusive::Exclusive::new(())];
955957
let mut _e = v.swap_remove(0);
956958
assert_eq!(v.len(), 2);
957959
_e = v.swap_remove(1);

src/librustrt/local.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ impl Local<local_ptr::Borrowed<Task>> for Task {
5252

5353
#[cfg(test)]
5454
mod test {
55+
extern crate rustrt;
56+
5557
use std::prelude::*;
56-
use std::rt::thread::Thread;
58+
use rustrt::thread::Thread;
5759
use super::*;
5860
use task::Task;
5961

src/librustrt/mutex.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
//! # Example
3434
//!
3535
//! ```rust
36-
//! use std::rt::mutex::{NativeMutex, StaticNativeMutex, NATIVE_MUTEX_INIT};
36+
//! use rustrt::mutex::{NativeMutex, StaticNativeMutex, NATIVE_MUTEX_INIT};
3737
//!
3838
//! // Use a statically initialized mutex
3939
//! static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
@@ -108,7 +108,7 @@ impl StaticNativeMutex {
108108
/// # Example
109109
///
110110
/// ```rust
111-
/// use std::rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
111+
/// use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
112112
/// static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
113113
/// unsafe {
114114
/// let _guard = LOCK.lock();
@@ -225,7 +225,7 @@ impl NativeMutex {
225225
/// # Example
226226
///
227227
/// ```rust
228-
/// use std::rt::mutex::NativeMutex;
228+
/// use rustrt::mutex::NativeMutex;
229229
/// unsafe {
230230
/// let mut lock = NativeMutex::new();
231231
///
@@ -649,11 +649,13 @@ mod imp {
649649

650650
#[cfg(test)]
651651
mod test {
652+
extern crate rustrt;
653+
652654
use std::prelude::*;
653655

654656
use std::mem::drop;
655657
use super::{StaticNativeMutex, NATIVE_MUTEX_INIT};
656-
use std::rt::thread::Thread;
658+
use rustrt::thread::Thread;
657659

658660
#[test]
659661
fn smoke_lock() {

src/librustrt/task.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,8 @@ impl Death {
544544

545545
#[cfg(test)]
546546
mod test {
547+
extern crate rustrt;
548+
547549
use super::*;
548550
use std::prelude::*;
549551
use std::task;
@@ -592,7 +594,7 @@ mod test {
592594
#[test]
593595
#[should_fail]
594596
fn test_begin_unwind() {
595-
use std::rt::unwind::begin_unwind;
597+
use rustrt::unwind::begin_unwind;
596598
begin_unwind("cause", &(file!(), line!()))
597599
}
598600

src/libstd/dynamic_lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ pub mod dl {
229229
}
230230

231231
pub fn check_for_errors_in<T>(f: || -> T) -> Result<T, String> {
232-
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
232+
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
233233
static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
234234
unsafe {
235235
// dlerror isn't thread safe, so we need to lock around this entire

src/libstd/failure.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use kinds::Send;
1818
use option::{Some, None};
1919
use result::Ok;
2020
use rt::backtrace;
21-
use rt::{Stderr, Stdio};
21+
use rustrt::{Stderr, Stdio};
2222
use rustrt::local::Local;
2323
use rustrt::task::Task;
2424
use str::Str;

src/libstd/io/stdio.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ use option::{Option, Some, None};
4040
use boxed::Box;
4141
use sys::{fs, tty};
4242
use result::{Ok, Err};
43-
use rt;
44-
use rt::local::Local;
45-
use rt::task::Task;
43+
use rustrt;
44+
use rustrt::local::Local;
45+
use rustrt::task::Task;
4646
use slice::SlicePrelude;
4747
use str::StrPrelude;
4848
use uint;
@@ -207,7 +207,7 @@ fn with_task_stdout(f: |&mut Writer| -> IoResult<()>) {
207207
local_stdout.replace(Some(my_stdout));
208208
result
209209
} else {
210-
let mut io = rt::Stdout;
210+
let mut io = rustrt::Stdout;
211211
f(&mut io as &mut Writer)
212212
};
213213
match result {

src/libstd/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ pub use core::result;
162162
pub use core::option;
163163

164164
pub use alloc::boxed;
165-
166165
pub use alloc::rc;
167166

168167
pub use core_collections::slice;
@@ -247,7 +246,7 @@ pub mod fmt;
247246

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

250-
mod rt;
249+
pub mod rt;
251250
mod failure;
252251

253252
// A curious inner-module that's not exported that contains the binding

src/libstd/os.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ Accessing environment variables is not generally threadsafe.
208208
Serialize access through a global lock.
209209
*/
210210
fn with_env_lock<T>(f: || -> T) -> T {
211-
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
211+
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
212212

213213
static LOCK: StaticNativeMutex = NATIVE_MUTEX_INIT;
214214

@@ -1039,9 +1039,9 @@ fn real_args_as_bytes() -> Vec<Vec<u8>> {
10391039
target_os = "freebsd",
10401040
target_os = "dragonfly"))]
10411041
fn real_args_as_bytes() -> Vec<Vec<u8>> {
1042-
use rt;
1042+
use rustrt;
10431043

1044-
match rt::args::clone() {
1044+
match rustrt::args::clone() {
10451045
Some(args) => args,
10461046
None => panic!("process arguments not initialized")
10471047
}

src/libstd/rt/backtrace.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ mod imp {
238238
use mem;
239239
use option::{Some, None, Option};
240240
use result::{Ok, Err};
241-
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
241+
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
242242

243243
/// As always - iOS on arm uses SjLj exceptions and
244244
/// _Unwind_Backtrace is even not available there. Still,
@@ -667,7 +667,7 @@ mod imp {
667667
use option::{Some, None};
668668
use path::Path;
669669
use result::{Ok, Err};
670-
use rt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
670+
use rustrt::mutex::{StaticNativeMutex, NATIVE_MUTEX_INIT};
671671
use slice::SlicePrelude;
672672
use str::StrPrelude;
673673
use dynamic_lib::DynamicLibrary;

src/libstd/rt/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,7 @@ pub use self::util::{default_sched_threads, min_stack, running_on_valgrind};
6666
// Reexport functionality from librustrt and other crates underneath the
6767
// standard library which work together to create the entire runtime.
6868
pub use alloc::heap;
69-
pub use rustrt::{task, local, mutex, exclusive, stack, args, thread};
70-
pub use rustrt::{Stdio, Stdout, Stderr, begin_unwind, begin_unwind_fmt};
71-
pub use rustrt::{at_exit, unwind, DEFAULT_ERROR_CODE};
69+
pub use rustrt::{begin_unwind, begin_unwind_fmt, at_exit};
7270

7371
// Simple backtrace functionality (to print on panic)
7472
pub mod backtrace;
@@ -84,7 +82,7 @@ mod util;
8482
#[allow(experimental)]
8583
pub fn init(argc: int, argv: *const *const u8) {
8684
rustrt::init(argc, argv);
87-
unsafe { unwind::register(failure::on_fail); }
85+
unsafe { rustrt::unwind::register(failure::on_fail); }
8886
}
8987

9088
#[cfg(any(windows, android))]
@@ -147,19 +145,19 @@ pub fn start(argc: int, argv: *const *const u8, main: proc()) -> int {
147145
init(argc, argv);
148146
let mut exit_code = None;
149147
let mut main = Some(main);
150-
let mut task = Task::new(Some((my_stack_bottom, my_stack_top)),
151-
Some(rt::thread::main_guard_page()));
148+
let mut task = box Task::new(Some((my_stack_bottom, my_stack_top)),
149+
Some(rustrt::thread::main_guard_page()));
152150
task.name = Some(str::Slice("<main>"));
153151
drop(task.run(|| {
154152
unsafe {
155-
rt::stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top);
153+
rustrt::stack::record_os_managed_stack_bounds(my_stack_bottom, my_stack_top);
156154
}
157155
(main.take().unwrap())();
158156
exit_code = Some(os::get_exit_status());
159157
}).destroy());
160158
unsafe { rt::cleanup(); }
161159
// If the exit code wasn't set, then the task block must have panicked.
162-
return exit_code.unwrap_or(rt::DEFAULT_ERROR_CODE);
160+
return exit_code.unwrap_or(rustrt::DEFAULT_ERROR_CODE);
163161
}
164162

165163
/// One-time runtime cleanup.

src/libstd/sys/common/helper_thread.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
2323
use mem;
2424
use rustrt::bookkeeping;
25-
use rt::mutex::StaticNativeMutex;
26-
use rt;
25+
use rustrt::mutex::StaticNativeMutex;
26+
use rustrt;
2727
use cell::UnsafeCell;
2828
use sys::helper_signal;
2929
use prelude::*;
@@ -83,7 +83,7 @@ impl<M: Send> Helper<M> {
8383
self.lock.lock().signal()
8484
});
8585

86-
rt::at_exit(proc() { self.shutdown() });
86+
rustrt::at_exit(proc() { self.shutdown() });
8787
*self.initialized.get() = true;
8888
}
8989
}

src/libstd/sys/common/net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use libc::{mod, c_char, c_int};
1616
use mem;
1717
use num::Int;
1818
use ptr::{mod, null, null_mut};
19-
use rt::mutex;
19+
use rustrt::mutex;
2020
use io::net::ip::{SocketAddr, IpAddr, Ipv4Addr, Ipv6Addr};
2121
use io::net::addrinfo;
2222
use io::{IoResult, IoError};

src/libstd/sys/unix/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use sys_common::mkerr_libc;
2525

2626
macro_rules! helper_init( (static $name:ident: Helper<$m:ty>) => (
2727
static $name: Helper<$m> = Helper {
28-
lock: ::rt::mutex::NATIVE_MUTEX_INIT,
28+
lock: ::rustrt::mutex::NATIVE_MUTEX_INIT,
2929
chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
3030
signal: ::cell::UnsafeCell { value: 0 },
3131
initialized: ::cell::UnsafeCell { value: false },

src/libstd/sys/unix/pipe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use alloc::arc::Arc;
1212
use libc;
1313
use c_str::CString;
1414
use mem;
15-
use rt::mutex;
15+
use rustrt::mutex;
1616
use sync::atomic;
1717
use io::{mod, IoResult, IoError};
1818
use prelude::*;

src/libstd/sys/windows/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use sync::{Once, ONCE_INIT};
2626

2727
macro_rules! helper_init( (static $name:ident: Helper<$m:ty>) => (
2828
static $name: Helper<$m> = Helper {
29-
lock: ::rt::mutex::NATIVE_MUTEX_INIT,
29+
lock: ::rustrt::mutex::NATIVE_MUTEX_INIT,
3030
chan: ::cell::UnsafeCell { value: 0 as *mut Sender<$m> },
3131
signal: ::cell::UnsafeCell { value: 0 },
3232
initialized: ::cell::UnsafeCell { value: false },

src/libstd/sys/windows/pipe.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ use c_str::CString;
9090
use mem;
9191
use ptr;
9292
use sync::atomic;
93-
use rt::mutex;
93+
use rustrt::mutex;
9494
use io::{mod, IoError, IoResult};
9595
use prelude::*;
9696

src/libstd/task.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ use kinds::{Send, marker};
5050
use option::{None, Some, Option};
5151
use boxed::Box;
5252
use result::Result;
53-
use rt::local::Local;
54-
use rt::task;
55-
use rt::task::Task;
53+
use rustrt::local::Local;
54+
use rustrt::task;
55+
use rustrt::task::Task;
5656
use str::{Str, SendStr, IntoMaybeOwned};
5757
use string::{String, ToString};
5858
use sync::Future;
@@ -142,13 +142,13 @@ impl TaskBuilder {
142142
stack_size: stack_size,
143143
};
144144
if stdout.is_some() || stderr.is_some() {
145-
spawner.spawn(opts, proc() {
145+
Task::spawn(opts, proc() {
146146
let _ = stdout.map(stdio::set_stdout);
147147
let _ = stderr.map(stdio::set_stderr);
148148
f();
149149
})
150150
} else {
151-
spawner.spawn(opts, f)
151+
Task::spawn(opts, f)
152152
}
153153
}
154154

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

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

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

src/libsync/comm/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,8 @@ macro_rules! test (
336336
mod $name {
337337
#![allow(unused_imports)]
338338

339+
extern crate rustrt;
340+
339341
use std::prelude::*;
340342

341343
use comm::*;
@@ -1512,7 +1514,7 @@ mod test {
15121514
})
15131515

15141516
test!(fn sends_off_the_runtime() {
1515-
use std::rt::thread::Thread;
1517+
use rustrt::thread::Thread;
15161518

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

15291531
test!(fn try_recvs_off_the_runtime() {
1530-
use std::rt::thread::Thread;
1532+
use rustrt::thread::Thread;
15311533

15321534
let (tx, rx) = channel();
15331535
let (cdone, pdone) = channel();
@@ -1977,7 +1979,7 @@ mod sync_tests {
19771979
})
19781980

19791981
test!(fn try_recvs_off_the_runtime() {
1980-
use std::rt::thread::Thread;
1982+
use rustrt::thread::Thread;
19811983

19821984
let (tx, rx) = sync_channel::<()>(0);
19831985
let (cdone, pdone) = channel();

src/libsync/deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ mod tests {
414414
use super::{Data, BufferPool, Abort, Empty, Worker, Stealer};
415415

416416
use std::mem;
417-
use std::rt::thread::Thread;
417+
use rustrt::thread::Thread;
418418
use std::rand;
419419
use std::rand::Rng;
420420
use atomic::{AtomicBool, INIT_ATOMIC_BOOL, SeqCst,

0 commit comments

Comments
 (0)