Skip to content

Commit

Permalink
libextra: Another round of de-Cell-ing.
Browse files Browse the repository at this point in the history
34 uses of `Cell` remain.
  • Loading branch information
pcwalton committed Dec 10, 2013
1 parent 5aad292 commit 786dea2
Show file tree
Hide file tree
Showing 35 changed files with 211 additions and 387 deletions.
6 changes: 3 additions & 3 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,10 @@ 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 || {
let c = Cell::new(c);
do task::spawn {
// wait until parent gets in
p.take().recv();
p.recv();
arc2.access_cond(|state, cond| {
*state = true;
cond.signal();
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
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
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
5 changes: 2 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,10 @@ 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();
watcher.fire();
};

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

0 comments on commit 786dea2

Please sign in to comment.