Skip to content
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

RFC: Introduce Mut<T>, remove Cell<T> #9429

Closed
wants to merge 8 commits into from
Closed
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
2 changes: 1 addition & 1 deletion doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -1875,7 +1875,7 @@ unless they contain managed boxes, managed closures, or borrowed pointers.
* `Freeze` - Constant (immutable) types.
These are types that do not contain anything intrinsically mutable.
Intrinsically mutable values include `@mut`
and `Cell` in the standard library.
and `Mut` in the standard library.

* `'static` - Non-borrowed types.
These are types that do not contain any data whose lifetime is bound to
Expand Down
17 changes: 9 additions & 8 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

extern mod extra;

use std::mutable::Mut;
use std::os;
use std::rt;

Expand Down Expand Up @@ -317,15 +318,15 @@ 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 testfile = Cell::new(testfile.to_str());
test::DynTestFn(|| { runtest::run(config.take(), testfile.take()) })
let config = Mut::new_some((*config).clone());
let testfile = Mut::new_some(testfile.to_str());
test::DynTestFn(|| { runtest::run(config.take_unwrap(), testfile.take_unwrap()) })
}

pub fn make_metrics_test_closure(config: &config, testfile: &Path) -> test::TestFn {
use std::cell::Cell;
let config = Cell::new((*config).clone());
let testfile = Cell::new(testfile.to_str());
test::DynMetricFn(|mm| { runtest::run_metrics(config.take(), testfile.take(), mm) })
let config = Mut::new_some((*config).clone());
let testfile = Mut::new_some(testfile.to_str());
do test::DynMetricFn |mm| {
runtest::run_metrics(config.take_unwrap(), testfile.take_unwrap(), mm)
}
}
15 changes: 8 additions & 7 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ use procsrv;
use util;
use util::logv;

use std::cell::Cell;

use std::io;
use std::mutable::Mut;
use std::os;
use std::str;
use std::task::{spawn_sched, SingleThreaded};
Expand All @@ -31,8 +32,8 @@ use std::unstable::running_on_valgrind;
use extra::test::MetricMap;

pub fn run(config: config, testfile: ~str) {
let config = Cell::new(config);
let testfile = Cell::new(testfile);
let config = Mut::new_some(config);
let testfile = Mut::new_some(testfile);
// FIXME #6436: Creating another thread to run the test because this
// is going to call waitpid. The new scheduler has some strange
// interaction between the blocking tasks and 'friend' schedulers
Expand All @@ -43,14 +44,14 @@ pub fn run(config: config, testfile: ~str) {
// We do _not_ create another thread if we're running on V because
// it serializes all threads anyways.
if running_on_valgrind() {
let config = config.take();
let testfile = testfile.take();
let config = config.take_unwrap();
let testfile = testfile.take_unwrap();
let mut _mm = MetricMap::new();
run_metrics(config, testfile, &mut _mm);
} else {
do spawn_sched(SingleThreaded) {
let config = config.take();
let testfile = testfile.take();
let config = config.take_unwrap();
let testfile = testfile.take_unwrap();
let mut _mm = MetricMap::new();
run_metrics(config, testfile, &mut _mm);
}
Expand Down
9 changes: 4 additions & 5 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,12 +593,11 @@ impl<'self, T:Freeze + Send> RWReadMode<'self, T> {

#[cfg(test)]
mod tests {

use arc::*;

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

#[test]
fn manually_share_arc() {
Expand Down Expand Up @@ -627,18 +626,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));
let (c,p) = (Mut::new_some(c), Mut::new_some(p));
do task::spawn || {
// wait until parent gets in
p.take().recv();
p.take_unwrap().recv();
do arc2.access_cond |state, cond| {
*state = true;
cond.signal();
}
}

do arc.access_cond |state, cond| {
c.take().send(());
c.take_unwrap().send(());
assert!(!*state);
while !*state {
cond.wait();
Expand Down
10 changes: 5 additions & 5 deletions src/libextra/flatpipes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ mod test {
use io_util::BufReader;

use std::io::BytesWriter;
use std::mutable::Mut;
use std::task;

#[test]
Expand Down Expand Up @@ -768,7 +769,6 @@ mod test {
writer_chan: WriterChanFactory<F>,
port: uint) {

use std::cell::Cell;
use std::comm;
use std::result;
use net::ip;
Expand All @@ -785,15 +785,15 @@ mod test {

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

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

// The server task
let addr = addr0.clone();
do task::spawn || {
let iotask = &uv::global_loop::get();
let begin_connect_chan = begin_connect_chan.take();
let accept_chan = accept_chan.take();
let begin_connect_chan = begin_connect_chan.take_unwrap();
let accept_chan = accept_chan.take_unwrap();
let listen_res = do tcp::listen(
addr.clone(), port, 128, iotask, |_kill_ch| {
// Tell the sender to initiate the connection
Expand Down
17 changes: 9 additions & 8 deletions src/libextra/future.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@


use std::cast;
use std::cell::Cell;

use std::comm::{PortOne, oneshot};
use std::mutable::Mut;
use std::task;
use std::util::replace;

Expand Down Expand Up @@ -121,9 +122,9 @@ pub fn from_port<A:Send>(port: PortOne<A>) -> Future<A> {
* waiting for the result to be received on the port.
*/

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

Expand All @@ -149,9 +150,9 @@ pub fn spawn<A:Send>(blk: ~fn() -> A) -> Future<A> {

let (port, chan) = oneshot();

let chan = Cell::new(chan);
let chan = Mut::new_some(chan);
do task::spawn {
let chan = chan.take();
let chan = chan.take_unwrap();
chan.send(blk());
}

Expand All @@ -162,8 +163,8 @@ pub fn spawn<A:Send>(blk: ~fn() -> A) -> Future<A> {
mod test {
use future::*;

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

#[test]
Expand Down Expand Up @@ -220,9 +221,9 @@ mod test {
#[test]
fn test_sendable_future() {
let expected = "schlorf";
let f = Cell::new(do spawn { expected });
let f = Mut::new_some(do spawn { expected });
do task::spawn {
let mut f = f.take();
let mut f = f.take_unwrap();
let actual = f.get();
assert_eq!(actual, expected);
}
Expand Down
Loading