Skip to content

Commit c936af4

Browse files
committed
Use tuples instead of explicit OfferNs
Definitely prettier, but we still need the BranchN constructs.
1 parent 471dddc commit c936af4

File tree

2 files changed

+20
-22
lines changed

2 files changed

+20
-22
lines changed

examples/atm.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ use session_types::*;
33
use std::thread::spawn;
44

55
type Id = String;
6-
type Atm = Recv<Id, Choose2<Rec<AtmInner>, Eps>>;
6+
type Atm = Recv<Id, Choose<(Rec<AtmInner>, Eps)>>;
77

8-
type AtmInner = Offer3<AtmDeposit,
8+
type AtmInner = Offer<(AtmDeposit,
99
AtmWithdraw,
10-
Eps>;
10+
Eps)>;
1111

1212
type AtmDeposit = Recv<u64, Send<u64, Var<Z>>>;
13-
type AtmWithdraw = Recv<u64, Choose2<Var<Z>, Var<Z>>>;
13+
type AtmWithdraw = Recv<u64, Choose<(Var<Z>, Var<Z>)>>;
1414

1515
type Client = <Atm as HasDual>::Dual;
1616

src/lib.rs

+16-18
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,10 @@ pub struct Recv<A, P> ( PhantomData<(A, P)> );
108108
pub struct Send<A, P> ( PhantomData<(A, P)> );
109109

110110
/// Active choice between `P` and `Q`
111-
pub struct Choose2<P, Q> ( PhantomData<(P, Q)> );
112-
pub struct Choose3<P, Q, R> ( PhantomData<(P, Q, R)> );
111+
pub struct Choose<T> ( PhantomData<T> );
113112

114113
/// Passive choice (offer) between `P` and `Q`
115-
pub struct Offer2<P, Q> ( PhantomData<(P, Q)> );
116-
pub struct Offer3<P, Q, R> ( PhantomData<(P, Q, R)> );
114+
pub struct Offer<T> ( PhantomData<T> );
117115

118116
/// Enter a recursive environment
119117
pub struct Rec<P> ( PhantomData<P> );
@@ -138,20 +136,20 @@ unsafe impl <A, P: HasDual> HasDual for Recv<A, P> {
138136
type Dual = Send<A, P::Dual>;
139137
}
140138

141-
unsafe impl <P: HasDual, Q: HasDual> HasDual for Choose2<P, Q> {
142-
type Dual = Offer2<P::Dual, Q::Dual>;
139+
unsafe impl <P: HasDual, Q: HasDual> HasDual for Choose<(P, Q)> {
140+
type Dual = Offer<(P::Dual, Q::Dual)>;
143141
}
144142

145-
unsafe impl <P: HasDual, Q: HasDual, R: HasDual> HasDual for Choose3<P, Q, R> {
146-
type Dual = Offer3<P::Dual, Q::Dual, R::Dual>;
143+
unsafe impl <P: HasDual, Q: HasDual, R: HasDual> HasDual for Choose<(P, Q, R)> {
144+
type Dual = Offer<(P::Dual, Q::Dual, R::Dual)>;
147145
}
148146

149-
unsafe impl <P: HasDual, Q: HasDual> HasDual for Offer2<P, Q> {
150-
type Dual = Choose2<P::Dual, Q::Dual>;
147+
unsafe impl <P: HasDual, Q: HasDual> HasDual for Offer<(P, Q)> {
148+
type Dual = Choose<(P::Dual, Q::Dual)>;
151149
}
152150

153-
unsafe impl <P: HasDual, Q: HasDual, R: HasDual> HasDual for Offer3<P, Q, R> {
154-
type Dual = Choose3<P::Dual, Q::Dual, R::Dual>;
151+
unsafe impl <P: HasDual, Q: HasDual, R: HasDual> HasDual for Offer<(P, Q, R)> {
152+
type Dual = Choose<(P::Dual, Q::Dual, R::Dual)>;
155153
}
156154

157155
unsafe impl HasDual for Var<Z> {
@@ -208,7 +206,7 @@ impl<E, P, A: marker::Send + 'static> Chan<E, Recv<A, P>> {
208206
}
209207
}
210208

211-
impl<E, P, Q> Chan<E, Choose2<P, Q>> {
209+
impl<E, P, Q> Chan<E, Choose<(P, Q)>> {
212210
/// Perform an active choice, selecting protocol `P`.
213211
#[must_use]
214212
pub fn sel1(self) -> Chan<E, P> {
@@ -228,7 +226,7 @@ impl<E, P, Q> Chan<E, Choose2<P, Q>> {
228226
}
229227
}
230228

231-
impl<E, P, Q> Chan<E, Offer2<P, Q>> {
229+
impl<E, P, Q> Chan<E, Offer<(P, Q)>> {
232230
/// Passive choice. This allows the other end of the channel to select one
233231
/// of two options for continuing the protocol: either `P` or `Q`.
234232
#[must_use]
@@ -244,7 +242,7 @@ impl<E, P, Q> Chan<E, Offer2<P, Q>> {
244242
}
245243
}
246244

247-
impl<E, P, Q, R> Chan<E, Choose3<P, Q, R>> {
245+
impl<E, P, Q, R> Chan<E, Choose<(P, Q, R)>> {
248246
/// Perform an active choice, selecting protocol `P`.
249247
#[must_use]
250248
pub fn sel1(self) -> Chan<E, P> {
@@ -273,7 +271,7 @@ impl<E, P, Q, R> Chan<E, Choose3<P, Q, R>> {
273271
}
274272
}
275273

276-
impl<E, P, Q, R> Chan<E, Offer3<P, Q, R>> {
274+
impl<E, P, Q, R> Chan<E, Offer<(P, Q, R)>> {
277275
/// Passive choice. This allows the other end of the channel to select one
278276
/// of two options for continuing the protocol: either `P` or `Q`.
279277
#[must_use]
@@ -390,7 +388,7 @@ impl<'c, T> ChanSelect<'c, T> {
390388
}
391389

392390
pub fn add_offer_ret<E, P, Q>(&mut self,
393-
chan: &'c Chan<E, Offer2<P, Q>>,
391+
chan: &'c Chan<E, Offer<(P, Q)>>,
394392
ret: T)
395393
{
396394
self.chans.push((unsafe { transmute(chan) }, ret));
@@ -443,7 +441,7 @@ impl<'c> ChanSelect<'c, usize> {
443441
}
444442

445443
pub fn add_offer<E, P, Q>(&mut self,
446-
c: &'c Chan<E, Offer2<P, Q>>)
444+
c: &'c Chan<E, Offer<(P, Q)>>)
447445
{
448446
let index = self.chans.len();
449447
self.add_offer_ret(c, index);

0 commit comments

Comments
 (0)