Skip to content

Commit 69f1e9d

Browse files
committed
libcore: Move Cell to core and de-~mut core and std
1 parent dcddfdd commit 69f1e9d

File tree

15 files changed

+60
-57
lines changed

15 files changed

+60
-57
lines changed

src/libstd/cell.rs renamed to src/libcore/cell.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use core::option;
12-
use core::prelude::*;
11+
use option;
12+
use prelude::*;
1313

1414
/// A dynamic, mutable location.
1515
///

src/libcore/core.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub mod dlist;
143143
#[path="iter-trait.rs"] #[merge = "iter-trait/dlist.rs"]
144144
pub mod dlist_iter;
145145
pub mod hashmap;
146+
pub mod cell;
146147

147148

148149
/* Tasks and communication */

src/libcore/pipes.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ bounded and unbounded protocols allows for less code duplication.
8686

8787
use cmp::Eq;
8888
use cast::{forget, reinterpret_cast, transmute};
89+
use cell::Cell;
8990
use either::{Either, Left, Right};
9091
use kinds::Owned;
9192
use libc;
@@ -917,11 +918,9 @@ pub fn spawn_service<T:Owned,Tb:Owned>(
917918
918919
// This is some nasty gymnastics required to safely move the pipe
919920
// into a new task.
920-
let server = ~mut Some(server);
921-
do task::spawn || {
922-
let mut server_ = None;
923-
server_ <-> *server;
924-
service(option::unwrap(server_))
921+
let server = Cell(server);
922+
do task::spawn {
923+
service(server.take());
925924
}
926925
927926
client
@@ -941,11 +940,9 @@ pub fn spawn_service_recv<T:Owned,Tb:Owned>(
941940
942941
// This is some nasty gymnastics required to safely move the pipe
943942
// into a new task.
944-
let server = ~mut Some(server);
945-
do task::spawn || {
946-
let mut server_ = None;
947-
server_ <-> *server;
948-
service(option::unwrap(server_))
943+
let server = Cell(server);
944+
do task::spawn {
945+
service(server.take())
949946
}
950947
951948
client

src/libcore/private.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,14 @@ fn compare_and_swap(address: &mut int, oldval: int, newval: int) -> bool {
107107
* Shared state & exclusive ARC
108108
****************************************************************************/
109109

110+
struct UnwrapProtoInner {
111+
contents: Option<(comm::ChanOne<()>, comm::PortOne<bool>)>,
112+
}
113+
110114
// An unwrapper uses this protocol to communicate with the "other" task that
111115
// drops the last refcount on an arc. Unfortunately this can't be a proper
112116
// pipe protocol because the unwrapper has to access both stages at once.
113-
type UnwrapProto = ~mut Option<(comm::ChanOne<()>, comm::PortOne<bool>)>;
117+
type UnwrapProto = ~UnwrapProtoInner;
114118

115119
struct ArcData<T> {
116120
mut count: libc::intptr_t,
@@ -139,9 +143,10 @@ struct ArcDestruct<T> {
139143
// reference. In effect, being here means we're the only
140144
// *awake* task with the data.
141145
if data.unwrapper != 0 {
142-
let p: UnwrapProto =
146+
let mut p: UnwrapProto =
143147
cast::reinterpret_cast(&data.unwrapper);
144-
let (message, response) = option::swap_unwrap(p);
148+
let (message, response) =
149+
option::swap_unwrap(&mut p.contents);
145150
// Send 'ready' and wait for a response.
146151
comm::send_one(message, ());
147152
// Unkillable wait. Message guaranteed to come.
@@ -196,7 +201,9 @@ pub unsafe fn unwrap_shared_mutable_state<T:Owned>(rc: SharedMutableState<T>)
196201
let ptr: ~ArcData<T> = cast::reinterpret_cast(&rc.data);
197202
let (p1,c1) = comm::oneshot(); // ()
198203
let (p2,c2) = comm::oneshot(); // bool
199-
let server: UnwrapProto = ~mut Some((c1,p2));
204+
let mut server: UnwrapProto = ~UnwrapProtoInner {
205+
contents: Some((c1,p2))
206+
};
200207
let serverp: int = cast::transmute(server);
201208
// Try to put our server end in the unwrapper slot.
202209
if compare_and_swap(&mut ptr.unwrapper, 0, serverp) {
@@ -409,8 +416,9 @@ pub fn unwrap_exclusive<T:Owned>(arc: Exclusive<T>) -> T {
409416
pub mod tests {
410417
use core::option::{None, Some};
411418
412-
use option;
419+
use cell::Cell;
413420
use comm;
421+
use option;
414422
use private::{exclusive, unwrap_exclusive};
415423
use result;
416424
use task;
@@ -423,7 +431,7 @@ pub mod tests {
423431
let num_tasks = 10;
424432
let count = 10;
425433
426-
let total = exclusive(~mut 0);
434+
let total = exclusive(~0);
427435
428436
for uint::range(0, num_tasks) |_i| {
429437
let total = total.clone();
@@ -472,21 +480,20 @@ pub mod tests {
472480
#[test]
473481
pub fn exclusive_unwrap_contended() {
474482
let x = exclusive(~~"hello");
475-
let x2 = ~mut Some(x.clone());
476-
do task::spawn || {
477-
let x2 = option::swap_unwrap(x2);
483+
let x2 = Cell(x.clone());
484+
do task::spawn {
485+
let x2 = option::swap_unwrap(x2.take());
478486
do x2.with |_hello| { }
479487
task::yield();
480488
}
481489
assert unwrap_exclusive(x) == ~~"hello";
482490
483491
// Now try the same thing, but with the child task blocking.
484492
let x = exclusive(~~"hello");
485-
let x2 = ~mut Some(x.clone());
493+
let x2 = Cell(x.clone());
486494
let mut res = None;
487-
do task::task().future_result(|+r| res = Some(r)).spawn
488-
|| {
489-
let x2 = option::swap_unwrap(x2);
495+
do task::task().future_result(|+r| res = Some(r)).spawn {
496+
let x2 = x2.take();
490497
assert unwrap_exclusive(x2) == ~~"hello";
491498
}
492499
// Have to get rid of our reference before blocking.
@@ -498,11 +505,10 @@ pub mod tests {
498505
#[test] #[should_fail] #[ignore(cfg(windows))]
499506
pub fn exclusive_unwrap_conflict() {
500507
let x = exclusive(~~"hello");
501-
let x2 = ~mut Some(x.clone());
508+
let x2 = Cell(x.clone());
502509
let mut res = None;
503-
do task::task().future_result(|+r| res = Some(r)).spawn
504-
|| {
505-
let x2 = option::swap_unwrap(x2);
510+
do task::task().future_result(|+r| res = Some(r)).spawn {
511+
let x2 = x2.take();
506512
assert unwrap_exclusive(x2) == ~~"hello";
507513
}
508514
assert unwrap_exclusive(x) == ~~"hello";

src/libcore/private/weak_task.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@ it is running, sending a notification to the task that the runtime
1818
is trying to shut down.
1919
*/
2020

21+
use cell::Cell;
22+
use comm::{GenericSmartChan, stream};
23+
use comm::{Port, Chan, SharedChan, GenericChan, GenericPort};
24+
use hashmap::linear::LinearMap;
25+
use ops::Drop;
2126
use option::{Some, None, swap_unwrap};
2227
use private::at_exit::at_exit;
23-
use private::global::global_data_clone_create;
2428
use private::finally::Finally;
25-
use comm::{Port, Chan, SharedChan, GenericChan,
26-
GenericPort, GenericSmartChan, stream};
27-
use task::{Task, task, spawn};
29+
use private::global::global_data_clone_create;
2830
use task::rt::{task_id, get_task_id};
29-
use hashmap::linear::LinearMap;
30-
use ops::Drop;
31+
use task::{Task, task, spawn};
3132

3233
type ShutdownMsg = ();
3334

@@ -37,14 +38,13 @@ pub unsafe fn weaken_task(f: &fn(Port<ShutdownMsg>)) {
3738
let service = global_data_clone_create(global_data_key,
3839
create_global_service);
3940
let (shutdown_port, shutdown_chan) = stream::<ShutdownMsg>();
40-
let shutdown_port = ~mut Some(shutdown_port);
41+
let shutdown_port = Cell(shutdown_port);
4142
let task = get_task_id();
4243
// Expect the weak task service to be alive
4344
assert service.try_send(RegisterWeakTask(task, shutdown_chan));
4445
unsafe { rust_dec_kernel_live_count(); }
4546
do fn&() {
46-
let shutdown_port = swap_unwrap(&mut *shutdown_port);
47-
f(shutdown_port)
47+
f(shutdown_port.take())
4848
}.finally || {
4949
unsafe { rust_inc_kernel_live_count(); }
5050
// Service my have already exited
@@ -67,16 +67,15 @@ fn create_global_service() -> ~WeakTaskService {
6767

6868
debug!("creating global weak task service");
6969
let (port, chan) = stream::<ServiceMsg>();
70-
let port = ~mut Some(port);
70+
let port = Cell(port);
7171
let chan = SharedChan(chan);
7272
let chan_clone = chan.clone();
7373

7474
do task().unlinked().spawn {
7575
debug!("running global weak task service");
76-
let port = swap_unwrap(&mut *port);
77-
let port = ~mut Some(port);
76+
let port = Cell(port.take());
7877
do fn&() {
79-
let port = swap_unwrap(&mut *port);
78+
let port = port.take();
8079
// The weak task service is itself a weak task
8180
debug!("weakening the weak service task");
8281
unsafe { rust_dec_kernel_live_count(); }

src/libcore/repr.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,6 @@ fn test_repr() {
602602
exact_test(&(@10), "@10");
603603
exact_test(&(@mut 10), "@10");
604604
exact_test(&(~10), "~10");
605-
exact_test(&(~mut 10), "~mut 10");
606605
exact_test(&(&10), "&10");
607606
let mut x = 10;
608607
exact_test(&(&mut x), "&mut 10");

src/libcore/task/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
*/
3535

3636
use cast;
37+
use cell::Cell;
3738
use cmp;
3839
use cmp::Eq;
3940
use iter;
@@ -397,9 +398,9 @@ impl TaskBuilder {
397398
}
398399
/// Runs a task, while transfering ownership of one argument to the child.
399400
fn spawn_with<A:Owned>(arg: A, f: fn~(v: A)) {
400-
let arg = ~mut Some(arg);
401-
do self.spawn || {
402-
f(option::swap_unwrap(arg))
401+
let arg = Cell(arg);
402+
do self.spawn {
403+
f(arg.take());
403404
}
404405
}
405406

src/libcore/task/spawn.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
#[doc(hidden)]; // FIXME #3538
7474

7575
use cast;
76+
use cell::Cell;
7677
use container::Map;
7778
use option;
7879
use comm::{Chan, GenericChan, GenericPort, Port, stream};
@@ -530,11 +531,11 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
530531
gen_child_taskgroup(opts.linked, opts.supervised);
531532

532533
unsafe {
533-
let child_data = ~mut Some((child_tg, ancestors, f));
534+
let child_data = Cell((child_tg, ancestors, f));
534535
// Being killed with the unsafe task/closure pointers would leak them.
535536
do unkillable {
536537
// Agh. Get move-mode items into the closure. FIXME (#2829)
537-
let (child_tg, ancestors, f) = option::swap_unwrap(child_data);
538+
let (child_tg, ancestors, f) = child_data.take();
538539
// Create child task.
539540
let new_task = match opts.sched.mode {
540541
DefaultScheduler => rt::new_task(),
@@ -571,10 +572,10 @@ pub fn spawn_raw(opts: TaskOpts, f: fn~()) {
571572
ancestors: AncestorList, is_main: bool,
572573
notify_chan: Option<Chan<TaskResult>>,
573574
f: fn~()) -> fn~() {
574-
let child_data = ~mut Some((child_arc, ancestors));
575+
let child_data = Cell((child_arc, ancestors));
575576
return fn~() {
576577
// Agh. Get move-mode items into the closure. FIXME (#2829)
577-
let mut (child_arc, ancestors) = option::swap_unwrap(child_data);
578+
let mut (child_arc, ancestors) = child_data.take();
578579
// Child task runs this code.
579580

580581
// Even if the below code fails to kick the child off, we must

src/librustc/middle/typeck/infer/region_inference.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,7 @@ use syntax::codemap;
549549
use util::common::indenter;
550550
use util::ppaux::note_and_explain_region;
551551

552+
use core::cell::{Cell, empty_cell};
552553
use core::cmp;
553554
use core::dvec::DVec;
554555
use core::to_bytes;
@@ -557,7 +558,6 @@ use core::vec;
557558
use result::Result;
558559
use result::{Ok, Err};
559560
use std::oldmap::HashMap;
560-
use std::cell::{Cell, empty_cell};
561561
use std::list::{List, Nil, Cons};
562562
use syntax::codemap::span;
563563
use syntax::codemap;

src/librustc/rustc.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ fails without recording a fatal error then we've encountered a compiler
314314
bug and need to present an error.
315315
*/
316316
pub fn monitor(+f: fn~(diagnostic::Emitter)) {
317+
use core::cell::Cell;
317318
use core::comm::*;
318-
use std::cell::Cell;
319319
let (p, ch) = stream();
320320
let ch = SharedChan(ch);
321321
let ch_capture = ch.clone();

src/librustdoc/astsrv.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use core::prelude::*;
2121

2222
use parse;
2323
use util;
24-
use std::cell::Cell;
2524

25+
use core::cell::Cell;
2626
use core::comm::{stream, Chan, SharedChan, Port};
2727
use core::vec;
2828
use core::ops::Drop;

src/librustdoc/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use core::prelude::*;
1212

13+
use core::cell::Cell;
1314
use core::cmp;
1415
use core::os;
1516
use core::result;
@@ -18,7 +19,6 @@ use core::run::ProgramOutput;
1819
use core::vec;
1920
use core::result::Result;
2021
use std::getopts;
21-
use std::cell::Cell;
2222

2323
/// The type of document to output
2424
pub enum OutputFormat {

src/librustdoc/markdown_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ use sort_pass;
3434
use trim_pass;
3535
use unindent_pass;
3636

37+
use core::cell::Cell;
3738
use core::iter;
3839
use core::str;
3940
use core::vec;
4041
use std::par;
41-
use std::cell::Cell;
4242
use syntax;
4343

4444
pub fn mk_pass(writer_factory: WriterFactory) -> Pass {

src/librustdoc/text_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ use fold;
2020
use pass::Pass;
2121
use util::NominalOp;
2222

23+
use core::cell::Cell;
2324
use std::par;
24-
use std::cell::Cell;
2525

2626
pub fn mk_pass(name: ~str, op: @fn(&str) -> ~str) -> Pass {
2727
let op = Cell(op);

src/libstd/std.rc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ pub mod uv_global_loop;
5454

5555
pub mod c_vec;
5656
pub mod timer;
57-
pub mod cell;
5857
pub mod io_util;
5958

6059
// Concurrency

0 commit comments

Comments
 (0)