Skip to content

Commit

Permalink
std: Change Cell constructor to new convention
Browse files Browse the repository at this point in the history
  • Loading branch information
brson committed Jun 5, 2013
1 parent 846545a commit 8cb84f5
Show file tree
Hide file tree
Showing 45 changed files with 138 additions and 137 deletions.
4 changes: 2 additions & 2 deletions src/compiletest/compiletest.rc
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub fn make_test_name(config: &config, testfile: &Path) -> test::TestName {

pub fn make_test_closure(config: &config, testfile: &Path) -> test::TestFn {
use core::cell::Cell;
let config = Cell(copy *config);
let testfile = Cell(testfile.to_str());
let config = Cell::new(copy *config);
let testfile = Cell::new(testfile.to_str());
test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) })
}
2 changes: 1 addition & 1 deletion src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ mod tests {
let arc = ~MutexARC(false);
let arc2 = ~arc.clone();
let (p,c) = comm::oneshot();
let (c,p) = (Cell(c), Cell(p));
let (c,p) = (Cell::new(c), Cell::new(p));
do task::spawn || {
// wait until parent gets in
comm::recv_one(p.take());
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/flatpipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,8 +791,8 @@ mod test {

let addr0 = ip::v4::parse_addr("127.0.0.1");

let begin_connect_chan = Cell(begin_connect_chan);
let accept_chan = Cell(accept_chan);
let begin_connect_chan = Cell::new(begin_connect_chan);
let accept_chan = Cell::new(accept_chan);

// The server task
let addr = copy addr0;
Expand Down
6 changes: 3 additions & 3 deletions src/libextra/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ pub fn from_port<A:Owned>(port: PortOne<A>) -> Future<A> {
* waiting for the result to be received on the port.
*/

let port = Cell(port);
let port = Cell::new(port);
do from_fn {
recv_one(port.take())
}
Expand Down Expand Up @@ -137,7 +137,7 @@ pub fn spawn<A:Owned>(blk: ~fn() -> A) -> Future<A> {

let (port, chan) = oneshot();

let chan = Cell(chan);
let chan = Cell::new(chan);
do task::spawn {
let chan = chan.take();
send_one(chan, blk());
Expand Down Expand Up @@ -204,7 +204,7 @@ mod test {
#[test]
fn test_sendable_future() {
let expected = "schlorf";
let f = Cell(do spawn { expected });
let f = Cell::new(do spawn { expected });
do task::spawn {
let mut f = f.take();
let actual = f.get();
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/net_tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1830,7 +1830,7 @@ mod test {
let (server_po, server_ch) = stream::<~str>();
let server_ch = SharedChan::new(server_ch);
let server_ip_addr = ip::v4::parse_addr(server_ip);
let resp_cell = Cell(resp);
let resp_cell = Cell::new(resp);
let listen_result = listen(server_ip_addr, server_port, 128,
iotask,
// on_establish_cb -- called when listener is set up
Expand All @@ -1842,7 +1842,7 @@ mod test {
// risky to run this on the loop, but some users
// will want the POWER
|new_conn, kill_ch| {
let resp_cell2 = Cell(resp_cell.take());
let resp_cell2 = Cell::new(resp_cell.take());
debug!("SERVER: new connection!");
let (cont_po, cont_ch) = stream();
let server_ch = server_ch.clone();
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/rc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ mod test_rc {

#[test]
fn test_clone() {
let x = rc_from_owned(Cell(5));
let x = rc_from_owned(Cell::new(5));
let y = x.clone();
do x.borrow().with_mut_ref |inner| {
*inner = 20;
Expand All @@ -115,7 +115,7 @@ mod test_rc {

#[test]
fn test_deep_clone() {
let x = rc_from_owned(Cell(5));
let x = rc_from_owned(Cell::new(5));
let y = x.deep_clone();
do x.borrow().with_mut_ref |inner| {
*inner = 20;
Expand Down
4 changes: 2 additions & 2 deletions src/libextra/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ mod tests {
let s = ~semaphore(1);
let s2 = ~s.clone();
let (p,c) = comm::stream();
let child_data = Cell((s2, c));
let child_data = Cell::new((s2, c));
do s.access {
let (s2, c) = child_data.take();
do task::spawn || {
Expand Down Expand Up @@ -999,7 +999,7 @@ mod tests {
let mut sibling_convos = ~[];
for 2.times {
let (p,c) = comm::stream();
let c = Cell(c);
let c = Cell::new(c);
sibling_convos.push(p);
let mi = ~m2.clone();
// spawn sibling task
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ pub fn run_test(force_ignore: bool,
fn run_test_inner(desc: TestDesc,
monitor_ch: SharedChan<MonitorMsg>,
testfn: ~fn()) {
let testfn_cell = ::core::cell::Cell(testfn);
let testfn_cell = ::core::cell::Cell::new(testfn);
do task::spawn {
let mut result_future = None; // task::future_result(builder);

Expand Down
2 changes: 1 addition & 1 deletion src/libextra/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ mod test {

for (times as uint).times {
let mut rng = rand::rng();
let expected = Cell(rng.gen_str(16u));
let expected = Cell::new(rng.gen_str(16u));
let (test_po, test_ch) = stream::<~str>();
let hl_loop_clone = hl_loop.clone();
do task::spawn() {
Expand Down
2 changes: 1 addition & 1 deletion src/libextra/workcache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl TPrep for Prep {
_ => {
let (port, chan) = oneshot();
let blk = replace(&mut bo, None).unwrap();
let chan = Cell(chan);
let chan = Cell::new(chan);

do task::spawn {
let exe = Exec {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/typeck/infer/region_inference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ use middle::typeck::infer::cres;
use util::common::indenter;
use util::ppaux::note_and_explain_region;

use core::cell::{Cell, empty_cell};
use core::cell::Cell;
use core::hashmap::{HashMap, HashSet};
use core::to_bytes;
use core::uint;
Expand Down Expand Up @@ -633,7 +633,7 @@ pub fn RegionVarBindings(tcx: ty::ctxt) -> RegionVarBindings {
RegionVarBindings {
tcx: tcx,
var_spans: ~[],
values: empty_cell(),
values: Cell::empty(),
constraints: HashMap::new(),
lubs: HashMap::new(),
glbs: HashMap::new(),
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/astsrv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ fn run<T>(owner: SrvOwner<T>, source: ~str, parse: Parser) -> T {

let (po, ch) = stream();

let source = Cell(source);
let parse = Cell(parse);
let source = Cell::new(source);
let parse = Cell::new(parse);
do task::spawn {
act(&po, source.take(), parse.take());
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ fn config_from_opts(
}
}
};
let process_output = Cell(process_output);
let process_output = Cell::new(process_output);
let result = do result::chain(result) |config| {
let pandoc_cmd = getopts::opt_maybe_str(matches, opt_pandoc_cmd());
let pandoc_cmd = maybe_find_pandoc(
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/markdown_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use core::vec;
use syntax;

pub fn mk_pass(writer_factory: WriterFactory) -> Pass {
let writer_factory = Cell(writer_factory);
let writer_factory = Cell::new(writer_factory);
Pass {
name: ~"markdown",
f: |srv, doc| run(srv, doc, writer_factory.take())
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/text_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use util::NominalOp;
use core::cell::Cell;

pub fn mk_pass(name: ~str, op: @fn(&str) -> ~str) -> Pass {
let op = Cell(op);
let op = Cell::new(op);
Pass {
name: copy name,
f: |srv: astsrv::Srv, doc: doc::Doc| -> doc::Doc {
Expand Down
4 changes: 2 additions & 2 deletions src/librusti/rusti.rc
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,8 @@ pub fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str,
}
}

let line = Cell(line);
let r = Cell(copy *repl);
let line = Cell::new(line);
let r = Cell::new(copy *repl);
let result = do task::try {
run(r.take(), line.take())
};
Expand Down
28 changes: 14 additions & 14 deletions src/libstd/cell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ pub struct Cell<T> {
priv value: Option<T>
}

/// Creates a new full cell with the given value.
pub fn Cell<T>(value: T) -> Cell<T> {
Cell { value: Some(value) }
}
pub impl<T> Cell<T> {
/// Creates a new full cell with the given value.
fn new(value: T) -> Cell<T> {
Cell { value: Some(value) }
}

/// Creates a new empty cell with no value inside.
pub fn empty_cell<T>() -> Cell<T> {
Cell { value: None }
}
/// Creates an empty cell.
pub fn empty() -> Cell<T> {
Cell { value: None }
}

impl<T> Cell<T> {
/// Yields the value, failing if the cell is empty.
pub fn take(&self) -> T {
let this = unsafe { transmute_mut(self) };
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<T> Cell<T> {

#[test]
fn test_basic() {
let value_cell = Cell(~10);
let value_cell = Cell::new(~10);
assert!(!value_cell.is_empty());
let value = value_cell.take();
assert!(value == ~10);
Expand All @@ -96,22 +96,22 @@ fn test_basic() {
#[should_fail]
#[ignore(cfg(windows))]
fn test_take_empty() {
let value_cell = empty_cell::<~int>();
let value_cell = Cell::empty::<~int>();
value_cell.take();
}

#[test]
#[should_fail]
#[ignore(cfg(windows))]
fn test_put_back_non_empty() {
let value_cell = Cell(~10);
let value_cell = Cell::new(~10);
value_cell.put_back(~20);
}

#[test]
fn test_with_ref() {
let good = 6;
let c = Cell(~[1, 2, 3, 4, 5, 6]);
let c = Cell::new(~[1, 2, 3, 4, 5, 6]);
let l = do c.with_ref() |v| { v.len() };
assert_eq!(l, good);
}
Expand All @@ -120,7 +120,7 @@ fn test_with_ref() {
fn test_with_mut_ref() {
let good = ~[1, 2, 3];
let v = ~[1, 2];
let c = Cell(v);
let c = Cell::new(v);
do c.with_mut_ref() |v| { v.push(3); }
let v = c.take();
assert_eq!(v, good);
Expand Down
32 changes: 16 additions & 16 deletions src/libstd/rt/comm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,8 @@ pub struct Port<T> {

pub fn stream<T: Owned>() -> (Port<T>, Chan<T>) {
let (pone, cone) = oneshot();
let port = Port { next: Cell(pone) };
let chan = Chan { next: Cell(cone) };
let port = Port { next: Cell::new(pone) };
let chan = Chan { next: Cell::new(cone) };
return (port, chan);
}

Expand Down Expand Up @@ -483,7 +483,7 @@ mod test {
fn oneshot_multi_task_recv_then_send() {
do run_in_newsched_task {
let (port, chan) = oneshot::<~int>();
let port_cell = Cell(port);
let port_cell = Cell::new(port);
do spawntask_immediately {
assert!(port_cell.take().recv() == ~10);
}
Expand All @@ -496,8 +496,8 @@ mod test {
fn oneshot_multi_task_recv_then_close() {
do run_in_newsched_task {
let (port, chan) = oneshot::<~int>();
let port_cell = Cell(port);
let chan_cell = Cell(chan);
let port_cell = Cell::new(port);
let chan_cell = Cell::new(chan);
do spawntask_later {
let _cell = chan_cell.take();
}
Expand All @@ -513,7 +513,7 @@ mod test {
for stress_factor().times {
do run_in_newsched_task {
let (port, chan) = oneshot::<int>();
let port_cell = Cell(port);
let port_cell = Cell::new(port);
let _thread = do spawntask_thread {
let _p = port_cell.take();
};
Expand All @@ -527,8 +527,8 @@ mod test {
for stress_factor().times {
do run_in_newsched_task {
let (port, chan) = oneshot::<int>();
let chan_cell = Cell(chan);
let port_cell = Cell(port);
let chan_cell = Cell::new(chan);
let port_cell = Cell::new(port);
let _thread1 = do spawntask_thread {
let _p = port_cell.take();
};
Expand All @@ -545,17 +545,17 @@ mod test {
for stress_factor().times {
do run_in_newsched_task {
let (port, chan) = oneshot::<int>();
let chan_cell = Cell(chan);
let port_cell = Cell(port);
let chan_cell = Cell::new(chan);
let port_cell = Cell::new(port);
let _thread1 = do spawntask_thread {
let port_cell = Cell(port_cell.take());
let port_cell = Cell::new(port_cell.take());
let res = do spawntask_try {
port_cell.take().recv();
};
assert!(res.is_err());
};
let _thread2 = do spawntask_thread {
let chan_cell = Cell(chan_cell.take());
let chan_cell = Cell::new(chan_cell.take());
do spawntask {
chan_cell.take();
}
Expand All @@ -569,8 +569,8 @@ mod test {
for stress_factor().times {
do run_in_newsched_task {
let (port, chan) = oneshot::<~int>();
let chan_cell = Cell(chan);
let port_cell = Cell(port);
let chan_cell = Cell::new(chan);
let port_cell = Cell::new(port);
let _thread1 = do spawntask_thread {
chan_cell.take().send(~10);
};
Expand All @@ -593,7 +593,7 @@ mod test {
fn send(chan: Chan<~int>, i: int) {
if i == 10 { return }

let chan_cell = Cell(chan);
let chan_cell = Cell::new(chan);
let _thread = do spawntask_thread {
let chan = chan_cell.take();
chan.send(~i);
Expand All @@ -604,7 +604,7 @@ mod test {
fn recv(port: Port<~int>, i: int) {
if i == 10 { return }

let port_cell = Cell(port);
let port_cell = Cell::new(port);
let _thread = do spawntask_thread {
let port = port_cell.take();
assert!(port.recv() == ~i);
Expand Down
Loading

3 comments on commit 8cb84f5

@bors
Copy link
Contributor

@bors bors commented on 8cb84f5 Jun 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from brson
at brson@8cb84f5

@bors
Copy link
Contributor

@bors bors commented on 8cb84f5 Jun 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging brson/rust/cell = 8cb84f5 into auto

@bors
Copy link
Contributor

@bors bors commented on 8cb84f5 Jun 5, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging brson/rust/cell = 8cb84f5 into auto failed

Please sign in to comment.