Skip to content

Commit ca2778e

Browse files
committed
auto merge of #15286 : alexcrichton/rust/channel-stability, r=cmr
* channel() - #[unstable]. This will likely remain forever * sync_channel(n: int) - #[unstable with comment]. Concerns have ben raised about the usage of the term "synchronous channel" because that generally only applies to the case where n == 0. If n > 0 then these channels are often referred to as buffered channels. * Sender::send(), SyncSender::send(), Receiver::recv() - #[experimental]. These functions directly violate the general guideline of not providing a failing and non-failing variant. These functions were explicitly selected for being excused from this guideline, but recent discussions have cast doubt on that decision. These functions are #[experimental] for now until a decision is made as they are candidates for removal. * Sender::send_opt(), SyncSender::send_opt(), Receiver::recv_opt() - #[unstable with a comment]. If the above no-`_opt` functions are removed, these functions will be renamed to the non-`_opt` variants. * SyncSender::try_send(), Receiver::try_recv() - #[unstable with a comment]. These return types of these functions to not follow general conventions. They are consistent with the rest of the api, but not with the rest of the libraries. Until their return types are nailed down, these functions are #[unstable]. * Receiver::iter() - #[unstable]. This will likely remain forever. * std::com::select - #[experimental]. The functionality is likely to remain in some form forever, but it is highly unlikely to remain in its current form. It is unknown how much breakage this will cause if and when the api is redesigned, so the entire module and its components are all experimental. * DuplexStream - #[deprecated]. This type is not composable with other channels in terms of selection or other expected locations. It can also not be used with ChanWriter and ChanReader, for example. Due to it being only lightly used, and easily replaced with two channels, this type is being deprecated and slated for removal. * Clone for {,Sync}Sender - #[unstable]. This will likely remain forever.
2 parents cb220a8 + 58133ae commit ca2778e

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

src/doc/guide-tasks.md

+4
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,8 @@ the string in response. The child terminates when it receives `0`.
457457
Here is the function that implements the child task:
458458

459459
~~~
460+
#![allow(deprecated)]
461+
460462
use std::comm::DuplexStream;
461463
# fn main() {
462464
fn stringifier(channel: &DuplexStream<String, uint>) {
@@ -481,6 +483,8 @@ response itself is simply the stringified version of the received value,
481483
Here is the code for the parent task:
482484

483485
~~~
486+
#![allow(deprecated)]
487+
484488
use std::comm::duplex;
485489
# use std::task::spawn;
486490
# use std::comm::DuplexStream;

src/libsync/comm/duplex.rs

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ Higher level communication abstractions.
1515
*/
1616

1717
#![allow(missing_doc)]
18+
#![deprecated = "This type is replaced by having a pair of channels. This type \
19+
is not fully composable with other channels in terms of \
20+
or possible semantics on a duplex stream. It will be removed \
21+
soon"]
1822

1923
use core::prelude::*;
2024

src/libsync/comm/mod.rs

+25
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,7 @@ static RESCHED_FREQ: int = 256;
370370

371371
/// The receiving-half of Rust's channel type. This half can only be owned by
372372
/// one task
373+
#[unstable]
373374
pub struct Receiver<T> {
374375
inner: Unsafe<Flavor<T>>,
375376
receives: Cell<uint>,
@@ -380,12 +381,14 @@ pub struct Receiver<T> {
380381
/// An iterator over messages on a receiver, this iterator will block
381382
/// whenever `next` is called, waiting for a new message, and `None` will be
382383
/// returned when the corresponding channel has hung up.
384+
#[unstable]
383385
pub struct Messages<'a, T> {
384386
rx: &'a Receiver<T>
385387
}
386388

387389
/// The sending-half of Rust's asynchronous channel type. This half can only be
388390
/// owned by one task, but it can be cloned to send to other tasks.
391+
#[unstable]
389392
pub struct Sender<T> {
390393
inner: Unsafe<Flavor<T>>,
391394
sends: Cell<uint>,
@@ -395,6 +398,7 @@ pub struct Sender<T> {
395398

396399
/// The sending-half of Rust's synchronous channel type. This half can only be
397400
/// owned by one task, but it can be cloned to send to other tasks.
401+
#[unstable = "this type may be renamed, but it will always exist"]
398402
pub struct SyncSender<T> {
399403
inner: Arc<Unsafe<sync::Packet<T>>>,
400404
// can't share in an arc
@@ -404,6 +408,7 @@ pub struct SyncSender<T> {
404408
/// This enumeration is the list of the possible reasons that try_recv could not
405409
/// return data when called.
406410
#[deriving(PartialEq, Clone, Show)]
411+
#[experimental = "this is likely to be removed in changing try_recv()"]
407412
pub enum TryRecvError {
408413
/// This channel is currently empty, but the sender(s) have not yet
409414
/// disconnected, so data may yet become available.
@@ -416,6 +421,7 @@ pub enum TryRecvError {
416421
/// This enumeration is the list of the possible error outcomes for the
417422
/// `SyncSender::try_send` method.
418423
#[deriving(PartialEq, Clone, Show)]
424+
#[experimental = "this is likely to be removed in changing try_send()"]
419425
pub enum TrySendError<T> {
420426
/// The data could not be sent on the channel because it would require that
421427
/// the callee block to send the data.
@@ -478,6 +484,7 @@ impl<T> UnsafeFlavor<T> for Receiver<T> {
478484
/// // Let's see what that answer was
479485
/// println!("{}", rx.recv());
480486
/// ```
487+
#[unstable]
481488
pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
482489
let a = Arc::new(Unsafe::new(oneshot::Packet::new()));
483490
(Sender::new(Oneshot(a.clone())), Receiver::new(Oneshot(a)))
@@ -514,6 +521,8 @@ pub fn channel<T: Send>() -> (Sender<T>, Receiver<T>) {
514521
/// assert_eq!(rx.recv(), 1i);
515522
/// assert_eq!(rx.recv(), 2i);
516523
/// ```
524+
#[unstable = "this function may be renamed to more accurately reflect the type \
525+
of channel that is is creating"]
517526
pub fn sync_channel<T: Send>(bound: uint) -> (SyncSender<T>, Receiver<T>) {
518527
let a = Arc::new(Unsafe::new(sync::Packet::new(bound)));
519528
(SyncSender::new(a.clone()), Receiver::new(Sync(a)))
@@ -547,6 +556,8 @@ impl<T: Send> Sender<T> {
547556
///
548557
/// The purpose of this functionality is to propagate failure among tasks.
549558
/// If failure is not desired, then consider using the `send_opt` method
559+
#[experimental = "this function is being considered candidate for removal \
560+
to adhere to the general guidelines of rust"]
550561
pub fn send(&self, t: T) {
551562
if self.send_opt(t).is_err() {
552563
fail!("sending on a closed channel");
@@ -583,6 +594,7 @@ impl<T: Send> Sender<T> {
583594
/// drop(rx);
584595
/// assert_eq!(tx.send_opt(1i), Err(1));
585596
/// ```
597+
#[unstable = "this function may be renamed to send() in the future"]
586598
pub fn send_opt(&self, t: T) -> Result<(), T> {
587599
// In order to prevent starvation of other tasks in situations where
588600
// a task sends repeatedly without ever receiving, we occasionally
@@ -638,6 +650,7 @@ impl<T: Send> Sender<T> {
638650
}
639651
}
640652

653+
#[unstable]
641654
impl<T: Send> Clone for Sender<T> {
642655
fn clone(&self) -> Sender<T> {
643656
let (packet, sleeper) = match *unsafe { self.inner() } {
@@ -719,6 +732,8 @@ impl<T: Send> SyncSender<T> {
719732
/// If failure is not desired, you can achieve the same semantics with the
720733
/// `SyncSender::send_opt` method which will not fail if the receiver
721734
/// disconnects.
735+
#[experimental = "this function is being considered candidate for removal \
736+
to adhere to the general guidelines of rust"]
722737
pub fn send(&self, t: T) {
723738
if self.send_opt(t).is_err() {
724739
fail!("sending on a closed channel");
@@ -736,6 +751,7 @@ impl<T: Send> SyncSender<T> {
736751
/// # Failure
737752
///
738753
/// This function cannot fail.
754+
#[unstable = "this function may be renamed to send() in the future"]
739755
pub fn send_opt(&self, t: T) -> Result<(), T> {
740756
unsafe { (*self.inner.get()).send(t) }
741757
}
@@ -753,11 +769,14 @@ impl<T: Send> SyncSender<T> {
753769
/// # Failure
754770
///
755771
/// This function cannot fail
772+
#[unstable = "the return type of this function is candidate for \
773+
modification"]
756774
pub fn try_send(&self, t: T) -> Result<(), TrySendError<T>> {
757775
unsafe { (*self.inner.get()).try_send(t) }
758776
}
759777
}
760778

779+
#[unstable]
761780
impl<T: Send> Clone for SyncSender<T> {
762781
fn clone(&self) -> SyncSender<T> {
763782
unsafe { (*self.inner.get()).clone_chan(); }
@@ -800,6 +819,8 @@ impl<T: Send> Receiver<T> {
800819
///
801820
/// * If blocking is not desired, then the `try_recv` method will attempt to
802821
/// peek at a value on this receiver.
822+
#[experimental = "this function is being considered candidate for removal \
823+
to adhere to the general guidelines of rust"]
803824
pub fn recv(&self) -> T {
804825
match self.recv_opt() {
805826
Ok(t) => t,
@@ -817,6 +838,7 @@ impl<T: Send> Receiver<T> {
817838
/// block on a receiver.
818839
///
819840
/// This function cannot fail.
841+
#[unstable = "the return type of this function may be altered"]
820842
pub fn try_recv(&self) -> Result<T, TryRecvError> {
821843
// If a thread is spinning in try_recv, we should take the opportunity
822844
// to reschedule things occasionally. See notes above in scheduling on
@@ -881,6 +903,7 @@ impl<T: Send> Receiver<T> {
881903
///
882904
/// If the channel has hung up, then `Err` is returned. Otherwise `Ok` of
883905
/// the value found on the receiver is returned.
906+
#[unstable = "this function may be renamed to recv()"]
884907
pub fn recv_opt(&self) -> Result<T, ()> {
885908
loop {
886909
let new_port = match *unsafe { self.inner() } {
@@ -917,6 +940,7 @@ impl<T: Send> Receiver<T> {
917940

918941
/// Returns an iterator which will block waiting for messages, but never
919942
/// `fail!`. It will return `None` when the channel has hung up.
943+
#[unstable]
920944
pub fn iter<'a>(&'a self) -> Messages<'a, T> {
921945
Messages { rx: self }
922946
}
@@ -1009,6 +1033,7 @@ impl<T: Send> select::Packet for Receiver<T> {
10091033
}
10101034
}
10111035

1036+
#[unstable]
10121037
impl<'a, T: Send> Iterator<T> for Messages<'a, T> {
10131038
fn next(&mut self) -> Option<T> { self.rx.recv_opt().ok() }
10141039
}

src/libsync/comm/select.rs

+7
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@
4444
//! ```
4545
4646
#![allow(dead_code)]
47+
#![experimental = "This implementation, while likely sufficient, is unsafe and \
48+
likely to be error prone. At some point in the future this \
49+
module will likely be replaced, and it is currently \
50+
unknown how much API breakage that will cause. The ability \
51+
to select over a number of channels will remain forever, \
52+
but no guarantees beyond this are being made"]
53+
4754

4855
use core::prelude::*;
4956

0 commit comments

Comments
 (0)