Skip to content

Commit bc83a00

Browse files
committed
std: Second pass stabilization for comm
This commit is a second pass stabilization for the `std::comm` module, performing the following actions: * The entire `std::comm` module was moved under `std::sync::mpsc`. This movement reflects that channels are just yet another synchronization primitive, and they don't necessarily deserve a special place outside of the other concurrency primitives that the standard library offers. * The `send` and `recv` methods have all been removed. * The `send_opt` and `recv_opt` methods have been renamed to `send` and `recv`. This means that all send/receive operations return a `Result` now indicating whether the operation was successful or not. * The error type of `send` is now a `SendError` to implement a custom error message and allow for `unwrap()`. The error type contains an `into_inner` method to extract the value. * The error type of `recv` is now `RecvError` for the same reasons as `send`. * The `TryRecvError` and `TrySendError` types have had public reexports removed of their variants and the variant names have been tweaked with enum namespacing rules. * The `Messages` iterator is renamed to `Iter` This functionality is now all `#[stable]`: * `Sender` * `SyncSender` * `Receiver` * `std::sync::mpsc` * `channel` * `sync_channel` * `Iter` * `Sender::send` * `Sender::clone` * `SyncSender::send` * `SyncSender::try_send` * `SyncSender::clone` * `Receiver::recv` * `Receiver::try_recv` * `Receiver::iter` * `SendError` * `RecvError` * `TrySendError::{mod, Full, Disconnected}` * `TryRecvError::{mod, Empty, Disconnected}` * `SendError::into_inner` * `TrySendError::into_inner` This is a breaking change due to the modification of where this module is located, as well as the changing of the semantics of `send` and `recv`. Most programs just need to rename imports of `std::comm` to `std::sync::mpsc` and add calls to `unwrap` after a send or a receive operation. [breaking-change]
1 parent bb8f4fc commit bc83a00

File tree

109 files changed

+1175
-1206
lines changed

Some content is hidden

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

109 files changed

+1175
-1206
lines changed

src/etc/licenseck.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
"rt/isaac/randport.cpp", # public domain
3939
"rt/isaac/rand.h", # public domain
4040
"rt/isaac/standard.h", # public domain
41-
"libstd/comm/mpsc_queue.rs", # BSD
42-
"libstd/comm/spsc_queue.rs", # BSD
41+
"libstd/sync/mpsc/mpsc_queue.rs", # BSD
42+
"libstd/sync/mpsc/spsc_queue.rs", # BSD
4343
"test/bench/shootout-binarytrees.rs", # BSD
4444
"test/bench/shootout-chameneos-redux.rs", # BSD
4545
"test/bench/shootout-fannkuch-redux.rs", # BSD

src/liballoc/arc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ impl<T: Default + Sync + Send> Default for Arc<T> {
592592
#[allow(experimental)]
593593
mod tests {
594594
use std::clone::Clone;
595-
use std::comm::channel;
595+
use std::sync::mpsc::channel;
596596
use std::mem::drop;
597597
use std::ops::Drop;
598598
use std::option::Option;
@@ -628,11 +628,11 @@ mod tests {
628628
let (tx, rx) = channel();
629629

630630
task::spawn(move || {
631-
let arc_v: Arc<Vec<int>> = rx.recv();
631+
let arc_v: Arc<Vec<int>> = rx.recv().unwrap();
632632
assert_eq!((*arc_v)[3], 4);
633633
});
634634

635-
tx.send(arc_v.clone());
635+
tx.send(arc_v.clone()).unwrap();
636636

637637
assert_eq!((*arc_v)[2], 3);
638638
assert_eq!((*arc_v)[4], 5);

src/libcollections/bit.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2452,7 +2452,7 @@ mod tests {
24522452

24532453
#[cfg(test)]
24542454
mod bitv_bench {
2455-
use std::prelude::*;
2455+
use std::prelude::v1::*;
24562456
use std::rand;
24572457
use std::rand::Rng;
24582458
use std::u32;
@@ -2947,7 +2947,7 @@ mod bitv_set_test {
29472947

29482948
#[cfg(test)]
29492949
mod bitv_set_bench {
2950-
use std::prelude::*;
2950+
use std::prelude::v1::*;
29512951
use std::rand;
29522952
use std::rand::Rng;
29532953
use std::u32;

src/librustc_driver/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ use rustc::DIAGNOSTICS;
5555

5656
use std::any::AnyRefExt;
5757
use std::cmp::Ordering::Equal;
58-
use std::comm::channel;
5958
use std::io;
6059
use std::iter::repeat;
6160
use std::os;
61+
use std::sync::mpsc::channel;
6262
use std::thread;
6363

6464
use rustc::session::early_error;

src/librustc_trans/back/write.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ use syntax::diagnostic;
2323
use syntax::diagnostic::{Emitter, Handler, Level, mk_handler};
2424

2525
use std::c_str::{ToCStr, CString};
26-
use std::comm::channel;
2726
use std::io::Command;
2827
use std::io::fs;
2928
use std::iter::Unfold;
3029
use std::ptr;
3130
use std::str;
3231
use std::mem;
3332
use std::sync::{Arc, Mutex};
33+
use std::sync::mpsc::channel;
3434
use std::thread;
3535
use libc::{c_uint, c_int, c_void};
3636

@@ -929,13 +929,13 @@ fn run_work_multithreaded(sess: &Session,
929929
}
930930
}
931931

932-
tx.take().unwrap().send(());
932+
tx.take().unwrap().send(()).unwrap();
933933
}).detach();
934934
}
935935

936936
let mut panicked = false;
937937
for rx in futures.into_iter() {
938-
match rx.recv_opt() {
938+
match rx.recv() {
939939
Ok(()) => {},
940940
Err(_) => {
941941
panicked = true;

src/librustc_trans/save/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1203,8 +1203,7 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DxrVisitor<'l, 'tcx> {
12031203
let glob_map = &self.analysis.glob_map;
12041204
let glob_map = glob_map.as_ref().unwrap();
12051205
if glob_map.contains_key(&id) {
1206-
let names = glob_map.index(&id);
1207-
for n in names.iter() {
1206+
for n in glob_map[id].iter() {
12081207
if name_string.len() > 0 {
12091208
name_string.push_str(", ");
12101209
}

src/librustdoc/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use std::cell::RefCell;
12-
use std::comm::channel;
12+
use std::sync::mpsc::channel;
1313
use std::dynamic_lib::DynamicLibrary;
1414
use std::io::{Command, TempDir};
1515
use std::io;

src/libstd/bitflags.rs

-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ macro_rules! bitflags {
273273
mod tests {
274274
use hash;
275275
use option::Option::{Some, None};
276-
use ops::{BitOr, BitAnd, BitXor, Sub, Not};
277276

278277
bitflags! {
279278
#[doc = "> The first principle is that you must not fool yourself — and"]

src/libstd/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ mod tests {
621621
#[test]
622622
fn test_unwrap() {
623623
let c_str = "hello".to_c_str();
624-
unsafe { libc::free(c_str.unwrap() as *mut libc::c_void) }
624+
unsafe { libc::free(c_str.into_inner() as *mut libc::c_void) }
625625
}
626626

627627
#[test]

src/libstd/c_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ mod tests {
228228
let cv = CVec::new_with_dtor(1 as *mut int,
229229
0,
230230
move|:| panic!("Don't run this destructor!"));
231-
let p = cv.unwrap();
231+
let p = cv.into_inner();
232232
assert_eq!(p, 1 as *mut int);
233233
}
234234
}

src/libstd/collections/hash/map.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,7 @@ mod test_map {
14851485

14861486
struct KindaIntLike(int);
14871487

1488+
#[allow(deprecated)]
14881489
impl Equiv<int> for KindaIntLike {
14891490
fn equiv(&self, other: &int) -> bool {
14901491
let KindaIntLike(this) = *self;
@@ -1812,7 +1813,7 @@ mod test_map {
18121813
}
18131814

18141815
#[test]
1815-
#[allow(experimental)]
1816+
#[allow(deprecated)]
18161817
fn test_pop_equiv() {
18171818
let mut m = HashMap::new();
18181819
m.insert(1i, 2i);

src/libstd/io/buffered.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,7 @@ mod test {
533533
w.write(&[0, 1]).unwrap();
534534
let a: &[_] = &[];
535535
assert_eq!(a, w.get_ref()[]);
536-
let w = w.unwrap();
536+
let w = w.into_inner();
537537
let a: &[_] = &[0, 1];
538538
assert_eq!(a, w[]);
539539
}

src/libstd/io/comm_adapters.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use clone::Clone;
1212
use cmp;
13-
use comm::{Sender, Receiver};
13+
use sync::mpsc::{Sender, Receiver};
1414
use io;
1515
use option::Option::{None, Some};
1616
use result::Result::{Ok, Err};
@@ -23,7 +23,7 @@ use vec::Vec;
2323
/// # Example
2424
///
2525
/// ```
26-
/// use std::comm::channel;
26+
/// use std::sync::mpsc::channel;
2727
/// use std::io::ChanReader;
2828
///
2929
/// let (tx, rx) = channel();
@@ -59,11 +59,11 @@ impl Buffer for ChanReader {
5959
fn fill_buf<'a>(&'a mut self) -> IoResult<&'a [u8]> {
6060
if self.pos >= self.buf.len() {
6161
self.pos = 0;
62-
match self.rx.recv_opt() {
62+
match self.rx.recv() {
6363
Ok(bytes) => {
6464
self.buf = bytes;
6565
},
66-
Err(()) => {
66+
Err(..) => {
6767
self.closed = true;
6868
self.buf = Vec::new();
6969
}
@@ -115,7 +115,7 @@ impl Reader for ChanReader {
115115
///
116116
/// ```
117117
/// # #![allow(unused_must_use)]
118-
/// use std::comm::channel;
118+
/// use std::sync::mpsc::channel;
119119
/// use std::io::ChanWriter;
120120
///
121121
/// let (tx, rx) = channel();
@@ -143,7 +143,7 @@ impl Clone for ChanWriter {
143143

144144
impl Writer for ChanWriter {
145145
fn write(&mut self, buf: &[u8]) -> IoResult<()> {
146-
self.tx.send_opt(buf.to_vec()).map_err(|_| {
146+
self.tx.send(buf.to_vec()).map_err(|_| {
147147
io::IoError {
148148
kind: io::BrokenPipe,
149149
desc: "Pipe closed",
@@ -158,7 +158,7 @@ impl Writer for ChanWriter {
158158
mod test {
159159
use prelude::v1::*;
160160

161-
use comm::channel;
161+
use sync::mpsc::channel;
162162
use super::*;
163163
use io;
164164
use thread::Thread;
@@ -167,11 +167,11 @@ mod test {
167167
fn test_rx_reader() {
168168
let (tx, rx) = channel();
169169
Thread::spawn(move|| {
170-
tx.send(vec![1u8, 2u8]);
171-
tx.send(vec![]);
172-
tx.send(vec![3u8, 4u8]);
173-
tx.send(vec![5u8, 6u8]);
174-
tx.send(vec![7u8, 8u8]);
170+
tx.send(vec![1u8, 2u8]).unwrap();
171+
tx.send(vec![]).unwrap();
172+
tx.send(vec![3u8, 4u8]).unwrap();
173+
tx.send(vec![5u8, 6u8]).unwrap();
174+
tx.send(vec![7u8, 8u8]).unwrap();
175175
}).detach();
176176

177177
let mut reader = ChanReader::new(rx);
@@ -209,12 +209,12 @@ mod test {
209209
fn test_rx_buffer() {
210210
let (tx, rx) = channel();
211211
Thread::spawn(move|| {
212-
tx.send(b"he".to_vec());
213-
tx.send(b"llo wo".to_vec());
214-
tx.send(b"".to_vec());
215-
tx.send(b"rld\nhow ".to_vec());
216-
tx.send(b"are you?".to_vec());
217-
tx.send(b"".to_vec());
212+
tx.send(b"he".to_vec()).unwrap();
213+
tx.send(b"llo wo".to_vec()).unwrap();
214+
tx.send(b"".to_vec()).unwrap();
215+
tx.send(b"rld\nhow ".to_vec()).unwrap();
216+
tx.send(b"are you?".to_vec()).unwrap();
217+
tx.send(b"".to_vec()).unwrap();
218218
}).detach();
219219

220220
let mut reader = ChanReader::new(rx);
@@ -234,7 +234,7 @@ mod test {
234234
writer.write_be_u32(42).unwrap();
235235

236236
let wanted = vec![0u8, 0u8, 0u8, 42u8];
237-
let got = match Thread::spawn(move|| { rx.recv() }).join() {
237+
let got = match Thread::spawn(move|| { rx.recv().unwrap() }).join() {
238238
Ok(got) => got,
239239
Err(_) => panic!(),
240240
};

src/libstd/io/mem.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ mod test {
402402
use prelude::v1::*;
403403

404404
use super::*;
405-
use io::*;
406405
use io;
406+
use io::{SeekSet, SeekCur, SeekEnd};
407407
use self::test_crate::Bencher;
408408

409409
#[test]

0 commit comments

Comments
 (0)