From a34f2bf574734eeff52230e6afe3f0c08acd6a57 Mon Sep 17 00:00:00 2001 From: Frank McSherry Date: Sun, 26 May 2024 16:17:04 -0400 Subject: [PATCH] Replace covariant PartialOrd with reborrow() --- src/trace/cursor/mod.rs | 2 +- .../implementations/huffman_container.rs | 2 ++ src/trace/implementations/mod.rs | 21 +++++++++++++------ src/trace/implementations/ord_neu.rs | 6 +++--- src/trace/implementations/rhh.rs | 4 ++-- 5 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/trace/cursor/mod.rs b/src/trace/cursor/mod.rs index 8c3cc057d..27e24a13a 100644 --- a/src/trace/cursor/mod.rs +++ b/src/trace/cursor/mod.rs @@ -45,7 +45,7 @@ pub trait Cursor { /// Key by which updates are indexed. type Key<'a>: Copy + Clone + Ord; /// Values associated with keys. - type Val<'a>: Copy + Clone + Ord + for<'b> PartialOrd>; + type Val<'a>: Copy + Clone + Ord; /// Timestamps associated with updates type Time: Timestamp + Lattice + Ord + Clone; /// Associated update. diff --git a/src/trace/implementations/huffman_container.rs b/src/trace/implementations/huffman_container.rs index c3d2496b6..b069d4ce8 100644 --- a/src/trace/implementations/huffman_container.rs +++ b/src/trace/implementations/huffman_container.rs @@ -52,6 +52,8 @@ impl PushInto> for HuffmanContainer { impl BatchContainer for HuffmanContainer { type ReadItem<'a> = Wrapped<'a, B>; + fn reborrow<'b, 'a: 'b>(item: Self::ReadItem<'a>) -> Self::ReadItem<'b> { item } + fn copy(&mut self, item: Self::ReadItem<'_>) { match item.decode() { Ok(decoded) => { diff --git a/src/trace/implementations/mod.rs b/src/trace/implementations/mod.rs index 6a0fe72c9..f7c21ca2b 100644 --- a/src/trace/implementations/mod.rs +++ b/src/trace/implementations/mod.rs @@ -318,6 +318,8 @@ impl BatchContainer for OffsetList { } } + fn reborrow<'b, 'a: 'b>(item: Self::ReadItem<'a>) -> Self::ReadItem<'b> { item } + fn with_capacity(size: usize) -> Self { Self::with_capacity(size) } @@ -427,11 +429,11 @@ where } fn key_eq(this: &&K::Owned, other: <::Container as BatchContainer>::ReadItem<'_>) -> bool { - other.eq(&<<::Container as BatchContainer>::ReadItem<'_> as IntoOwned>::borrow_as(this)) + <::Container as BatchContainer>::reborrow(other).eq(&<::Container as BatchContainer>::reborrow(<<::Container as BatchContainer>::ReadItem<'_> as IntoOwned>::borrow_as(this))) } fn val_eq(this: &&V::Owned, other: <::Container as BatchContainer>::ReadItem<'_>) -> bool { - other.eq(&<<::Container as BatchContainer>::ReadItem<'_> as IntoOwned>::borrow_as(this)) + <::Container as BatchContainer>::reborrow(other).eq(&<::Container as BatchContainer>::reborrow(<<::Container as BatchContainer>::ReadItem<'_> as IntoOwned>::borrow_as(this))) } } @@ -443,12 +445,10 @@ pub mod containers { use timely::container::columnation::{Columnation, TimelyStack}; use timely::container::PushInto; - use std::borrow::ToOwned; - /// A general-purpose container resembling `Vec`. pub trait BatchContainer: 'static { /// The type that can be read back out of the container. - type ReadItem<'a>: Copy + Ord + for<'b> PartialOrd>; + type ReadItem<'a>: Copy + Ord; /// Push an item into this container fn push(&mut self, item: D) where Self: PushInto { @@ -467,6 +467,9 @@ pub mod containers { /// Creates a new container with sufficient capacity. fn merge_capacity(cont1: &Self, cont2: &Self) -> Self; + /// Converts a read item into one with a narrower lifetime. + fn reborrow<'b, 'a: 'b>(item: Self::ReadItem<'a>) -> Self::ReadItem<'b>; + /// Reference to the element at this position. fn index(&self, index: usize) -> Self::ReadItem<'_>; /// Number of contained elements @@ -533,6 +536,8 @@ pub mod containers { impl BatchContainer for Vec { type ReadItem<'a> = &'a T; + fn reborrow<'b, 'a: 'b>(item: Self::ReadItem<'a>) -> Self::ReadItem<'b> { item } + fn copy(&mut self, item: &T) { self.push(item.clone()); } @@ -555,9 +560,11 @@ pub mod containers { // The `ToOwned` requirement exists to satisfy `self.reserve_items`, who must for now // be presented with the actual contained type, rather than a type that borrows into it. - impl + 'static> BatchContainer for TimelyStack { + impl BatchContainer for TimelyStack { type ReadItem<'a> = &'a T; + fn reborrow<'b, 'a: 'b>(item: Self::ReadItem<'a>) -> Self::ReadItem<'b> { item } + fn copy(&mut self, item: &T) { self.copy(item); } @@ -622,6 +629,8 @@ pub mod containers { { type ReadItem<'a> = &'a [B]; + fn reborrow<'b, 'a: 'b>(item: Self::ReadItem<'a>) -> Self::ReadItem<'b> { item } + fn copy(&mut self, item: Self::ReadItem<'_>) { for x in item.iter() { self.inner.copy(x); diff --git a/src/trace/implementations/ord_neu.rs b/src/trace/implementations/ord_neu.rs index 4c7fc006a..c7884e493 100644 --- a/src/trace/implementations/ord_neu.rs +++ b/src/trace/implementations/ord_neu.rs @@ -473,7 +473,7 @@ mod val_batch { } } fn seek_key(&mut self, storage: &OrdValBatch, key: Self::Key<'_>) { - self.key_cursor += storage.storage.keys.advance(self.key_cursor, storage.storage.keys.len(), |x| x.lt(&key)); + self.key_cursor += storage.storage.keys.advance(self.key_cursor, storage.storage.keys.len(), |x| ::reborrow(x).lt(&::reborrow(key))); if self.key_valid(storage) { self.rewind_vals(storage); } @@ -485,7 +485,7 @@ mod val_batch { } } fn seek_val(&mut self, storage: &OrdValBatch, val: Self::Val<'_>) { - self.val_cursor += storage.storage.vals.advance(self.val_cursor, storage.storage.values_for_key(self.key_cursor).1, |x| x.lt(&val)); + self.val_cursor += storage.storage.vals.advance(self.val_cursor, storage.storage.values_for_key(self.key_cursor).1, |x| ::reborrow(x).lt(&::reborrow(val))); } fn rewind_keys(&mut self, storage: &OrdValBatch) { self.key_cursor = 0; @@ -921,7 +921,7 @@ mod key_batch { } } fn seek_key(&mut self, storage: &Self::Storage, key: Self::Key<'_>) { - self.key_cursor += storage.storage.keys.advance(self.key_cursor, storage.storage.keys.len(), |x| x.lt(&key)); + self.key_cursor += storage.storage.keys.advance(self.key_cursor, storage.storage.keys.len(), |x| ::reborrow(x).lt(&::reborrow(key))); if self.key_valid(storage) { self.rewind_vals(storage); } diff --git a/src/trace/implementations/rhh.rs b/src/trace/implementations/rhh.rs index 168ce761b..ef857cac7 100644 --- a/src/trace/implementations/rhh.rs +++ b/src/trace/implementations/rhh.rs @@ -213,7 +213,7 @@ mod val_batch { /// Returns true if one should advance one's index in the search for `key`. fn advance_key(&self, index: usize, key: ::ReadItem<'_>) -> bool { // Ideally this short-circuits, as `self.keys[index]` is bogus data. - !self.live_key(index) || self.keys.index(index).lt(&key) + !self.live_key(index) || self.keys.index(index).lt(&::reborrow(key)) } /// Indicates that a key is valid, rather than dead space, by looking for a valid offset range. @@ -675,7 +675,7 @@ mod val_batch { } } fn seek_val(&mut self, storage: &RhhValBatch, val: Self::Val<'_>) { - self.val_cursor += storage.storage.vals.advance(self.val_cursor, storage.storage.values_for_key(self.key_cursor).1, |x| x.lt(&val)); + self.val_cursor += storage.storage.vals.advance(self.val_cursor, storage.storage.values_for_key(self.key_cursor).1, |x| ::reborrow(x).lt(&::reborrow(val))); } fn rewind_keys(&mut self, storage: &RhhValBatch) { self.key_cursor = 0;