Skip to content

libextra: Another round of de-Cell-ing. #10791

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 13 commits into from
Dec 11, 2013
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
14 changes: 6 additions & 8 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,19 +325,17 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {
}

pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn {
use std::cell::Cell;
let config = Cell::new((*config).clone());
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = Cell::new(testfile.as_str().unwrap().to_owned());
test::DynTestFn(proc() { runtest::run(config.take(), testfile.take()) })
let testfile = testfile.as_str().unwrap().to_owned();
test::DynTestFn(proc() { runtest::run(config, testfile) })
}

pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::TestFn {
use std::cell::Cell;
let config = Cell::new((*config).clone());
let config = (*config).clone();
// FIXME (#9639): This needs to handle non-utf8 paths
let testfile = Cell::new(testfile.as_str().unwrap().to_owned());
let testfile = testfile.as_str().unwrap().to_owned();
test::DynMetricFn(proc(mm) {
runtest::run_metrics(config.take(), testfile.take(), mm)
runtest::run_metrics(config, testfile, mm)
})
}
9 changes: 4 additions & 5 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,6 @@ mod tests {

use arc::*;

use std::cell::Cell;
use std::comm;
use std::task;

Expand Down Expand Up @@ -628,18 +627,18 @@ mod tests {
let arc = ~MutexArc::new(false);
let arc2 = ~arc.clone();
let (p,c) = comm::oneshot();
let (c,p) = (Cell::new(c), Cell::new(p));
do task::spawn || {
do task::spawn {
// wait until parent gets in
p.take().recv();
p.recv();
arc2.access_cond(|state, cond| {
*state = true;
cond.signal();
})
}

let mut c = Some(c);
arc.access_cond(|state, cond| {
c.take().send(());
c.take_unwrap().send(());
assert!(!*state);
while !*state {
cond.wait();
Expand Down
9 changes: 3 additions & 6 deletions src/libextra/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

#[allow(missing_doc)];

use std::cell::Cell;
use std::comm::{PortOne, oneshot};
use std::util::replace;

Expand Down Expand Up @@ -113,9 +112,8 @@ impl<A:Send> Future<A> {
* waiting for the result to be received on the port.
*/

let port = Cell::new(port);
do Future::from_fn {
port.take().recv()
port.recv()
}
}

Expand All @@ -141,7 +139,6 @@ impl<A:Send> Future<A> {
mod test {
use future::Future;

use std::cell::Cell;
use std::comm::oneshot;
use std::task;

Expand Down Expand Up @@ -199,9 +196,9 @@ mod test {
#[test]
fn test_sendable_future() {
let expected = "schlorf";
let f = Cell::new(do Future::spawn { expected });
let f = do Future::spawn { expected };
do task::spawn {
let mut f = f.take();
let mut f = f;
let actual = f.get();
assert_eq!(actual, expected);
}
Expand Down
9 changes: 4 additions & 5 deletions src/libextra/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,6 @@ mod tests {
use sync::*;

use std::cast;
use std::cell::Cell;
use std::comm;
use std::result;
use std::task;
Expand Down Expand Up @@ -762,9 +761,9 @@ mod tests {
let s = Semaphore::new(1);
let s2 = s.clone();
let (p, c) = comm::stream();
let child_data = Cell::new((s2, c));
let mut child_data = Some((s2, c));
s.access(|| {
let (s2, c) = child_data.take();
let (s2, c) = child_data.take_unwrap();
do task::spawn {
c.send(());
s2.access(|| { });
Expand Down Expand Up @@ -947,13 +946,13 @@ mod tests {
let mut sibling_convos = ~[];
2.times(|| {
let (p, c) = comm::stream();
let c = Cell::new(c);
sibling_convos.push(p);
let mi = m2.clone();
// spawn sibling task
do task::spawn { // linked
let mut c = Some(c);
mi.lock_cond(|cond| {
let c = c.take();
let c = c.take_unwrap();
c.send(()); // tell sibling to go ahead
(|| {
cond.wait(); // block forever
Expand Down
3 changes: 1 addition & 2 deletions src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -872,15 +872,14 @@ pub fn run_test(force_ignore: bool,
fn run_test_inner(desc: TestDesc,
monitor_ch: SharedChan<MonitorMsg>,
testfn: proc()) {
let testfn_cell = ::std::cell::Cell::new(testfn);
do task::spawn {
let mut task = task::task();
task.name(match desc.name {
DynTestName(ref name) => SendStrOwned(name.clone()),
StaticTestName(name) => SendStrStatic(name),
});
let result_future = task.future_result();
task.spawn(testfn_cell.take());
task.spawn(testfn);

let task_result = result_future.recv();
let test_result = calc_result(&desc, task_result.is_ok());
Expand Down
3 changes: 0 additions & 3 deletions src/libextra/workcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use json::ToJson;
use serialize::{Encoder, Encodable, Decoder, Decodable};
use arc::{Arc,RWArc};
use treemap::TreeMap;
use std::cell::Cell;
use std::comm::{PortOne, oneshot};
use std::{str, task};
use std::io;
Expand Down Expand Up @@ -430,15 +429,13 @@ impl<'self> Prep<'self> {
debug!("Cache miss!");
let (port, chan) = oneshot();
let blk = bo.take_unwrap();
let chan = Cell::new(chan);

// XXX: What happens if the task fails?
do task::spawn {
let mut exe = Exec {
discovered_inputs: WorkMap::new(),
discovered_outputs: WorkMap::new(),
};
let chan = chan.take();
let v = blk(&mut exe);
chan.send((exe, v));
}
Expand Down
43 changes: 27 additions & 16 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
//! These tasks are not parallelized (they haven't been a bottleneck yet), and
//! both occur before the crate is rendered.

use std::cell::Cell;
use std::comm::{SharedPort, SharedChan};
use std::comm;
use std::fmt;
Expand All @@ -46,7 +45,6 @@ use std::io::File;
use std::os;
use std::str;
use std::task;
use std::unstable::finally::Finally;
use std::vec;

use extra::arc::RWArc;
Expand Down Expand Up @@ -642,6 +640,22 @@ impl<'self> Cache {
}
}

enum Progress {
JobNew,
JobDone,
}

/// A helper object to unconditionally send a value on a chanel.
struct ChannelGuard {
channel: SharedChan<Progress>,
}

impl Drop for ChannelGuard {
fn drop(&mut self) {
self.channel.send(JobDone)
}
}

impl Context {
/// Recurse in the directory structure and change the "root path" to make
/// sure it always points to the top (relatively)
Expand Down Expand Up @@ -674,8 +688,6 @@ impl Context {
Die,
Process(Context, clean::Item),
}
enum Progress { JobNew, JobDone }

let workers = match os::getenv("RUSTDOC_WORKERS") {
Some(s) => {
match from_str::<uint>(s) {
Expand Down Expand Up @@ -725,16 +737,15 @@ impl Context {
match port.recv() {
Process(cx, item) => {
let mut cx = cx;
let item = Cell::new(item);
(|| {
cx.item(item.take(), |cx, item| {
prog_chan.send(JobNew);
chan.send(Process(cx.clone(), item));
})
}).finally(|| {
// If we fail, everything else should still get
// completed
prog_chan.send(JobDone);

// If we fail, everything else should still get
// completed.
let _guard = ChannelGuard {
channel: prog_chan.clone(),
};
cx.item(item, |cx, item| {
prog_chan.send(JobNew);
chan.send(Process(cx.clone(), item));
})
}
Die => break,
Expand Down Expand Up @@ -802,9 +813,9 @@ impl Context {
// recurse into the items of the module as well.
clean::ModuleItem(..) => {
let name = item.name.get_ref().to_owned();
let item = Cell::new(item);
let mut item = Some(item);
self.recurse(name, |this| {
let item = item.take();
let item = item.take_unwrap();
let dst = this.dst.join("index.html");
render(File::create(&dst).unwrap(), this, &item, false);

Expand Down
11 changes: 5 additions & 6 deletions src/librustdoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ extern mod syntax;
extern mod rustc;
extern mod extra;

use std::cell::Cell;
use std::local_data;
use std::io;
use std::io::File;
Expand Down Expand Up @@ -194,13 +193,13 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
let mut plugins = matches.opt_strs("plugins");

// First, parse the crate and extract all relevant information.
let libs = Cell::new(matches.opt_strs("L").map(|s| Path::new(s.as_slice())));
let cfgs = Cell::new(matches.opt_strs("cfg"));
let cr = Cell::new(Path::new(cratefile));
let libs = matches.opt_strs("L").map(|s| Path::new(s.as_slice()));
let cfgs = matches.opt_strs("cfg");
let cr = Path::new(cratefile);
info!("starting to run rustc");
let (crate, analysis) = do std::task::try {
let cr = cr.take();
core::run_core(libs.take().move_iter().collect(), cfgs.take(), &cr)
let cr = cr;
core::run_core(libs.move_iter().collect(), cfgs, &cr)
}.unwrap();
info!("finished with rustc");
local_data::set(analysiskey, analysis);
Expand Down
9 changes: 3 additions & 6 deletions src/librustdoc/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::num;
use std::cell::Cell;
use std::uint;
use std::hashmap::HashSet;
use std::local_data;

use std::num;
use std::uint;
use syntax::ast;

use clean;
Expand Down Expand Up @@ -56,11 +54,10 @@ pub fn strip_hidden(crate: clean::Crate) -> plugins::PluginResult {
pub fn strip_private(crate: clean::Crate) -> plugins::PluginResult {
// This stripper collects all *retained* nodes.
let mut retained = HashSet::new();
let crate = Cell::new(crate);
let exported_items = local_data::get(super::analysiskey, |analysis| {
analysis.unwrap().exported_items.clone()
});
let mut crate = crate.take();
let mut crate = crate;

// strip all private items
{
Expand Down
15 changes: 12 additions & 3 deletions src/librustpkg/installed_packages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ use std::io::fs;
pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool {
let workspaces = rust_path();
for p in workspaces.iter() {
let binfiles = io::ignore_io_error(|| fs::readdir(&p.join("bin")));
let binfiles = {
let _guard = io::ignore_io_error();
fs::readdir(&p.join("bin"))
};
for exec in binfiles.iter() {
// FIXME (#9639): This needs to handle non-utf8 paths
match exec.filestem_str() {
Expand All @@ -31,7 +34,10 @@ pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool {
}
}
}
let libfiles = io::ignore_io_error(|| fs::readdir(&p.join("lib")));
let libfiles = {
let _guard = io::ignore_io_error();
fs::readdir(&p.join("lib"))
};
for lib in libfiles.iter() {
debug!("Full name: {}", lib.display());
match has_library(lib) {
Expand All @@ -55,7 +61,10 @@ pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool {
}

pub fn has_library(p: &Path) -> Option<~str> {
let files = io::ignore_io_error(|| fs::readdir(p));
let files = {
let _guard = io::ignore_io_error();
fs::readdir(p)
};
for path in files.iter() {
if path.extension_str() == Some(os::consts::DLL_EXTENSION) {
let stuff : &str = path.filestem_str().expect("has_library: weird path");
Expand Down
5 changes: 4 additions & 1 deletion src/librustpkg/path_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ pub fn system_library(sysroot: &Path, lib_name: &str) -> Option<Path> {

fn library_in(short_name: &str, version: &Version, dir_to_search: &Path) -> Option<Path> {
debug!("Listing directory {}", dir_to_search.display());
let dir_contents = io::ignore_io_error(|| fs::readdir(dir_to_search));
let dir_contents = {
let _guard = io::ignore_io_error();
fs::readdir(dir_to_search)
};
debug!("dir has {:?} entries", dir_contents.len());

let lib_prefix = format!("{}{}", os::consts::DLL_PREFIX, short_name);
Expand Down
6 changes: 3 additions & 3 deletions src/librustuv/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ impl Drop for AsyncWatcher {

#[cfg(test)]
mod test_remote {
use std::cell::Cell;
use std::rt::rtio::Callback;
use std::rt::thread::Thread;
use std::rt::tube::Tube;
Expand All @@ -150,10 +149,11 @@ mod test_remote {

let mut tube = Tube::new();
let cb = ~MyCallback(Some(tube.clone()));
let watcher = Cell::new(AsyncWatcher::new(local_loop(), cb as ~Callback));
let watcher = AsyncWatcher::new(local_loop(), cb as ~Callback);

let thread = do Thread::start {
watcher.take().fire();
let mut watcher = watcher;
watcher.fire();
};

assert_eq!(tube.recv(), 1);
Expand Down
Loading