Skip to content

Commit 72f34aa

Browse files
Merge pull request #516 from bkirwi/docs
Document various trait invariants / requirements
2 parents 9579b19 + ebb6b24 commit 72f34aa

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

timely/src/order.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,18 @@
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<Rhs: ?Sized = Self>: PartialEq<Rhs> {
9-
/// Returns `true` iff one element is strictly less than the other.
12+
/// Returns true iff one element is strictly less than the other.
13+
#[must_use]
1014
fn less_than(&self, other: &Rhs) -> bool {
1115
self.less_equal(other) && self != other
1216
}
13-
/// Returns `true` iff one element is less than or equal to the other.
17+
18+
/// Returns true iff one element is less than or equal to the other.
19+
#[must_use]
1420
fn less_equal(&self, other: &Rhs) -> bool;
1521
}
1622

timely/src/progress/reachability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ impl<T: Timestamp> Builder<T> {
205205
Tracker::allocate_from(self, logger)
206206
}
207207

208-
/// Tests whether the graph a cycle of default path summaries.
208+
/// Tests whether the graph includes a cycle of default path summaries.
209209
///
210210
/// Graphs containing cycles of default path summaries will most likely
211211
/// not work well with progress tracking, as a timestamp can result in

timely/src/progress/timestamp.rs

+26-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ use crate::ExchangeData;
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+ExchangeData+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,21 @@ 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+
/// This summary's partial order is expected to be compatible with the partial order of [T],
35+
/// in the sense that if `s1.less_equal(s2)`, then `s1.results_in(&t)` is less than or equal to
36+
/// `s2.results_in(&t)`.
37+
///
38+
/// Note that `Self::default()` is expected to behave as an "empty" or "noop" summary, such that
39+
/// `Self::default().results_in(&t) == Some(t)`.
40+
///
3141
/// # Examples
3242
/// ```
3343
/// use timely::progress::timestamp::PathSummary;
3444
///
3545
/// let timestamp = 3;
3646
///
3747
/// let summary1 = 5;
38-
/// let summary2 = usize::max_value() - 2;
48+
/// let summary2 = usize::MAX - 2;
3949
///
4050
/// assert_eq!(summary1.results_in(&timestamp), Some(8));
4151
/// assert_eq!(summary2.results_in(&timestamp), None);
@@ -49,14 +59,27 @@ pub trait PathSummary<T> : Clone+'static+Eq+PartialOrder+Debug+Default {
4959
/// important that this not be used casually, as this does not prevent the actual movement of
5060
/// data.
5161
///
62+
/// Calling `results_in` on the composed summary should behave the same as though the two
63+
/// summaries were applied to the argument in order.
64+
///
5265
/// # Examples
5366
/// ```
5467
/// use timely::progress::timestamp::PathSummary;
5568
///
5669
/// let summary1 = 5;
57-
/// let summary2 = usize::max_value() - 3;
70+
/// let summary2 = usize::MAX - 3;
5871
///
5972
/// assert_eq!(summary1.followed_by(&summary2), None);
73+
///
74+
/// let time = 10;
75+
/// let summary2 = 15;
76+
/// assert_eq!(
77+
/// // Applying the composed summary...
78+
/// summary1.followed_by(&summary2).and_then(|s| s.results_in(&time)),
79+
/// // ...has the same result as applying the two summaries in sequence.
80+
/// summary1.results_in(&time).and_then(|t| summary2.results_in(&t)),
81+
/// );
82+
///
6083
/// ```
6184
fn followed_by(&self, other: &Self) -> Option<Self>;
6285
}

0 commit comments

Comments
 (0)