Skip to content

Commit b229162

Browse files
committed
Remove StreamLike trait
Signed-off-by: Moritz Hoffmann <[email protected]>
1 parent 0fdc20c commit b229162

38 files changed

+283
-326
lines changed

timely/examples/unionfind.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ fn main() {
4747
}).unwrap(); // asserts error-free execution;
4848
}
4949

50-
trait UnionFind<G: Scope> {
51-
fn union_find(self) -> OwnedStream<G, Vec<(usize, usize)>>;
50+
trait UnionFind {
51+
fn union_find(self) -> Self;
5252
}
5353

54-
impl<G: Scope, S: StreamLike<G, Vec<(usize, usize)>>> UnionFind<G> for S {
55-
fn union_find(self) -> OwnedStream<G, Vec<(usize, usize)>> {
54+
impl<G: Scope> UnionFind for Stream<G, (usize, usize)> {
55+
fn union_find(self) -> Stream<G, (usize, usize)> {
5656

5757
self.unary(Pipeline, "UnionFind", |_,_| {
5858

timely/examples/wordcount.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ fn main() {
1717
// create a new input, exchange data, and inspect its output
1818
worker.dataflow::<usize,_,_>(|scope| {
1919
input.to_stream(scope)
20+
.container::<Vec<_>>()
2021
.flat_map(|(text, diff): (String, i64)|
2122
text.split_whitespace()
2223
.map(move |word| (word.to_owned(), diff))
2324
.collect::<Vec<_>>()
2425
)
26+
.container::<Vec<_>>()
2527
.unary_frontier(exchange, "WordCount", |_capability, _info| {
2628

2729
let mut queues = HashMap::new();

timely/src/dataflow/channels/pushers/owned.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ impl<T, D> PushOwned<T, D> {
1919
}
2020

2121
/// Set the downstream pusher.
22-
pub fn set<P: Push<Message<T, D>> + 'static>(self, pusher: P) {
22+
///
23+
/// Consumes `Self` as only a single pusher can be set.
24+
pub fn set_pusher<P: Push<Message<T, D>> + 'static>(self, pusher: P) {
2325
*self.0.borrow_mut() = Some(Box::new(pusher));
2426
}
2527
}

timely/src/dataflow/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
//! });
1414
//! ```
1515
16-
pub use self::stream::{StreamCore, Stream, StreamLike, OwnedStream};
16+
pub use self::stream::{StreamTee, Stream, StreamCore};
1717
pub use self::scopes::{Scope, ScopeParent};
1818

1919
pub use self::operators::core::input::Handle as InputHandleCore;

timely/src/dataflow/operators/aggregation/aggregate.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::hash::Hash;
33
use std::collections::HashMap;
44

55
use crate::ExchangeData;
6-
use crate::dataflow::{Scope, StreamLike, OwnedStream};
6+
use crate::dataflow::{Stream, Scope};
77
use crate::dataflow::operators::generic::operator::Operator;
88
use crate::dataflow::channels::pact::Exchange;
99

@@ -64,22 +64,16 @@ pub trait Aggregate<S: Scope, K: ExchangeData+Hash, V: ExchangeData> {
6464
self,
6565
fold: F,
6666
emit: E,
67-
hash: H) -> OwnedStream<S, Vec<R>> where S::Timestamp: Eq;
67+
hash: H) -> Stream<S, R> where S::Timestamp: Eq;
6868
}
6969

70-
impl<G, K, V, S> Aggregate<G, K, V> for S
71-
where
72-
G: Scope,
73-
K: ExchangeData + Hash + Eq + Clone,
74-
V: ExchangeData,
75-
S: StreamLike<G, Vec<(K, V)>>,
76-
{
70+
impl<S: Scope, K: ExchangeData+Hash+Eq+Clone, V: ExchangeData> Aggregate<S, K, V> for Stream<S, (K, V)> {
7771

7872
fn aggregate<R: 'static, D: Default+'static, F: Fn(&K, V, &mut D)+'static, E: Fn(K, D)->R+'static, H: Fn(&K)->u64+'static>(
7973
self,
8074
fold: F,
8175
emit: E,
82-
hash: H) -> OwnedStream<G, Vec<R>> where G::Timestamp: Eq {
76+
hash: H) -> Stream<S, R> where S::Timestamp: Eq {
8377

8478
let mut aggregates = HashMap::new();
8579
self.unary_notify(Exchange::new(move |(k, _)| hash(k)), "Aggregate", vec![], move |input, output, notificator| {

timely/src/dataflow/operators/aggregation/state_machine.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::hash::Hash;
33
use std::collections::HashMap;
44

55
use crate::ExchangeData;
6-
use crate::dataflow::{OwnedStream, Scope, StreamLike};
6+
use crate::dataflow::{Stream, Scope};
77
use crate::dataflow::operators::generic::operator::Operator;
88
use crate::dataflow::channels::pact::Exchange;
99

@@ -51,23 +51,17 @@ pub trait StateMachine<S: Scope, K: ExchangeData+Hash+Eq, V: ExchangeData> {
5151
I: IntoIterator<Item=R>, // type of output iterator
5252
F: Fn(&K, V, &mut D)->(bool, I)+'static, // state update logic
5353
H: Fn(&K)->u64+'static, // "hash" function for keys
54-
>(self, fold: F, hash: H) -> OwnedStream<S, Vec<R>> where S::Timestamp : Hash+Eq ;
54+
>(self, fold: F, hash: H) -> Stream<S, R> where S::Timestamp : Hash+Eq ;
5555
}
5656

57-
impl<G, K, V, S> StateMachine<G, K, V> for S
58-
where
59-
G: Scope,
60-
K: ExchangeData + Hash + Eq + Clone,
61-
V: ExchangeData,
62-
S: StreamLike<G, Vec<(K, V)>>,
63-
{
57+
impl<S: Scope, K: ExchangeData+Hash+Eq+Clone, V: ExchangeData> StateMachine<S, K, V> for Stream<S, (K, V)> {
6458
fn state_machine<
6559
R: 'static, // output type
6660
D: Default+'static, // per-key state (data)
6761
I: IntoIterator<Item=R>, // type of output iterator
6862
F: Fn(&K, V, &mut D)->(bool, I)+'static, // state update logic
6963
H: Fn(&K)->u64+'static, // "hash" function for keys
70-
>(self, fold: F, hash: H) -> OwnedStream<G, Vec<R>> where G::Timestamp : Hash+Eq {
64+
>(self, fold: F, hash: H) -> Stream<S, R> where S::Timestamp : Hash+Eq {
7165

7266
let mut pending: HashMap<_, Vec<(K, V)>> = HashMap::new(); // times -> (keys -> state)
7367
let mut states = HashMap::new(); // keys -> state

timely/src/dataflow/operators/branch.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::dataflow::channels::pact::Pipeline;
44
use crate::dataflow::operators::generic::builder_rc::OperatorBuilder;
5-
use crate::dataflow::{Scope, OwnedStream, StreamLike};
5+
use crate::dataflow::{Scope, Stream, StreamCore};
66
use crate::Container;
77

88
/// Extension trait for `Stream`.
@@ -31,14 +31,14 @@ pub trait Branch<S: Scope, D> {
3131
fn branch(
3232
self,
3333
condition: impl Fn(&S::Timestamp, &D) -> bool + 'static,
34-
) -> (OwnedStream<S, Vec<D>>, OwnedStream<S, Vec<D>>);
34+
) -> (Stream<S, D>, Stream<S, D>);
3535
}
3636

37-
impl<G: Scope, D: 'static, S: StreamLike<G, Vec<D>>> Branch<G, D> for S {
37+
impl<S: Scope, D: 'static> Branch<S, D> for Stream<S, D> {
3838
fn branch(
3939
self,
40-
condition: impl Fn(&G::Timestamp, &D) -> bool + 'static,
41-
) -> (OwnedStream<G, Vec<D>>, OwnedStream<G, Vec<D>>) {
40+
condition: impl Fn(&S::Timestamp, &D) -> bool + 'static,
41+
) -> (Stream<S, D>, Stream<S, D>) {
4242
let mut builder = OperatorBuilder::new("Branch".to_owned(), self.scope());
4343

4444
let mut input = builder.new_input(self, Pipeline);
@@ -69,7 +69,7 @@ impl<G: Scope, D: 'static, S: StreamLike<G, Vec<D>>> Branch<G, D> for S {
6969
}
7070

7171
/// Extension trait for `Stream`.
72-
pub trait BranchWhen<G: Scope, C: Container>: Sized {
72+
pub trait BranchWhen<T>: Sized {
7373
/// Takes one input stream and splits it into two output streams.
7474
/// For each time, the supplied closure is called. If it returns `true`,
7575
/// the records for that will be sent to the second returned stream, otherwise
@@ -89,11 +89,11 @@ pub trait BranchWhen<G: Scope, C: Container>: Sized {
8989
/// after_five.inspect(|x| println!("Times 5 and later: {:?}", x));
9090
/// });
9191
/// ```
92-
fn branch_when(self, condition: impl Fn(&G::Timestamp) -> bool + 'static) -> (OwnedStream<G, C>, OwnedStream<G, C>);
92+
fn branch_when(self, condition: impl Fn(&T) -> bool + 'static) -> (Self, Self);
9393
}
9494

95-
impl<G: Scope, C: Container + 'static, S: StreamLike<G, C>> BranchWhen<G, C> for S {
96-
fn branch_when(self, condition: impl Fn(&G::Timestamp) -> bool + 'static) -> (OwnedStream<G, C>, OwnedStream<G, C>) {
95+
impl<S: Scope, C: Container + 'static> BranchWhen<S::Timestamp> for StreamCore<S, C> {
96+
fn branch_when(self, condition: impl Fn(&S::Timestamp) -> bool + 'static) -> (Self, Self) {
9797
let mut builder = OperatorBuilder::new("Branch".to_owned(), self.scope());
9898

9999
let mut input = builder.new_input(self, Pipeline);

timely/src/dataflow/operators/broadcast.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
//! Broadcast records to all workers.
22
33
use crate::ExchangeData;
4-
use crate::dataflow::{OwnedStream, StreamLike, Scope};
4+
use crate::dataflow::{Stream, Scope};
55
use crate::dataflow::operators::{Map, Exchange};
66

77
/// Broadcast records to all workers.
8-
pub trait Broadcast<G: Scope, D: ExchangeData> {
8+
pub trait Broadcast<D: ExchangeData> {
99
/// Broadcast records to all workers.
1010
///
1111
/// # Examples
@@ -18,11 +18,11 @@ pub trait Broadcast<G: Scope, D: ExchangeData> {
1818
/// .inspect(|x| println!("seen: {:?}", x));
1919
/// });
2020
/// ```
21-
fn broadcast(self) -> OwnedStream<G, Vec<D>>;
21+
fn broadcast(self) -> Self;
2222
}
2323

24-
impl<G: Scope, D: ExchangeData + Clone, S: StreamLike<G, Vec<D>>> Broadcast<G, D> for S {
25-
fn broadcast(self) -> OwnedStream<G, Vec<D>> {
24+
impl<G: Scope, D: ExchangeData + Clone> Broadcast<D> for Stream<G, D> {
25+
fn broadcast(self) -> Stream<G, D> {
2626

2727
// NOTE: Simplified implementation due to underlying motion
2828
// in timely dataflow internals. Optimize once they have

timely/src/dataflow/operators/core/capture/capture.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! and there are several default implementations, including a linked-list, Rust's MPSC
66
//! queue, and a binary serializer wrapping any `W: Write`.
77
8-
use crate::dataflow::{Scope, StreamLike};
8+
use crate::dataflow::{Scope, StreamCore};
99
use crate::dataflow::channels::pact::Pipeline;
1010
use crate::dataflow::channels::pullers::Counter as PullCounter;
1111
use crate::dataflow::operators::generic::builder_raw::OperatorBuilder;
@@ -17,7 +17,7 @@ use crate::progress::Timestamp;
1717
use super::{Event, EventPusher};
1818

1919
/// Capture a stream of timestamped data for later replay.
20-
pub trait Capture<G: Scope, C: Container + 'static> : Sized {
20+
pub trait Capture<T: Timestamp, C: Container + 'static> : Sized {
2121
/// Captures a stream of timestamped data for later replay.
2222
///
2323
/// # Examples
@@ -103,18 +103,18 @@ pub trait Capture<G: Scope, C: Container + 'static> : Sized {
103103
///
104104
/// assert_eq!(recv0.extract()[0].1, (0..10).collect::<Vec<_>>());
105105
/// ```
106-
fn capture_into<P: EventPusher<G::Timestamp, C>+'static>(self, pusher: P);
106+
fn capture_into<P: EventPusher<T, C>+'static>(self, pusher: P);
107107

108108
/// Captures a stream using Rust's MPSC channels.
109-
fn capture(self) -> ::std::sync::mpsc::Receiver<Event<G::Timestamp, C>> {
109+
fn capture(self) -> ::std::sync::mpsc::Receiver<Event<T, C>> {
110110
let (send, recv) = ::std::sync::mpsc::channel();
111111
self.capture_into(send);
112112
recv
113113
}
114114
}
115115

116-
impl<G: Scope, C: Container + 'static, S: StreamLike<G, C>> Capture<G, C> for S {
117-
fn capture_into<P: EventPusher<G::Timestamp, C>+'static>(self, mut event_pusher: P) {
116+
impl<S: Scope, C: Container + 'static> Capture<S::Timestamp, C> for StreamCore<S, C> {
117+
fn capture_into<P: EventPusher<S::Timestamp, C>+'static>(self, mut event_pusher: P) {
118118

119119
let mut builder = OperatorBuilder::new("Capture".to_owned(), self.scope());
120120
let mut input = PullCounter::new(builder.new_input(self, Pipeline));

timely/src/dataflow/operators/core/capture/replay.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
//! allowing the replay to occur in a timely dataflow computation with more or fewer workers
3939
//! than that in which the stream was captured.
4040
41-
use crate::dataflow::{Scope, OwnedStream};
41+
use crate::dataflow::{Scope, StreamCore};
4242
use crate::dataflow::channels::pushers::Counter as PushCounter;
4343
use crate::dataflow::channels::pushers::buffer::Buffer as PushBuffer;
4444
use crate::dataflow::operators::generic::builder_raw::OperatorBuilder;
@@ -50,24 +50,24 @@ use crate::Container;
5050

5151
/// Replay a capture stream into a scope with the same timestamp.
5252
pub trait Replay<T: Timestamp, C> : Sized {
53-
/// Replays `self` into the provided scope, as a `OwnedStream<S, C>`.
54-
fn replay_into<S: Scope<Timestamp=T>>(self, scope: &mut S) -> OwnedStream<S, C> {
53+
/// Replays `self` into the provided scope, as a `StreamCore<S, C>`.
54+
fn replay_into<S: Scope<Timestamp=T>>(self, scope: &mut S) -> StreamCore<S, C> {
5555
self.replay_core(scope, Some(std::time::Duration::new(0, 0)))
5656
}
57-
/// Replays `self` into the provided scope, as a `OwnedStream<S, C>`.
57+
/// Replays `self` into the provided scope, as a `StreamCore<S, C>`.
5858
///
5959
/// The `period` argument allows the specification of a re-activation period, where the operator
6060
/// will re-activate itself every so often. The `None` argument instructs the operator not to
6161
/// re-activate itself.
62-
fn replay_core<S: Scope<Timestamp=T>>(self, scope: &mut S, period: Option<std::time::Duration>) -> OwnedStream<S, C>;
62+
fn replay_core<S: Scope<Timestamp=T>>(self, scope: &mut S, period: Option<std::time::Duration>) -> StreamCore<S, C>;
6363
}
6464

6565
impl<T: Timestamp, C: Container + Clone + 'static, I> Replay<T, C> for I
6666
where
6767
I : IntoIterator,
6868
<I as IntoIterator>::Item: EventIterator<T, C>+'static,
6969
{
70-
fn replay_core<S: Scope<Timestamp=T>>(self, scope: &mut S, period: Option<std::time::Duration>) -> OwnedStream<S, C>{
70+
fn replay_core<S: Scope<Timestamp=T>>(self, scope: &mut S, period: Option<std::time::Duration>) -> StreamCore<S, C>{
7171

7272
let mut builder = OperatorBuilder::new("Replay".to_owned(), scope.clone());
7373

timely/src/dataflow/operators/core/concat.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
use crate::Container;
55
use crate::dataflow::channels::pact::Pipeline;
6-
use crate::dataflow::{OwnedStream, StreamLike, Scope};
6+
use crate::dataflow::{StreamCore, Scope};
77

88
/// Merge the contents of two streams.
9-
pub trait Concat<G: Scope, C: Container, S: StreamLike<G, C>> {
9+
pub trait Concat<G: Scope, C: Container> {
1010
/// Merge the contents of two streams.
1111
///
1212
/// # Examples
@@ -16,21 +16,21 @@ pub trait Concat<G: Scope, C: Container, S: StreamLike<G, C>> {
1616
/// timely::example(|scope| {
1717
///
1818
/// let stream = (0..10).to_stream(scope).tee();
19-
/// stream.concat(&stream)
19+
/// stream.owned().concat(stream.owned())
2020
/// .inspect(|x| println!("seen: {:?}", x));
2121
/// });
2222
/// ```
23-
fn concat(self, other: S) -> OwnedStream<G, C>;
23+
fn concat(self, other: StreamCore<G, C>) -> StreamCore<G, C>;
2424
}
2525

26-
impl<G: Scope, C: Container + 'static, S: StreamLike<G, C>> Concat<G, C, S> for S {
27-
fn concat(self, other: S) -> OwnedStream<G, C> {
26+
impl<G: Scope, C: Container + 'static> Concat<G, C> for StreamCore<G, C> {
27+
fn concat(self, other: StreamCore<G, C>) -> StreamCore<G, C> {
2828
self.scope().concatenate([self, other])
2929
}
3030
}
3131

3232
/// Merge the contents of multiple streams.
33-
pub trait Concatenate<G: Scope, C: Container, S: StreamLike<G, C>> {
33+
pub trait Concatenate<G: Scope, C: Container> {
3434
/// Merge the contents of multiple streams.
3535
///
3636
/// # Examples
@@ -43,28 +43,29 @@ pub trait Concatenate<G: Scope, C: Container, S: StreamLike<G, C>> {
4343
/// (0..10).to_stream(scope),
4444
/// (0..10).to_stream(scope)];
4545
///
46-
/// scope.concatenate(streams)
46+
/// scope.clone()
47+
/// .concatenate(streams)
4748
/// .inspect(|x| println!("seen: {:?}", x));
4849
/// });
4950
/// ```
50-
fn concatenate<I>(self, sources: I) -> OwnedStream<G, C>
51+
fn concatenate<I>(self, sources: I) -> StreamCore<G, C>
5152
where
52-
I: IntoIterator<Item=S>;
53+
I: IntoIterator<Item=StreamCore<G, C>>;
5354
}
5455

55-
impl<G: Scope, C: Container + 'static> Concatenate<G, C, OwnedStream<G, C>> for OwnedStream<G, C> {
56-
fn concatenate<I>(self, sources: I) -> OwnedStream<G, C>
56+
impl<G: Scope, C: Container + 'static> Concatenate<G, C> for StreamCore<G, C> {
57+
fn concatenate<I>(self, sources: I) -> StreamCore<G, C>
5758
where
58-
I: IntoIterator<Item=OwnedStream<G, C>>
59+
I: IntoIterator<Item=StreamCore<G, C>>
5960
{
6061
self.scope().concatenate(Some(self).into_iter().chain(sources))
6162
}
6263
}
6364

64-
impl<G: Scope, C: Container + 'static, S: StreamLike<G, C>> Concatenate<G, C, S> for &G {
65-
fn concatenate<I>(self, sources: I) -> OwnedStream<G, C>
65+
impl<G: Scope, C: Container + 'static> Concatenate<G, C> for G {
66+
fn concatenate<I>(self, sources: I) -> StreamCore<G, C>
6667
where
67-
I: IntoIterator<Item=S>
68+
I: IntoIterator<Item=StreamCore<G, C>>
6869
{
6970

7071
// create an operator builder.

0 commit comments

Comments
 (0)