Skip to content

Commit 589beb9

Browse files
committed
Auto merge of #60921 - cuviper:remove-mpsc_select, r=SimonSapin
Remove the unstable and deprecated mpsc_select This removes macro `select!` and `std::sync::mpsc::{Handle, Select}`, which were all unstable and have been deprecated since 1.32. Closes #27800 r? @SimonSapin
2 parents caef1e8 + f950193 commit 589beb9

File tree

10 files changed

+9
-1130
lines changed

10 files changed

+9
-1130
lines changed

src/libstd/macros.rs

-55
Original file line numberDiff line numberDiff line change
@@ -357,61 +357,6 @@ macro_rules! dbg {
357357
};
358358
}
359359

360-
/// Selects the first successful receive event from a number of receivers.
361-
///
362-
/// This macro is used to wait for the first event to occur on a number of
363-
/// receivers. It places no restrictions on the types of receivers given to
364-
/// this macro, this can be viewed as a heterogeneous select.
365-
///
366-
/// # Examples
367-
///
368-
/// ```
369-
/// #![feature(mpsc_select)]
370-
///
371-
/// use std::thread;
372-
/// use std::sync::mpsc;
373-
///
374-
/// // two placeholder functions for now
375-
/// fn long_running_thread() {}
376-
/// fn calculate_the_answer() -> u32 { 42 }
377-
///
378-
/// let (tx1, rx1) = mpsc::channel();
379-
/// let (tx2, rx2) = mpsc::channel();
380-
///
381-
/// thread::spawn(move|| { long_running_thread(); tx1.send(()).unwrap(); });
382-
/// thread::spawn(move|| { tx2.send(calculate_the_answer()).unwrap(); });
383-
///
384-
/// select! {
385-
/// _ = rx1.recv() => println!("the long running thread finished first"),
386-
/// answer = rx2.recv() => {
387-
/// println!("the answer was: {}", answer.unwrap());
388-
/// }
389-
/// }
390-
/// # drop(rx1.recv());
391-
/// # drop(rx2.recv());
392-
/// ```
393-
///
394-
/// For more information about select, see the `std::sync::mpsc::Select` structure.
395-
#[macro_export]
396-
#[unstable(feature = "mpsc_select", issue = "27800")]
397-
#[rustc_deprecated(since = "1.32.0",
398-
reason = "channel selection will be removed in a future release")]
399-
macro_rules! select {
400-
(
401-
$($name:pat = $rx:ident.$meth:ident() => $code:expr),+
402-
) => ({
403-
use $crate::sync::mpsc::Select;
404-
let sel = Select::new();
405-
$( let mut $rx = sel.handle(&$rx); )+
406-
unsafe {
407-
$( $rx.add(); )+
408-
}
409-
let ret = sel.wait();
410-
$( if ret == $rx.id() { let $name = $rx.$meth(); $code } else )+
411-
{ unreachable!() }
412-
})
413-
}
414-
415360
#[cfg(test)]
416361
macro_rules! assert_approx_eq {
417362
($a:expr, $b:expr) => ({

src/libstd/sync/mpsc/mod.rs

+2-83
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
//! ```
117117
118118
#![stable(feature = "rust1", since = "1.0.0")]
119-
#![allow(deprecated)] // for mpsc_select
120119

121120
// A description of how Rust's channel implementation works
122121
//
@@ -263,6 +262,8 @@
263262
// believe that there is anything fundamental that needs to change about these
264263
// channels, however, in order to support a more efficient select().
265264
//
265+
// FIXME: Select is now removed, so these factors are ready to be cleaned up!
266+
//
266267
// # Conclusion
267268
//
268269
// And now that you've seen all the races that I found and attempted to fix,
@@ -275,18 +276,8 @@ use crate::mem;
275276
use crate::cell::UnsafeCell;
276277
use crate::time::{Duration, Instant};
277278

278-
#[unstable(feature = "mpsc_select", issue = "27800")]
279-
pub use self::select::{Select, Handle};
280-
use self::select::StartResult;
281-
use self::select::StartResult::*;
282-
use self::blocking::SignalToken;
283-
284-
#[cfg(all(test, not(target_os = "emscripten")))]
285-
mod select_tests;
286-
287279
mod blocking;
288280
mod oneshot;
289-
mod select;
290281
mod shared;
291282
mod stream;
292283
mod sync;
@@ -1514,78 +1505,6 @@ impl<T> Receiver<T> {
15141505

15151506
}
15161507

1517-
impl<T> select::Packet for Receiver<T> {
1518-
fn can_recv(&self) -> bool {
1519-
loop {
1520-
let new_port = match *unsafe { self.inner() } {
1521-
Flavor::Oneshot(ref p) => {
1522-
match p.can_recv() {
1523-
Ok(ret) => return ret,
1524-
Err(upgrade) => upgrade,
1525-
}
1526-
}
1527-
Flavor::Stream(ref p) => {
1528-
match p.can_recv() {
1529-
Ok(ret) => return ret,
1530-
Err(upgrade) => upgrade,
1531-
}
1532-
}
1533-
Flavor::Shared(ref p) => return p.can_recv(),
1534-
Flavor::Sync(ref p) => return p.can_recv(),
1535-
};
1536-
unsafe {
1537-
mem::swap(self.inner_mut(),
1538-
new_port.inner_mut());
1539-
}
1540-
}
1541-
}
1542-
1543-
fn start_selection(&self, mut token: SignalToken) -> StartResult {
1544-
loop {
1545-
let (t, new_port) = match *unsafe { self.inner() } {
1546-
Flavor::Oneshot(ref p) => {
1547-
match p.start_selection(token) {
1548-
oneshot::SelSuccess => return Installed,
1549-
oneshot::SelCanceled => return Abort,
1550-
oneshot::SelUpgraded(t, rx) => (t, rx),
1551-
}
1552-
}
1553-
Flavor::Stream(ref p) => {
1554-
match p.start_selection(token) {
1555-
stream::SelSuccess => return Installed,
1556-
stream::SelCanceled => return Abort,
1557-
stream::SelUpgraded(t, rx) => (t, rx),
1558-
}
1559-
}
1560-
Flavor::Shared(ref p) => return p.start_selection(token),
1561-
Flavor::Sync(ref p) => return p.start_selection(token),
1562-
};
1563-
token = t;
1564-
unsafe {
1565-
mem::swap(self.inner_mut(), new_port.inner_mut());
1566-
}
1567-
}
1568-
}
1569-
1570-
fn abort_selection(&self) -> bool {
1571-
let mut was_upgrade = false;
1572-
loop {
1573-
let result = match *unsafe { self.inner() } {
1574-
Flavor::Oneshot(ref p) => p.abort_selection(),
1575-
Flavor::Stream(ref p) => p.abort_selection(was_upgrade),
1576-
Flavor::Shared(ref p) => return p.abort_selection(was_upgrade),
1577-
Flavor::Sync(ref p) => return p.abort_selection(),
1578-
};
1579-
let new_port = match result { Ok(b) => return b, Err(p) => p };
1580-
was_upgrade = true;
1581-
unsafe {
1582-
mem::swap(self.inner_mut(),
1583-
new_port.inner_mut());
1584-
}
1585-
}
1586-
}
1587-
}
1588-
15891508
#[stable(feature = "rust1", since = "1.0.0")]
15901509
impl<'a, T> Iterator for Iter<'a, T> {
15911510
type Item = T;

src/libstd/sync/mpsc/oneshot.rs

-72
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
2525
pub use self::Failure::*;
2626
pub use self::UpgradeResult::*;
27-
pub use self::SelectionResult::*;
2827
use self::MyUpgrade::*;
2928

3029
use crate::sync::mpsc::Receiver;
@@ -66,12 +65,6 @@ pub enum UpgradeResult {
6665
UpWoke(SignalToken),
6766
}
6867

69-
pub enum SelectionResult<T> {
70-
SelCanceled,
71-
SelUpgraded(SignalToken, Receiver<T>),
72-
SelSuccess,
73-
}
74-
7568
enum MyUpgrade<T> {
7669
NothingSent,
7770
SendUsed,
@@ -264,71 +257,6 @@ impl<T> Packet<T> {
264257
// select implementation
265258
////////////////////////////////////////////////////////////////////////////
266259

267-
// If Ok, the value is whether this port has data, if Err, then the upgraded
268-
// port needs to be checked instead of this one.
269-
pub fn can_recv(&self) -> Result<bool, Receiver<T>> {
270-
unsafe {
271-
match self.state.load(Ordering::SeqCst) {
272-
EMPTY => Ok(false), // Welp, we tried
273-
DATA => Ok(true), // we have some un-acquired data
274-
DISCONNECTED if (*self.data.get()).is_some() => Ok(true), // we have data
275-
DISCONNECTED => {
276-
match ptr::replace(self.upgrade.get(), SendUsed) {
277-
// The other end sent us an upgrade, so we need to
278-
// propagate upwards whether the upgrade can receive
279-
// data
280-
GoUp(upgrade) => Err(upgrade),
281-
282-
// If the other end disconnected without sending an
283-
// upgrade, then we have data to receive (the channel is
284-
// disconnected).
285-
up => { ptr::write(self.upgrade.get(), up); Ok(true) }
286-
}
287-
}
288-
_ => unreachable!(), // we're the "one blocker"
289-
}
290-
}
291-
}
292-
293-
// Attempts to start selection on this port. This can either succeed, fail
294-
// because there is data, or fail because there is an upgrade pending.
295-
pub fn start_selection(&self, token: SignalToken) -> SelectionResult<T> {
296-
unsafe {
297-
let ptr = token.cast_to_usize();
298-
match self.state.compare_and_swap(EMPTY, ptr, Ordering::SeqCst) {
299-
EMPTY => SelSuccess,
300-
DATA => {
301-
drop(SignalToken::cast_from_usize(ptr));
302-
SelCanceled
303-
}
304-
DISCONNECTED if (*self.data.get()).is_some() => {
305-
drop(SignalToken::cast_from_usize(ptr));
306-
SelCanceled
307-
}
308-
DISCONNECTED => {
309-
match ptr::replace(self.upgrade.get(), SendUsed) {
310-
// The other end sent us an upgrade, so we need to
311-
// propagate upwards whether the upgrade can receive
312-
// data
313-
GoUp(upgrade) => {
314-
SelUpgraded(SignalToken::cast_from_usize(ptr), upgrade)
315-
}
316-
317-
// If the other end disconnected without sending an
318-
// upgrade, then we have data to receive (the channel is
319-
// disconnected).
320-
up => {
321-
ptr::write(self.upgrade.get(), up);
322-
drop(SignalToken::cast_from_usize(ptr));
323-
SelCanceled
324-
}
325-
}
326-
}
327-
_ => unreachable!(), // we're the "one blocker"
328-
}
329-
}
330-
}
331-
332260
// Remove a previous selecting thread from this port. This ensures that the
333261
// blocked thread will no longer be visible to any other threads.
334262
//

0 commit comments

Comments
 (0)