Skip to content

Commit

Permalink
Remove 'static requirement from difference traits
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmcsherry committed May 27, 2024
1 parent 1f17e65 commit fc87f61
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 89 deletions.
4 changes: 2 additions & 2 deletions dogsdogsdogs/src/calculus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<G, D, R> Differentiate<G, D, R> for Collection<G, D, R>
where
G: Scope,
D: Data,
R: Abelian,
R: Abelian + 'static,
{
// For each (data, Alt(time), diff) we add a (data, Neu(time), -diff).
fn differentiate<'a>(&self, child: &Child<'a, G, AltNeu<G::Timestamp>>) -> Collection<Child<'a, G, AltNeu<G::Timestamp>>, D, R> {
Expand All @@ -53,7 +53,7 @@ impl<'a, G, D, R> Integrate<G, D, R> for Collection<Child<'a, G, AltNeu<G::Times
where
G: Scope,
D: Data,
R: Abelian,
R: Abelian + 'static,
{
// We discard each `neu` variant and strip off the `alt` wrapper.
fn integrate(&self) -> Collection<G, D, R> {
Expand Down
2 changes: 1 addition & 1 deletion dogsdogsdogs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<G, P, R> ProposeExtensionMethod<G, P, R> for Collection<G, P, R>
where
G: Scope,
P: ExchangeData+Ord,
R: Monoid+Multiply<Output = R>,
R: Monoid+Multiply<Output = R>+'static,
{
fn propose_using<PE>(&self, extender: &mut PE) -> Collection<G, (P, PE::Extension), R>
where
Expand Down
2 changes: 1 addition & 1 deletion dogsdogsdogs/src/operators/half_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ where
FF: Fn(&G::Timestamp, &mut Antichain<G::Timestamp>) + 'static,
CF: Fn(&G::Timestamp, &G::Timestamp) -> bool + 'static,
DOut: Clone+'static,
ROut: Semigroup,
ROut: Semigroup + 'static,
Y: Fn(std::time::Instant, usize) -> bool + 'static,
I: IntoIterator<Item=(DOut, G::Timestamp, ROut)>,
S: FnMut(&K, &V, Tr::Val<'_>, &G::Timestamp, &G::Timestamp, &R, &Tr::Diff)-> I + 'static,
Expand Down
2 changes: 1 addition & 1 deletion dogsdogsdogs/src/operators/lookup_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ where
D: ExchangeData,
R: ExchangeData+Monoid,
DOut: Clone+'static,
ROut: Monoid,
ROut: Monoid + 'static,
S: FnMut(&D, &R, Tr::Val<'_>, &Tr::Diff)->(DOut, ROut)+'static,
{
// No need to block physical merging for this operator.
Expand Down
16 changes: 8 additions & 8 deletions src/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub struct Collection<G: Scope, D, R: Semigroup = isize> {
pub inner: Stream<G, (D, G::Timestamp, R)>
}

impl<G: Scope, D: Data, R: Semigroup> Collection<G, D, R> where G::Timestamp: Data {
impl<G: Scope, D: Data, R: Semigroup+'static> Collection<G, D, R> where G::Timestamp: Data {
/// Creates a new Collection from a timely dataflow stream.
///
/// This method seems to be rarely used, with the `as_collection` method on streams being a more
Expand Down Expand Up @@ -226,7 +226,7 @@ impl<G: Scope, D: Data, R: Semigroup> Collection<G, D, R> where G::Timestamp: Da
pub fn explode<D2, R2, I, L>(&self, mut logic: L) -> Collection<G, D2, <R2 as Multiply<R>>::Output>
where D2: Data,
R2: Semigroup+Multiply<R>,
<R2 as Multiply<R>>::Output: Data+Semigroup,
<R2 as Multiply<R>>::Output: Semigroup+'static,
I: IntoIterator<Item=(D2,R2)>,
L: FnMut(D)->I+'static,
{
Expand Down Expand Up @@ -261,7 +261,7 @@ impl<G: Scope, D: Data, R: Semigroup> Collection<G, D, R> where G::Timestamp: Da
where G::Timestamp: Lattice,
D2: Data,
R2: Semigroup+Multiply<R>,
<R2 as Multiply<R>>::Output: Data+Semigroup,
<R2 as Multiply<R>>::Output: Semigroup+'static,
I: IntoIterator<Item=(D2,G::Timestamp,R2)>,
L: FnMut(D)->I+'static,
{
Expand Down Expand Up @@ -476,7 +476,7 @@ use timely::dataflow::scopes::ScopeParent;
use timely::progress::timestamp::Refines;

/// Methods requiring a nested scope.
impl<'a, G: Scope, T: Timestamp, D: Data, R: Semigroup> Collection<Child<'a, G, T>, D, R>
impl<'a, G: Scope, T: Timestamp, D: Data, R: Semigroup+'static> Collection<Child<'a, G, T>, D, R>
where
T: Refines<<G as ScopeParent>::Timestamp>,
{
Expand Down Expand Up @@ -509,7 +509,7 @@ where
}

/// Methods requiring a region as the scope.
impl<'a, G: Scope, D: Data, R: Semigroup> Collection<Child<'a, G, G::Timestamp>, D, R>
impl<'a, G: Scope, D: Data, R: Semigroup+'static> Collection<Child<'a, G, G::Timestamp>, D, R>
{
/// Returns the value of a Collection from a nested region to its containing scope.
///
Expand All @@ -523,7 +523,7 @@ impl<'a, G: Scope, D: Data, R: Semigroup> Collection<Child<'a, G, G::Timestamp>,
}

/// Methods requiring an Abelian difference, to support negation.
impl<G: Scope, D: Data, R: Abelian> Collection<G, D, R> where G::Timestamp: Data {
impl<G: Scope, D: Data, R: Abelian+'static> Collection<G, D, R> where G::Timestamp: Data {
/// Creates a new collection whose counts are the negation of those in the input.
///
/// This method is most commonly used with `concat` to get those element in one collection but not another.
Expand Down Expand Up @@ -594,7 +594,7 @@ pub trait AsCollection<G: Scope, D: Data, R: Semigroup> {
fn as_collection(&self) -> Collection<G, D, R>;
}

impl<G: Scope, D: Data, R: Semigroup> AsCollection<G, D, R> for Stream<G, (D, G::Timestamp, R)> {
impl<G: Scope, D: Data, R: Semigroup+'static> AsCollection<G, D, R> for Stream<G, (D, G::Timestamp, R)> {
fn as_collection(&self) -> Collection<G, D, R> {
Collection::new(self.clone())
}
Expand Down Expand Up @@ -625,7 +625,7 @@ pub fn concatenate<G, D, R, I>(scope: &mut G, iterator: I) -> Collection<G, D, R
where
G: Scope,
D: Data,
R: Semigroup,
R: Semigroup+'static,
I: IntoIterator<Item=Collection<G, D, R>>,
{
scope
Expand Down
4 changes: 2 additions & 2 deletions src/consolidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl<D,T,R> ConsolidatingContainerBuilder<Vec<(D, T, R)>>
where
D: Data,
T: Data,
R: Semigroup,
R: Semigroup+'static,
{
/// Flush `self.current` up to the biggest `multiple` of elements. Pass 1 to flush all elements.
// TODO: Can we replace `multiple` by a bool?
Expand All @@ -165,7 +165,7 @@ impl<D,T,R> ContainerBuilder for ConsolidatingContainerBuilder<Vec<(D, T, R)>>
where
D: Data,
T: Data,
R: Semigroup,
R: Semigroup+'static,
{
type Container = Vec<(D,T,R)>;

Expand Down
4 changes: 1 addition & 3 deletions src/difference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
//! dataflow collections would then track for each record the total of counts and heights, which allows
//! us to track something like the average.

use crate::Data;

#[deprecated]
pub use self::Abelian as Diff;

Expand All @@ -22,7 +20,7 @@ pub use self::Abelian as Diff;
/// There is a light presumption of commutativity here, in that while we will largely perform addition
/// in order of timestamps, for many types of timestamps there is no total order and consequently no
/// obvious order to respect. Non-commutative semigroups should be used with care.
pub trait Semigroup<Rhs: ?Sized = Self> : Data + Clone {
pub trait Semigroup<Rhs: ?Sized = Self> : Clone {
/// The method of `std::ops::AddAssign`, for types that do not implement `AddAssign`.
fn plus_equals(&mut self, rhs: &Rhs);
/// Returns true if the element is the additive identity.
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl<G, D, R, T, TOuter> Collection<G, D, R>
where
G: Scope<Timestamp = Product<TOuter, PointStamp<T>>>,
D: Data,
R: Semigroup,
R: Semigroup+'static,
T: Timestamp+Default,
TOuter: Timestamp,
{
Expand Down
14 changes: 7 additions & 7 deletions src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub trait Input : TimelyInput {
/// }).unwrap();
/// ```
fn new_collection<D, R>(&mut self) -> (InputSession<<Self as ScopeParent>::Timestamp, D, R>, Collection<Self, D, R>)
where D: Data, R: Semigroup;
where D: Data, R: Semigroup+'static;
/// Create a new collection and input handle from initial data.
///
/// # Examples
Expand Down Expand Up @@ -94,13 +94,13 @@ pub trait Input : TimelyInput {
/// }).unwrap();
/// ```
fn new_collection_from_raw<D, R, I>(&mut self, data: I) -> (InputSession<<Self as ScopeParent>::Timestamp, D, R>, Collection<Self, D, R>)
where I: IntoIterator<Item=(D,<Self as ScopeParent>::Timestamp,R)>+'static, D: Data, R: Semigroup+Data;
where I: IntoIterator<Item=(D,<Self as ScopeParent>::Timestamp,R)>+'static, D: Data, R: Semigroup+'static;
}

use crate::lattice::Lattice;
impl<G: TimelyInput> Input for G where <G as ScopeParent>::Timestamp: Lattice {
fn new_collection<D, R>(&mut self) -> (InputSession<<G as ScopeParent>::Timestamp, D, R>, Collection<G, D, R>)
where D: Data, R: Semigroup{
where D: Data, R: Semigroup+'static{
let (handle, stream) = self.new_input();
(InputSession::from(handle), stream.as_collection())
}
Expand All @@ -111,7 +111,7 @@ impl<G: TimelyInput> Input for G where <G as ScopeParent>::Timestamp: Lattice {
fn new_collection_from_raw<D,R,I>(&mut self, data: I) -> (InputSession<<G as ScopeParent>::Timestamp, D, R>, Collection<G, D, R>)
where
D: Data,
R: Semigroup+Data,
R: Semigroup+'static,
I: IntoIterator<Item=(D,<Self as ScopeParent>::Timestamp,R)>+'static,
{
use timely::dataflow::operators::ToStream;
Expand Down Expand Up @@ -166,7 +166,7 @@ impl<G: TimelyInput> Input for G where <G as ScopeParent>::Timestamp: Lattice {
///
/// }).unwrap();
/// ```
pub struct InputSession<T: Timestamp+Clone, D: Data, R: Semigroup> {
pub struct InputSession<T: Timestamp+Clone, D: Data, R: Semigroup+'static> {
time: T,
buffer: Vec<(D, T, R)>,
handle: Handle<T,(D,T,R)>,
Expand All @@ -193,7 +193,7 @@ impl<T: Timestamp+Clone, D: Data> InputSession<T, D, isize> {
// pub fn remove(&mut self, element: D) { self.update(element,-1); }
// }

impl<T: Timestamp+Clone, D: Data, R: Semigroup> InputSession<T, D, R> {
impl<T: Timestamp+Clone, D: Data, R: Semigroup+'static> InputSession<T, D, R> {

/// Introduces a handle as collection.
pub fn to_collection<G: TimelyInput>(&mut self, scope: &mut G) -> Collection<G, D, R>
Expand Down Expand Up @@ -281,7 +281,7 @@ impl<T: Timestamp+Clone, D: Data, R: Semigroup> InputSession<T, D, R> {
pub fn close(self) { }
}

impl<T: Timestamp+Clone, D: Data, R: Semigroup> Drop for InputSession<T, D, R> {
impl<T: Timestamp+Clone, D: Data, R: Semigroup+'static> Drop for InputSession<T, D, R> {
fn drop(&mut self) {
self.flush();
}
Expand Down
8 changes: 4 additions & 4 deletions src/operators/arrange/arrangement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ where
where
T2: for<'a> TraceReader<Key<'a>=T1::Key<'a>,Time=T1::Time>+Clone+'static,
T1::Diff: Multiply<T2::Diff>,
<T1::Diff as Multiply<T2::Diff>>::Output: Semigroup,
<T1::Diff as Multiply<T2::Diff>>::Output: Semigroup+'static,
I: IntoIterator,
I::Item: Data,
L: FnMut(T1::Key<'_>,T1::Val<'_>,T2::Val<'_>)->I+'static
Expand All @@ -261,7 +261,7 @@ where
where
T2: for<'a> TraceReader<Key<'a>=T1::Key<'a>, Time=T1::Time>+Clone+'static,
D: Data,
ROut: Semigroup,
ROut: Semigroup+'static,
I: IntoIterator<Item=(D, G::Timestamp, ROut)>,
L: FnMut(T1::Key<'_>, T1::Val<'_>,T2::Val<'_>,&G::Timestamp,&T1::Diff,&T2::Diff)->I+'static,
{
Expand Down Expand Up @@ -603,7 +603,7 @@ where
/// This arrangement requires `Key: Hashable`, and uses the `hashed()` method to place keys in a hashed
/// map. This can result in many hash calls, and in some cases it may help to first transform `K` to the
/// pair `(u64, K)` of hash value and key.
pub trait ArrangeByKey<G: Scope, K: Data+Hashable, V: Data, R: Semigroup>
pub trait ArrangeByKey<G: Scope, K: Data+Hashable, V: Data, R: Ord+Semigroup+'static>
where G::Timestamp: Lattice+Ord {
/// Arranges a collection of `(Key, Val)` records by `Key`.
///
Expand Down Expand Up @@ -634,7 +634,7 @@ where
/// This arrangement requires `Key: Hashable`, and uses the `hashed()` method to place keys in a hashed
/// map. This can result in many hash calls, and in some cases it may help to first transform `K` to the
/// pair `(u64, K)` of hash value and key.
pub trait ArrangeBySelf<G: Scope, K: Data+Hashable, R: Semigroup>
pub trait ArrangeBySelf<G: Scope, K: Data+Hashable, R: Ord+Semigroup+'static>
where
G::Timestamp: Lattice+Ord
{
Expand Down
7 changes: 4 additions & 3 deletions src/operators/count.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use timely::dataflow::channels::pact::Pipeline;

use crate::trace::cursor::IntoOwned;

use crate::Data;
use crate::lattice::Lattice;
use crate::{ExchangeData, Collection};
use crate::difference::Semigroup;
Expand Down Expand Up @@ -41,12 +42,12 @@ pub trait CountTotal<G: Scope, K: ExchangeData, R: Semigroup> where G::Timestamp
/// This method allows `count_total` to produce collections whose difference
/// type is something other than an `isize` integer, for example perhaps an
/// `i32`.
fn count_total_core<R2: Semigroup + From<i8>>(&self) -> Collection<G, (K, R), R2>;
fn count_total_core<R2: Data + Semigroup + From<i8>>(&self) -> Collection<G, (K, R), R2>;
}

impl<G: Scope, K: ExchangeData+Hashable, R: ExchangeData+Semigroup> CountTotal<G, K, R> for Collection<G, K, R>
where G::Timestamp: TotalOrder+Lattice+Ord {
fn count_total_core<R2: Semigroup + From<i8>>(&self) -> Collection<G, (K, R), R2> {
fn count_total_core<R2: Data + Semigroup + From<i8>>(&self) -> Collection<G, (K, R), R2> {
self.arrange_by_self_named("Arrange: CountTotal")
.count_total_core()
}
Expand All @@ -61,7 +62,7 @@ where
T1::Time: TotalOrder,
T1::Diff: ExchangeData,
{
fn count_total_core<R2: Semigroup + From<i8>>(&self) -> Collection<G, (K, T1::Diff), R2> {
fn count_total_core<R2: Data + Semigroup + From<i8>>(&self) -> Collection<G, (K, T1::Diff), R2> {

let mut trace = self.trace.clone();
let mut buffer = Vec::new();
Expand Down
8 changes: 4 additions & 4 deletions src/operators/iterate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ pub trait Iterate<G: Scope, D: Data, R: Semigroup> {
for<'a> F: FnOnce(&Collection<Iterative<'a, G, u64>, D, R>)->Collection<Iterative<'a, G, u64>, D, R>;
}

impl<G: Scope, D: Ord+Data+Debug, R: Abelian> Iterate<G, D, R> for Collection<G, D, R> {
impl<G: Scope, D: Ord+Data+Debug, R: Abelian+'static> Iterate<G, D, R> for Collection<G, D, R> {
fn iterate<F>(&self, logic: F) -> Collection<G, D, R>
where G::Timestamp: Lattice,
for<'a> F: FnOnce(&Collection<Iterative<'a, G, u64>, D, R>)->Collection<Iterative<'a, G, u64>, D, R> {
Expand All @@ -96,7 +96,7 @@ impl<G: Scope, D: Ord+Data+Debug, R: Abelian> Iterate<G, D, R> for Collection<G,
}
}

impl<G: Scope, D: Ord+Data+Debug, R: Semigroup> Iterate<G, D, R> for G {
impl<G: Scope, D: Ord+Data+Debug, R: Semigroup+'static> Iterate<G, D, R> for G {
fn iterate<F>(&self, logic: F) -> Collection<G, D, R>
where G::Timestamp: Lattice,
for<'a> F: FnOnce(&Collection<Iterative<'a, G, u64>, D, R>)->Collection<Iterative<'a, G, u64>, D, R> {
Expand Down Expand Up @@ -151,7 +151,7 @@ impl<G: Scope, D: Ord+Data+Debug, R: Semigroup> Iterate<G, D, R> for G {
/// });
/// })
/// ```
pub struct Variable<G: Scope, D: Data, R: Abelian>
pub struct Variable<G: Scope, D: Data, R: Abelian+'static>
where G::Timestamp: Lattice {
collection: Collection<G, D, R>,
feedback: Handle<G, Vec<(D, G::Timestamp, R)>>,
Expand Down Expand Up @@ -222,7 +222,7 @@ impl<G: Scope, D: Data, R: Abelian> Deref for Variable<G, D, R> where G::Timesta
/// that do not implement `Abelian` and only implement `Semigroup`. This means
/// that it can be used in settings where the difference type does not support
/// negation.
pub struct SemigroupVariable<G: Scope, D: Data, R: Semigroup>
pub struct SemigroupVariable<G: Scope, D: Data, R: Semigroup+'static>
where G::Timestamp: Lattice {
collection: Collection<G, D, R>,
feedback: Handle<G, Vec<(D, G::Timestamp, R)>>,
Expand Down
Loading

0 comments on commit fc87f61

Please sign in to comment.