Skip to content

Commit b8b16ae

Browse files
committed
auto merge of #10791 : pcwalton/rust/decelling, r=pcwalton
34 uses of `Cell` remain. r? @alexcrichton
2 parents ac4dd9e + fd7a513 commit b8b16ae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+876
-967
lines changed

src/compiletest/compiletest.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,17 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {
325325
}
326326

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

335334
pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::TestFn {
336-
use std::cell::Cell;
337-
let config = Cell::new((*config).clone());
335+
let config = (*config).clone();
338336
// FIXME (#9639): This needs to handle non-utf8 paths
339-
let testfile = Cell::new(testfile.as_str().unwrap().to_owned());
337+
let testfile = testfile.as_str().unwrap().to_owned();
340338
test::DynMetricFn(proc(mm) {
341-
runtest::run_metrics(config.take(), testfile.take(), mm)
339+
runtest::run_metrics(config, testfile, mm)
342340
})
343341
}

src/libextra/arc.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,6 @@ mod tests {
597597

598598
use arc::*;
599599

600-
use std::cell::Cell;
601600
use std::comm;
602601
use std::task;
603602

@@ -628,18 +627,18 @@ mod tests {
628627
let arc = ~MutexArc::new(false);
629628
let arc2 = ~arc.clone();
630629
let (p,c) = comm::oneshot();
631-
let (c,p) = (Cell::new(c), Cell::new(p));
632-
do task::spawn || {
630+
do task::spawn {
633631
// wait until parent gets in
634-
p.take().recv();
632+
p.recv();
635633
arc2.access_cond(|state, cond| {
636634
*state = true;
637635
cond.signal();
638636
})
639637
}
640638

639+
let mut c = Some(c);
641640
arc.access_cond(|state, cond| {
642-
c.take().send(());
641+
c.take_unwrap().send(());
643642
assert!(!*state);
644643
while !*state {
645644
cond.wait();

src/libextra/future.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
#[allow(missing_doc)];
2727

28-
use std::cell::Cell;
2928
use std::comm::{PortOne, oneshot};
3029
use std::util::replace;
3130

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

116-
let port = Cell::new(port);
117115
do Future::from_fn {
118-
port.take().recv()
116+
port.recv()
119117
}
120118
}
121119

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

144-
use std::cell::Cell;
145142
use std::comm::oneshot;
146143
use std::task;
147144

@@ -199,9 +196,9 @@ mod test {
199196
#[test]
200197
fn test_sendable_future() {
201198
let expected = "schlorf";
202-
let f = Cell::new(do Future::spawn { expected });
199+
let f = do Future::spawn { expected };
203200
do task::spawn {
204-
let mut f = f.take();
201+
let mut f = f;
205202
let actual = f.get();
206203
assert_eq!(actual, expected);
207204
}

src/libextra/sync.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,6 @@ mod tests {
676676
use sync::*;
677677

678678
use std::cast;
679-
use std::cell::Cell;
680679
use std::comm;
681680
use std::result;
682681
use std::task;
@@ -762,9 +761,9 @@ mod tests {
762761
let s = Semaphore::new(1);
763762
let s2 = s.clone();
764763
let (p, c) = comm::stream();
765-
let child_data = Cell::new((s2, c));
764+
let mut child_data = Some((s2, c));
766765
s.access(|| {
767-
let (s2, c) = child_data.take();
766+
let (s2, c) = child_data.take_unwrap();
768767
do task::spawn {
769768
c.send(());
770769
s2.access(|| { });
@@ -947,13 +946,13 @@ mod tests {
947946
let mut sibling_convos = ~[];
948947
2.times(|| {
949948
let (p, c) = comm::stream();
950-
let c = Cell::new(c);
951949
sibling_convos.push(p);
952950
let mi = m2.clone();
953951
// spawn sibling task
954952
do task::spawn { // linked
953+
let mut c = Some(c);
955954
mi.lock_cond(|cond| {
956-
let c = c.take();
955+
let c = c.take_unwrap();
957956
c.send(()); // tell sibling to go ahead
958957
(|| {
959958
cond.wait(); // block forever

src/libextra/test.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -872,15 +872,14 @@ pub fn run_test(force_ignore: bool,
872872
fn run_test_inner(desc: TestDesc,
873873
monitor_ch: SharedChan<MonitorMsg>,
874874
testfn: proc()) {
875-
let testfn_cell = ::std::cell::Cell::new(testfn);
876875
do task::spawn {
877876
let mut task = task::task();
878877
task.name(match desc.name {
879878
DynTestName(ref name) => SendStrOwned(name.clone()),
880879
StaticTestName(name) => SendStrStatic(name),
881880
});
882881
let result_future = task.future_result();
883-
task.spawn(testfn_cell.take());
882+
task.spawn(testfn);
884883

885884
let task_result = result_future.recv();
886885
let test_result = calc_result(&desc, task_result.is_ok());

src/libextra/workcache.rs

-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use json::ToJson;
1515
use serialize::{Encoder, Encodable, Decoder, Decodable};
1616
use arc::{Arc,RWArc};
1717
use treemap::TreeMap;
18-
use std::cell::Cell;
1918
use std::comm::{PortOne, oneshot};
2019
use std::{str, task};
2120
use std::io;
@@ -430,15 +429,13 @@ impl<'self> Prep<'self> {
430429
debug!("Cache miss!");
431430
let (port, chan) = oneshot();
432431
let blk = bo.take_unwrap();
433-
let chan = Cell::new(chan);
434432

435433
// XXX: What happens if the task fails?
436434
do task::spawn {
437435
let mut exe = Exec {
438436
discovered_inputs: WorkMap::new(),
439437
discovered_outputs: WorkMap::new(),
440438
};
441-
let chan = chan.take();
442439
let v = blk(&mut exe);
443440
chan.send((exe, v));
444441
}

src/librustdoc/html/render.rs

+27-16
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
//! These tasks are not parallelized (they haven't been a bottleneck yet), and
3434
//! both occur before the crate is rendered.
3535
36-
use std::cell::Cell;
3736
use std::comm::{SharedPort, SharedChan};
3837
use std::comm;
3938
use std::fmt;
@@ -46,7 +45,6 @@ use std::io::File;
4645
use std::os;
4746
use std::str;
4847
use std::task;
49-
use std::unstable::finally::Finally;
5048
use std::vec;
5149

5250
use extra::arc::RWArc;
@@ -642,6 +640,22 @@ impl<'self> Cache {
642640
}
643641
}
644642

643+
enum Progress {
644+
JobNew,
645+
JobDone,
646+
}
647+
648+
/// A helper object to unconditionally send a value on a chanel.
649+
struct ChannelGuard {
650+
channel: SharedChan<Progress>,
651+
}
652+
653+
impl Drop for ChannelGuard {
654+
fn drop(&mut self) {
655+
self.channel.send(JobDone)
656+
}
657+
}
658+
645659
impl Context {
646660
/// Recurse in the directory structure and change the "root path" to make
647661
/// sure it always points to the top (relatively)
@@ -674,8 +688,6 @@ impl Context {
674688
Die,
675689
Process(Context, clean::Item),
676690
}
677-
enum Progress { JobNew, JobDone }
678-
679691
let workers = match os::getenv("RUSTDOC_WORKERS") {
680692
Some(s) => {
681693
match from_str::<uint>(s) {
@@ -725,16 +737,15 @@ impl Context {
725737
match port.recv() {
726738
Process(cx, item) => {
727739
let mut cx = cx;
728-
let item = Cell::new(item);
729-
(|| {
730-
cx.item(item.take(), |cx, item| {
731-
prog_chan.send(JobNew);
732-
chan.send(Process(cx.clone(), item));
733-
})
734-
}).finally(|| {
735-
// If we fail, everything else should still get
736-
// completed
737-
prog_chan.send(JobDone);
740+
741+
// If we fail, everything else should still get
742+
// completed.
743+
let _guard = ChannelGuard {
744+
channel: prog_chan.clone(),
745+
};
746+
cx.item(item, |cx, item| {
747+
prog_chan.send(JobNew);
748+
chan.send(Process(cx.clone(), item));
738749
})
739750
}
740751
Die => break,
@@ -802,9 +813,9 @@ impl Context {
802813
// recurse into the items of the module as well.
803814
clean::ModuleItem(..) => {
804815
let name = item.name.get_ref().to_owned();
805-
let item = Cell::new(item);
816+
let mut item = Some(item);
806817
self.recurse(name, |this| {
807-
let item = item.take();
818+
let item = item.take_unwrap();
808819
let dst = this.dst.join("index.html");
809820
render(File::create(&dst).unwrap(), this, &item, false);
810821

src/librustdoc/lib.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ extern mod syntax;
2626
extern mod rustc;
2727
extern mod extra;
2828

29-
use std::cell::Cell;
3029
use std::local_data;
3130
use std::io;
3231
use std::io::File;
@@ -196,13 +195,13 @@ fn rust_input(cratefile: &str, matches: &getopts::Matches) -> Output {
196195
let mut plugins = matches.opt_strs("plugins");
197196

198197
// First, parse the crate and extract all relevant information.
199-
let libs = Cell::new(matches.opt_strs("L").map(|s| Path::new(s.as_slice())));
200-
let cfgs = Cell::new(matches.opt_strs("cfg"));
201-
let cr = Cell::new(Path::new(cratefile));
198+
let libs = matches.opt_strs("L").map(|s| Path::new(s.as_slice()));
199+
let cfgs = matches.opt_strs("cfg");
200+
let cr = Path::new(cratefile);
202201
info!("starting to run rustc");
203202
let (crate, analysis) = do std::task::try {
204-
let cr = cr.take();
205-
core::run_core(libs.take().move_iter().collect(), cfgs.take(), &cr)
203+
let cr = cr;
204+
core::run_core(libs.move_iter().collect(), cfgs, &cr)
206205
}.unwrap();
207206
info!("finished with rustc");
208207
local_data::set(analysiskey, analysis);

src/librustdoc/passes.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use std::num;
12-
use std::cell::Cell;
13-
use std::uint;
1411
use std::hashmap::HashSet;
1512
use std::local_data;
16-
13+
use std::num;
14+
use std::uint;
1715
use syntax::ast;
1816

1917
use clean;
@@ -56,11 +54,10 @@ pub fn strip_hidden(crate: clean::Crate) -> plugins::PluginResult {
5654
pub fn strip_private(crate: clean::Crate) -> plugins::PluginResult {
5755
// This stripper collects all *retained* nodes.
5856
let mut retained = HashSet::new();
59-
let crate = Cell::new(crate);
6057
let exported_items = local_data::get(super::analysiskey, |analysis| {
6158
analysis.unwrap().exported_items.clone()
6259
});
63-
let mut crate = crate.take();
60+
let mut crate = crate;
6461

6562
// strip all private items
6663
{

src/librustpkg/installed_packages.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ use std::io::fs;
1919
pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool {
2020
let workspaces = rust_path();
2121
for p in workspaces.iter() {
22-
let binfiles = io::ignore_io_error(|| fs::readdir(&p.join("bin")));
22+
let binfiles = {
23+
let _guard = io::ignore_io_error();
24+
fs::readdir(&p.join("bin"))
25+
};
2326
for exec in binfiles.iter() {
2427
// FIXME (#9639): This needs to handle non-utf8 paths
2528
match exec.filestem_str() {
@@ -31,7 +34,10 @@ pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool {
3134
}
3235
}
3336
}
34-
let libfiles = io::ignore_io_error(|| fs::readdir(&p.join("lib")));
37+
let libfiles = {
38+
let _guard = io::ignore_io_error();
39+
fs::readdir(&p.join("lib"))
40+
};
3541
for lib in libfiles.iter() {
3642
debug!("Full name: {}", lib.display());
3743
match has_library(lib) {
@@ -55,7 +61,10 @@ pub fn list_installed_packages(f: |&PkgId| -> bool) -> bool {
5561
}
5662

5763
pub fn has_library(p: &Path) -> Option<~str> {
58-
let files = io::ignore_io_error(|| fs::readdir(p));
64+
let files = {
65+
let _guard = io::ignore_io_error();
66+
fs::readdir(p)
67+
};
5968
for path in files.iter() {
6069
if path.extension_str() == Some(os::consts::DLL_EXTENSION) {
6170
let stuff : &str = path.filestem_str().expect("has_library: weird path");

src/librustpkg/path_util.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,10 @@ pub fn system_library(sysroot: &Path, lib_name: &str) -> Option<Path> {
217217

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

223226
let lib_prefix = format!("{}{}", os::consts::DLL_PREFIX, short_name);

src/librustuv/async.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ impl Drop for AsyncWatcher {
125125

126126
#[cfg(test)]
127127
mod test_remote {
128-
use std::cell::Cell;
129128
use std::rt::rtio::Callback;
130129
use std::rt::thread::Thread;
131130
use std::rt::tube::Tube;
@@ -150,10 +149,11 @@ mod test_remote {
150149

151150
let mut tube = Tube::new();
152151
let cb = ~MyCallback(Some(tube.clone()));
153-
let watcher = Cell::new(AsyncWatcher::new(local_loop(), cb as ~Callback));
152+
let watcher = AsyncWatcher::new(local_loop(), cb as ~Callback);
154153

155154
let thread = do Thread::start {
156-
watcher.take().fire();
155+
let mut watcher = watcher;
156+
watcher.fire();
157157
};
158158

159159
assert_eq!(tube.recv(), 1);

0 commit comments

Comments
 (0)