Skip to content

Commit 043ef73

Browse files
committed
Document various trait invariants
1 parent 036b4da commit 043ef73

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

timely/src/order.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
/// This trait is distinct from Rust's `PartialOrd` trait, because the implementation
66
/// of that trait precludes a distinct `Ord` implementation. We need an independent
77
/// trait if we want to have a partially ordered type that can also be sorted.
8+
///
9+
/// The partial order should be consistent with [Eq], in the sense that if `a == b` then
10+
/// `a.less_equal(b)` and `b.less_equal(a)`.
811
pub trait PartialOrder : Eq {
912
/// Returns true iff one element is strictly less than the other.
1013
fn less_than(&self, other: &Self) -> bool {

timely/src/progress/timestamp.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ use crate::communication::Data;
99
use crate::order::PartialOrder;
1010

1111
/// A composite trait for types that serve as timestamps in timely dataflow.
12+
///
13+
/// By implementing this trait, you promise that the type's [PartialOrder] implementation
14+
/// is compatible with [Ord], such that if `a.less_equal(b)` then `a <= b`.
1215
pub trait Timestamp: Clone+Eq+PartialOrder+Debug+Send+Any+Data+Hash+Ord {
1316
/// A type summarizing action on a timestamp along a dataflow path.
1417
type Summary : PathSummary<Self> + 'static;
15-
/// A minimum value suitable as a default.
18+
/// A unique minimum value in our partial order, suitable as a default.
1619
fn minimum() -> Self;
1720
}
1821

@@ -28,14 +31,17 @@ pub trait PathSummary<T> : Clone+'static+Eq+PartialOrder+Debug+Default {
2831
/// in computation, uses this method and will drop messages with timestamps that when advanced
2932
/// result in `None`. Ideally, all other timestamp manipulation should behave similarly.
3033
///
34+
/// Note that `Self::default()` is expected to behave as an "empty" or "noop" summary, such that
35+
/// `Self::default().results_in(&t) == Some(t)`.
36+
///
3137
/// # Examples
3238
/// ```
3339
/// use timely::progress::timestamp::PathSummary;
3440
///
3541
/// let timestamp = 3;
3642
///
3743
/// let summary1 = 5;
38-
/// let summary2 = usize::max_value() - 2;
44+
/// let summary2 = usize::MAX - 2;
3945
///
4046
/// assert_eq!(summary1.results_in(&timestamp), Some(8));
4147
/// assert_eq!(summary2.results_in(&timestamp), None);
@@ -45,18 +51,31 @@ pub trait PathSummary<T> : Clone+'static+Eq+PartialOrder+Debug+Default {
4551
///
4652
/// It is possible that the two composed paths result in an invalid summary, for example when
4753
/// integer additions overflow. If it is correct that all timestamps moved along these paths
48-
/// would also result in overflow and be discarded, `followed_by` can return `None. It is very
54+
/// would also result in overflow and be discarded, `followed_by` can return `None`. It is very
4955
/// important that this not be used casually, as this does not prevent the actual movement of
5056
/// data.
5157
///
58+
/// Calling `results_in` on the composed summary should behave the same as though the two
59+
/// summaries were applied to the argument in order.
60+
///
5261
/// # Examples
5362
/// ```
5463
/// use timely::progress::timestamp::PathSummary;
5564
///
5665
/// let summary1 = 5;
57-
/// let summary2 = usize::max_value() - 3;
66+
/// let summary2 = usize::MAX - 3;
5867
///
5968
/// assert_eq!(summary1.followed_by(&summary2), None);
69+
///
70+
/// let time = 10;
71+
/// let summary2 = 15;
72+
/// assert_eq!(
73+
/// // Applying the composed summary...
74+
/// summary1.followed_by(&summary2).and_then(|s| s.results_in(&time)),
75+
/// // ...has the same result as applying the two summaries in sequence.
76+
/// summary1.results_in(&time).and_then(|t| summary2.results_in(&t)),
77+
/// );
78+
///
6079
/// ```
6180
fn followed_by(&self, other: &Self) -> Option<Self>;
6281
}

0 commit comments

Comments
 (0)