Skip to content

Commit 04f2c61

Browse files
committed
frontier: tighter integration with rust traits
The `frontier` module implements a common Rust pattern where there is one type representing a mutable version of something and a separate type representing its immutable counterpart. Examples in std are `String` and `str`, `PathBuf` and `Path`, `OsString` and `OsStr`, and other. In all the examples above the mutable version holds onto a heap allocated buffer and the immutable version is just a `#[repr(transparent)]` wrapper over an raw unsized slice of the data type. This patch changes `AntichainRef<T>` to simply be a transparent wrapper over `[T]`. This change enables `Deref` implementations targeting the immutable antichain from both `MutableAntichain<T>` and `Antichain<T>`. This has a bunch of ergonomic improvements for users (due to auto-deref) and also allows having a single implementation of all methods that only need immutable access to the antichain. Specifically, the following methods have been deduplicated and are now implemented in only once place: * `AntichainRef::less_than` * `AntichainRef::less_equal` * `AntichainRef::dominates` * `AntichainRef::elements` * `<AntichainRef as PartialEq>::eq` * `<AntichainRef as PartialOrd>::partial_cmp` * `<AntichainRef as Hash>::hash` Finally, this change also enables replacing the inherent `Antichain::borrow` and `Antichain::to_owned` methods by implementing the `std::borrow::Borrow` and `std::borrow::ToOwned` traits respectively. Signed-off-by: Petros Angelatos <[email protected]>
1 parent 7ad8962 commit 04f2c61

File tree

6 files changed

+117
-212
lines changed

6 files changed

+117
-212
lines changed

timely/src/dataflow/operators/capability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl<T: Timestamp> CapabilitySet<T> {
403403
/// let mut cap = CapabilitySet::from_elem(default_cap);
404404
/// let mut vector = Vec::new();
405405
/// move |input, output| {
406-
/// cap.downgrade(&input.frontier().frontier());
406+
/// cap.downgrade(&**input.frontier());
407407
/// while let Some((time, data)) = input.next() {
408408
/// data.swap(&mut vector);
409409
/// }

timely/src/dataflow/operators/generic/notificator.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ impl<'a, T: Timestamp> Notificator<'a, T> {
4040
}
4141

4242
/// Reveals the elements in the frontier of the indicated input.
43-
pub fn frontier(&self, input: usize) -> AntichainRef<T> {
44-
self.frontiers[input].frontier()
43+
pub fn frontier(&self, input: usize) -> &AntichainRef<T> {
44+
self.frontiers[input]
4545
}
4646

4747
/// Requests a notification at the time associated with capability `cap`.

timely/src/dataflow/operators/inspect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ impl<G: Scope, C: Container> InspectCore<G, C> for StreamCore<G, C> {
124124
let mut frontier = crate::progress::Antichain::from_elem(G::Timestamp::minimum());
125125
let mut vector = Default::default();
126126
self.unary_frontier(Pipeline, "InspectBatch", move |_,_| move |input, output| {
127-
if input.frontier.frontier() != frontier.borrow() {
127+
if input.frontier != &frontier {
128128
frontier.clear();
129-
frontier.extend(input.frontier.frontier().iter().cloned());
129+
frontier.extend(input.frontier.iter().cloned());
130130
func(Err(frontier.elements()));
131131
}
132132
input.for_each(|time, data| {

timely/src/dataflow/operators/probe.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,8 @@ impl<T: Timestamp> Handle<T> {
166166
/// let frontier = handle.with_frontier(|frontier| frontier.to_vec());
167167
/// ```
168168
#[inline]
169-
pub fn with_frontier<R, F: FnMut(AntichainRef<T>)->R>(&self, mut function: F) -> R {
170-
function(self.frontier.borrow().frontier())
169+
pub fn with_frontier<R, F: FnMut(&AntichainRef<T>)->R>(&self, mut function: F) -> R {
170+
function(&self.frontier.borrow())
171171
}
172172
}
173173

0 commit comments

Comments
 (0)