Skip to content

Commit

Permalink
Remove Container: Clone + 'static
Browse files Browse the repository at this point in the history
Remove the requirement that all Container implementations are Clone and
'static. This makes implementing types simpler that depend on Container,
and requires us to explicitly mark various places as `Data` such that they
comply with Timely's type requirements.

Signed-off-by: Moritz Hoffmann <antiguru@gmail.com>
  • Loading branch information
antiguru committed Apr 23, 2024
1 parent 819135e commit 5b44c22
Show file tree
Hide file tree
Showing 25 changed files with 126 additions and 109 deletions.
6 changes: 3 additions & 3 deletions container/src/columnation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ mod container {

use crate::columnation::{Columnation, TimelyStack};

impl<T: Columnation + 'static> Container for TimelyStack<T> {
impl<T: Columnation> Container for TimelyStack<T> {
type ItemRef<'a> = &'a T where Self: 'a;
type Item<'a> = &'a T where Self: 'a;

Expand All @@ -330,13 +330,13 @@ mod container {
TimelyStack::clear(self)
}

type Iter<'a> = std::slice::Iter<'a, T>;
type Iter<'a> = std::slice::Iter<'a, T> where Self: 'a;

fn iter(&self) -> Self::Iter<'_> {
self.deref().iter()
}

type DrainIter<'a> = std::slice::Iter<'a, T>;
type DrainIter<'a> = std::slice::Iter<'a, T> where Self: 'a;

fn drain(&mut self) -> Self::DrainIter<'_> {
(*self).iter()
Expand Down
23 changes: 11 additions & 12 deletions container/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ pub mod flatcontainer;
/// We require the container to be cloneable to enable efficient copies when providing references
/// of containers to operators. Care must be taken that the type's `clone_from` implementation
/// is efficient (which is not necessarily the case when deriving `Clone`.)
/// TODO: Don't require `Container: Clone`
pub trait Container: Default + Clone + 'static {
pub trait Container: Default {
/// The type of elements when reading non-destructively from the container.
type ItemRef<'a> where Self: 'a;

Expand All @@ -42,13 +41,13 @@ pub trait Container: Default + Clone + 'static {
fn clear(&mut self);

/// Iterator type when reading from the container.
type Iter<'a>: Iterator<Item=Self::ItemRef<'a>>;
type Iter<'a>: Iterator<Item=Self::ItemRef<'a>> where Self: 'a;

/// Returns an iterator that reads the contents of this container.
fn iter(&self) -> Self::Iter<'_>;

/// Iterator type when draining the container.
type DrainIter<'a>: Iterator<Item=Self::Item<'a>>;
type DrainIter<'a>: Iterator<Item=Self::Item<'a>> where Self: 'a;

/// Returns an iterator that drains the contents of this container.
/// Drain leaves the container in an undefined state.
Expand Down Expand Up @@ -83,7 +82,7 @@ pub trait PushContainer: Container {
fn reserve(&mut self, additional: usize);
}

impl<T: Clone + 'static> Container for Vec<T> {
impl<T> Container for Vec<T> {
type ItemRef<'a> = &'a T where T: 'a;
type Item<'a> = T where T: 'a;

Expand All @@ -97,13 +96,13 @@ impl<T: Clone + 'static> Container for Vec<T> {

fn clear(&mut self) { Vec::clear(self) }

type Iter<'a> = std::slice::Iter<'a, T>;
type Iter<'a> = std::slice::Iter<'a, T> where Self: 'a;

fn iter(&self) -> Self::Iter<'_> {
self.as_slice().iter()
}

type DrainIter<'a> = std::vec::Drain<'a, T>;
type DrainIter<'a> = std::vec::Drain<'a, T> where Self: 'a;

fn drain(&mut self) -> Self::DrainIter<'_> {
self.drain(..)
Expand Down Expand Up @@ -165,13 +164,13 @@ mod rc {
}
}

type Iter<'a> = T::Iter<'a>;
type Iter<'a> = T::Iter<'a> where Self: 'a;

fn iter(&self) -> Self::Iter<'_> {
self.deref().iter()
}

type DrainIter<'a> = T::Iter<'a>;
type DrainIter<'a> = T::Iter<'a> where Self: 'a;

fn drain(&mut self) -> Self::DrainIter<'_> {
self.iter()
Expand Down Expand Up @@ -206,13 +205,13 @@ mod arc {
}
}

type Iter<'a> = T::Iter<'a>;
type Iter<'a> = T::Iter<'a> where Self: 'a;

fn iter(&self) -> Self::Iter<'_> {
self.deref().iter()
}

type DrainIter<'a> = T::Iter<'a>;
type DrainIter<'a> = T::Iter<'a> where Self: 'a;

fn drain(&mut self) -> Self::DrainIter<'_> {
self.iter()
Expand All @@ -232,7 +231,7 @@ pub trait PushPartitioned: PushContainer {
F: FnMut(usize, &mut Self);
}

impl<T: PushContainer + 'static> PushPartitioned for T where for<'a> T::Item<'a>: PushInto<T> {
impl<T: PushContainer> PushPartitioned for T where for<'a> T::Item<'a>: PushInto<T> {
fn push_partitioned<I, F>(&mut self, buffers: &mut [Self], mut index: I, mut flush: F)
where
for<'a> I: FnMut(&Self::Item<'a>) -> usize,
Expand Down
8 changes: 4 additions & 4 deletions timely/src/dataflow/channels/pact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
use std::{fmt::{self, Debug}, marker::PhantomData};

use crate::Container;
use crate::{Container, ExchangeData};
use crate::communication::allocator::thread::{ThreadPusher, ThreadPuller};
use crate::communication::{Push, Pull, Data};
use crate::communication::{Push, Pull};
use crate::container::PushPartitioned;
use crate::dataflow::channels::pushers::Exchange as ExchangePusher;
use crate::dataflow::channels::{Bundle, Message};
Expand All @@ -33,7 +33,7 @@ pub trait ParallelizationContract<T, C> {
#[derive(Debug)]
pub struct Pipeline;

impl<T: 'static, C: Container> ParallelizationContract<T, C> for Pipeline {
impl<T: 'static, C: Container + 'static> ParallelizationContract<T, C> for Pipeline {
type Pusher = LogPusher<T, C, ThreadPusher<Bundle<T, C>>>;
type Puller = LogPuller<T, C, ThreadPuller<Bundle<T, C>>>;
fn connect<A: AsWorker>(self, allocator: &mut A, identifier: usize, address: &[usize], logging: Option<Logger>) -> (Self::Pusher, Self::Puller) {
Expand Down Expand Up @@ -66,7 +66,7 @@ where
// Exchange uses a `Box<Pushable>` because it cannot know what type of pushable will return from the allocator.
impl<T: Timestamp, C, H: 'static> ParallelizationContract<T, C> for ExchangeCore<C, H>
where
C: Data + PushPartitioned,
C: PushPartitioned + ExchangeData,
for<'a> H: FnMut(&C::Item<'a>) -> u64
{
type Pusher = ExchangePusher<T, C, LogPusher<T, C, Box<dyn Push<Bundle<T, C>>>>, H>;
Expand Down
6 changes: 3 additions & 3 deletions timely/src/dataflow/channels/pushers/exchange.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use crate::communication::Push;
use crate::container::PushPartitioned;
use crate::dataflow::channels::{Bundle, Message};
use crate::{Container, Data};
use crate::Data;

// TODO : Software write combining
/// Distributes records among target pushees according to a distribution function.
Expand Down Expand Up @@ -44,9 +44,9 @@ where
}
}

impl<T: Eq+Data, C: Container, P: Push<Bundle<T, C>>, H, > Push<Bundle<T, C>> for Exchange<T, C, P, H>
impl<T: Eq+Data, C, P: Push<Bundle<T, C>>, H, > Push<Bundle<T, C>> for Exchange<T, C, P, H>
where
C: PushPartitioned,
C: PushPartitioned+Data,
for<'a> H: FnMut(&C::Item<'a>) -> u64
{
#[inline(never)]
Expand Down
2 changes: 1 addition & 1 deletion timely/src/dataflow/channels/pushers/tee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct Tee<T, C> {
shared: PushList<T, C>,
}

impl<T: Data, C: Container> Push<Bundle<T, C>> for Tee<T, C> {
impl<T: Data, C: Container+Data> Push<Bundle<T, C>> for Tee<T, C> {
#[inline]
fn push(&mut self, message: &mut Option<Bundle<T, C>>) {
let mut pushers = self.shared.borrow_mut();
Expand Down
2 changes: 1 addition & 1 deletion timely/src/dataflow/operators/branch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub trait BranchWhen<T>: Sized {
fn branch_when(&self, condition: impl Fn(&T) -> bool + 'static) -> (Self, Self);
}

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

Expand Down
6 changes: 3 additions & 3 deletions timely/src/dataflow/operators/core/capture/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ use crate::dataflow::channels::pact::Pipeline;
use crate::dataflow::channels::pullers::Counter as PullCounter;
use crate::dataflow::operators::generic::builder_raw::OperatorBuilder;

use crate::Container;
use crate::{Container, Data};
use crate::progress::ChangeBatch;
use crate::progress::Timestamp;

use super::{Event, EventPusher};

/// Capture a stream of timestamped data for later replay.
pub trait Capture<T: Timestamp, C: Container> {
pub trait Capture<T: Timestamp, C: Container+Data> {
/// Captures a stream of timestamped data for later replay.
///
/// # Examples
Expand Down Expand Up @@ -113,7 +113,7 @@ pub trait Capture<T: Timestamp, C: Container> {
}
}

impl<S: Scope, C: Container> Capture<S::Timestamp, C> for StreamCore<S, C> {
impl<S: Scope, C: Container + Data> Capture<S::Timestamp, C> for StreamCore<S, C> {
fn capture_into<P: EventPusher<S::Timestamp, C>+'static>(&self, mut event_pusher: P) {

let mut builder = OperatorBuilder::new("Capture".to_owned(), self.scope());
Expand Down
4 changes: 2 additions & 2 deletions timely/src/dataflow/operators/core/capture/replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use crate::progress::Timestamp;

use super::Event;
use super::event::EventIterator;
use crate::Container;
use crate::{Container, Data};

/// Replay a capture stream into a scope with the same timestamp.
pub trait Replay<T: Timestamp, C> : Sized {
Expand All @@ -62,7 +62,7 @@ pub trait Replay<T: Timestamp, C> : Sized {
fn replay_core<S: Scope<Timestamp=T>>(self, scope: &mut S, period: Option<std::time::Duration>) -> StreamCore<S, C>;
}

impl<T: Timestamp, C: Container, I> Replay<T, C> for I
impl<T: Timestamp, C: Container + Data, I> Replay<T, C> for I
where
I : IntoIterator,
<I as IntoIterator>::Item: EventIterator<T, C>+'static,
Expand Down
8 changes: 4 additions & 4 deletions timely/src/dataflow/operators/core/concat.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Merges the contents of multiple streams.

use crate::Container;
use crate::{Container, Data};
use crate::dataflow::channels::pact::Pipeline;
use crate::dataflow::{StreamCore, Scope};

Expand All @@ -23,7 +23,7 @@ pub trait Concat<G: Scope, C: Container> {
fn concat(&self, _: &StreamCore<G, C>) -> StreamCore<G, C>;
}

impl<G: Scope, C: Container> Concat<G, C> for StreamCore<G, C> {
impl<G: Scope, C: Container + Data> Concat<G, C> for StreamCore<G, C> {
fn concat(&self, other: &StreamCore<G, C>) -> StreamCore<G, C> {
self.scope().concatenate([self.clone(), other.clone()])
}
Expand Down Expand Up @@ -52,7 +52,7 @@ pub trait Concatenate<G: Scope, C: Container> {
I: IntoIterator<Item=StreamCore<G, C>>;
}

impl<G: Scope, C: Container> Concatenate<G, C> for StreamCore<G, C> {
impl<G: Scope, C: Container + Data> Concatenate<G, C> for StreamCore<G, C> {
fn concatenate<I>(&self, sources: I) -> StreamCore<G, C>
where
I: IntoIterator<Item=StreamCore<G, C>>
Expand All @@ -62,7 +62,7 @@ impl<G: Scope, C: Container> Concatenate<G, C> for StreamCore<G, C> {
}
}

impl<G: Scope, C: Container> Concatenate<G, C> for G {
impl<G: Scope, C: Container + Data> Concatenate<G, C> for G {
fn concatenate<I>(&self, sources: I) -> StreamCore<G, C>
where
I: IntoIterator<Item=StreamCore<G, C>>
Expand Down
6 changes: 3 additions & 3 deletions timely/src/dataflow/operators/core/enterleave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub trait Leave<G: Scope, C: Container> {
fn leave(&self) -> StreamCore<G, C>;
}

impl<'a, G: Scope, C: Clone+Container, T: Timestamp+Refines<G::Timestamp>> Leave<G, C> for StreamCore<Child<'a, G, T>, C> {
impl<'a, G: Scope, C: Container+Data, T: Timestamp+Refines<G::Timestamp>> Leave<G, C> for StreamCore<Child<'a, G, T>, C> {
fn leave(&self) -> StreamCore<G, C> {

let scope = self.scope();
Expand All @@ -130,14 +130,14 @@ impl<'a, G: Scope, C: Clone+Container, T: Timestamp+Refines<G::Timestamp>> Leave
}


struct IngressNub<TOuter: Timestamp, TInner: Timestamp+Refines<TOuter>, TContainer: Container> {
struct IngressNub<TOuter: Timestamp, TInner: Timestamp+Refines<TOuter>, TContainer: Container+Data> {
targets: Counter<TInner, TContainer, Tee<TInner, TContainer>>,
phantom: ::std::marker::PhantomData<TOuter>,
activator: crate::scheduling::Activator,
active: bool,
}

impl<TOuter: Timestamp, TInner: Timestamp+Refines<TOuter>, TContainer: Container> Push<Bundle<TOuter, TContainer>> for IngressNub<TOuter, TInner, TContainer> {
impl<TOuter: Timestamp, TInner: Timestamp+Refines<TOuter>, TContainer: Container+Data> Push<Bundle<TOuter, TContainer>> for IngressNub<TOuter, TInner, TContainer> {
fn push(&mut self, element: &mut Option<Bundle<TOuter, TContainer>>) {
if let Some(message) = element {
let outer_message = message.as_mut();
Expand Down
16 changes: 8 additions & 8 deletions timely/src/dataflow/operators/core/feedback.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Create cycles in a timely dataflow graph.
use crate::Container;
use crate::{Container, Data};

use crate::progress::{Timestamp, PathSummary};
use crate::progress::frontier::Antichain;
Expand Down Expand Up @@ -37,7 +37,7 @@ pub trait Feedback<G: Scope> {
/// .connect_loop(handle);
/// });
/// ```
fn feedback<C: Container>(&mut self, summary: <G::Timestamp as Timestamp>::Summary) -> (Handle<G, C>, StreamCore<G, C>);
fn feedback<C: Container+Data>(&mut self, summary: <G::Timestamp as Timestamp>::Summary) -> (Handle<G, C>, StreamCore<G, C>);
}

/// Creates a `StreamCore` and a `Handle` to later bind the source of that `StreamCore`.
Expand Down Expand Up @@ -65,12 +65,12 @@ pub trait LoopVariable<'a, G: Scope, T: Timestamp> {
/// });
/// });
/// ```
fn loop_variable<C: Container>(&mut self, summary: T::Summary) -> (Handle<Iterative<'a, G, T>, C>, StreamCore<Iterative<'a, G, T>, C>);
fn loop_variable<C: Container+Data>(&mut self, summary: T::Summary) -> (Handle<Iterative<'a, G, T>, C>, StreamCore<Iterative<'a, G, T>, C>);
}

impl<G: Scope> Feedback<G> for G {

fn feedback<C: Container>(&mut self, summary: <G::Timestamp as Timestamp>::Summary) -> (Handle<G, C>, StreamCore<G, C>) {
fn feedback<C: Container+Data>(&mut self, summary: <G::Timestamp as Timestamp>::Summary) -> (Handle<G, C>, StreamCore<G, C>) {

let mut builder = OperatorBuilder::new("Feedback".to_owned(), self.clone());
let (output, stream) = builder.new_output();
Expand All @@ -80,13 +80,13 @@ impl<G: Scope> Feedback<G> for G {
}

impl<'a, G: Scope, T: Timestamp> LoopVariable<'a, G, T> for Iterative<'a, G, T> {
fn loop_variable<C: Container>(&mut self, summary: T::Summary) -> (Handle<Iterative<'a, G, T>, C>, StreamCore<Iterative<'a, G, T>, C>) {
fn loop_variable<C: Container+Data>(&mut self, summary: T::Summary) -> (Handle<Iterative<'a, G, T>, C>, StreamCore<Iterative<'a, G, T>, C>) {
self.feedback(Product::new(Default::default(), summary))
}
}

/// Connect a `Stream` to the input of a loop variable.
pub trait ConnectLoop<G: Scope, C: Container> {
pub trait ConnectLoop<G: Scope, C: Container+Data> {
/// Connect a `Stream` to be the input of a loop variable.
///
/// # Examples
Expand All @@ -107,7 +107,7 @@ pub trait ConnectLoop<G: Scope, C: Container> {
fn connect_loop(&self, handle: Handle<G, C>);
}

impl<G: Scope, C: Container> ConnectLoop<G, C> for StreamCore<G, C> {
impl<G: Scope, C: Container+Data> ConnectLoop<G, C> for StreamCore<G, C> {
fn connect_loop(&self, handle: Handle<G, C>) {

let mut builder = handle.builder;
Expand All @@ -134,7 +134,7 @@ impl<G: Scope, C: Container> ConnectLoop<G, C> for StreamCore<G, C> {

/// A handle used to bind the source of a loop variable.
#[derive(Debug)]
pub struct Handle<G: Scope, C: Container> {
pub struct Handle<G: Scope, C: Container+Data> {
builder: OperatorBuilder<G>,
summary: <G::Timestamp as Timestamp>::Summary,
output: OutputWrapper<G::Timestamp, C, Tee<G::Timestamp, C>>,
Expand Down
3 changes: 2 additions & 1 deletion timely/src/dataflow/operators/core/filter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Filters a stream by a predicate.
use timely_container::{Container, PushContainer, PushInto};
use crate::Data;

use crate::dataflow::channels::pact::Pipeline;
use crate::dataflow::{Scope, StreamCore};
Expand All @@ -23,7 +24,7 @@ pub trait Filter<C: Container> {
fn filter<P: FnMut(&C::Item<'_>)->bool+'static>(&self, predicate: P) -> Self;
}

impl<G: Scope, C: PushContainer> Filter<C> for StreamCore<G, C>
impl<G: Scope, C: PushContainer+Data> Filter<C> for StreamCore<G, C>
where
for<'a> C::Item<'a>: PushInto<C>
{
Expand Down
Loading

0 comments on commit 5b44c22

Please sign in to comment.