Skip to content

Commit

Permalink
remove lifetime param, encountered the bug: Higher ranked lifetime er…
Browse files Browse the repository at this point in the history
…ror when tryng to see that a future is send. #114046

rust-lang/rust#114046
  • Loading branch information
drmingdrmer committed Sep 27, 2023
1 parent cb526f5 commit 66e321c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 53 deletions.
21 changes: 7 additions & 14 deletions src/meta/raft-store/src/sm_v002/leveled_store/level_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,38 +82,34 @@ impl LevelData {
}
}

impl<'d> MapApiRO<'d, String> for &'d LevelData {
impl<'d> MapApiRO<String> for &'d LevelData {
type GetFut<'f, Q> = impl Future<Output = Marked<<String as MapKey>::V>> + 'f
where
Self: 'f,
'd: 'f,
String: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
Q: 'f;

fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q>
where
// 'd: 'f,
String: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
Q: 'f,
{
async move { self.kv.get(key).cloned().unwrap_or(Marked::empty()) }
}

type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (String, Marked<<String as MapKey>::V>)>>
type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (String, Marked<<String as MapKey>::V>)>> + 'f
where
Self: 'f,
'd: 'f,
String: Borrow<Q>,
R: RangeBounds<Q> + Send + Sync + Clone,
R: 'f,
R: 'f,
Q: Ord + Send + Sync + ?Sized,
Q: 'f;

fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R>
where
'd: 'f,
String: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
R: RangeBounds<Q> + Clone + Send + Sync,
Expand All @@ -126,7 +122,7 @@ impl<'d> MapApiRO<'d, String> for &'d LevelData {
}
}

impl<'me> MapApi<'me, String> for &'me mut LevelData {
impl<'me> MapApi<String> for &'me mut LevelData {
type RO<'o> = &'o LevelData where Self: 'o;

fn to_ro<'o>(&'o self) -> Self::RO<'o> {
Expand All @@ -143,7 +139,7 @@ impl<'me> MapApi<'me, String> for &'me mut LevelData {
value: Option<(<String as MapKey>::V, Option<KVMeta>)>,
) -> Self::SetFut<'f>
where
'me: 'f,
Self: 'f,
{
// The chance it is the bottom level is very low in a loaded system.
// Thus we always tombstone the key if it is None.
Expand All @@ -167,11 +163,10 @@ impl<'me> MapApi<'me, String> for &'me mut LevelData {
}
}

impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData {
impl<'d> MapApiRO<ExpireKey> for &'d LevelData {
type GetFut<'f, Q> = impl Future<Output = Marked<<ExpireKey as MapKey>::V>> + 'f
where
Self: 'f,
'd: 'f,
ExpireKey: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
Q: 'f;
Expand All @@ -189,7 +184,6 @@ impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData {
type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (ExpireKey, Marked<<ExpireKey as MapKey>::V>)>> + 'f
where
Self: 'f,
'd: 'f,
ExpireKey: Borrow<Q>,
R: RangeBounds<Q> + Send + Sync + Clone,
R: 'f,
Expand All @@ -198,7 +192,6 @@ impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData {

fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R>
where
'd: 'f,
ExpireKey: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
R: RangeBounds<Q> + Clone + Send + Sync,
Expand All @@ -215,7 +208,7 @@ impl<'d> MapApiRO<'d, ExpireKey> for &'d LevelData {
}
}

impl<'me> MapApi<'me, ExpireKey> for &'me mut LevelData {
impl<'me> MapApi<ExpireKey> for &'me mut LevelData {
type RO<'o> = &'o LevelData
where Self: 'o;

Expand Down
35 changes: 15 additions & 20 deletions src/meta/raft-store/src/sm_v002/leveled_store/leveled_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,23 +58,22 @@ impl<'d> LeveledRef<'d> {
}
}

impl<'d, K> MapApiRO<'d, K> for LeveledRef<'d>
impl<'d, K> MapApiRO<K> for LeveledRef<'d>
where
K: MapKey + fmt::Debug,
// &'d LevelData: MapApiRO<'d, K>,
for<'him> &'him LevelData: MapApiRO<'him, K>,
// &'d LevelData: MapApiRO<K>,
for<'him> &'him LevelData: MapApiRO<K>,
// &'him LevelData: MapApiRO<K>,
{
type GetFut<'f, Q> = impl Future<Output = Marked<K::V>> + 'f
where
Self: 'f,
'd: 'f,
K: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
Q: 'f;

fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q>
where
'd: 'f,
K: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
Q: 'f,
Expand All @@ -90,10 +89,9 @@ where
}
}

type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (K, Marked<K::V>)>>
type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (K, Marked<K::V>)>> + 'f
where
Self: 'f,
'd: 'f,
K: Borrow<Q>,
R: RangeBounds<Q> + Send + Sync + Clone,
R:'f,
Expand All @@ -102,7 +100,6 @@ where

fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R>
where
'd: 'f,
K: Borrow<Q>,
R: RangeBounds<Q> + Clone + Send + Sync,
R: 'f,
Expand Down Expand Up @@ -176,15 +173,14 @@ impl<'d> LeveledRefMut<'d> {

// Because `LeveledRefMut` has a mut ref of lifetime 'd,
// `self` must outlive 'd otherwise there will be two mut ref.
impl<'d, K> MapApiRO<'d, K> for LeveledRefMut<'d>
impl<'d, K> MapApiRO<K> for LeveledRefMut<'d>
where
K: MapKey,
for<'him> &'him LevelData: MapApiRO<'him, K>,
for<'him> &'him LevelData: MapApiRO<K>,
{
type GetFut<'f, Q> = impl Future<Output = Marked<K::V>> + 'f
where
Self: 'f,
'd: 'f,
K: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
Q: 'f;
Expand All @@ -209,7 +205,6 @@ where
type RangeFut<'f, Q, R> = impl Future<Output = BoxStream<'f, (K, Marked<K::V>)>> +'f
where
Self: 'f,
'd: 'f,
K: Borrow<Q>,
R: RangeBounds<Q> + Send + Sync + Clone,
R: 'f,
Expand All @@ -227,11 +222,11 @@ where
}
}

impl<'d, K> MapApi<'d, K> for LeveledRefMut<'d>
impl<'d, K> MapApi<K> for LeveledRefMut<'d>
where
K: MapKey,
for<'him> &'him LevelData: MapApiRO<'him, K>,
for<'him> &'him mut LevelData: MapApi<'him, K>,
for<'him> &'him LevelData: MapApiRO<K>,
for<'him> &'him mut LevelData: MapApi<K>,
{
type RO<'o> = LeveledRef<'o>
where Self: 'o;
Expand Down Expand Up @@ -342,10 +337,10 @@ impl LeveledMap {
}
}

impl<'d, K> MapApiRO<'d, K> for &'d LeveledMap
impl<'d, K> MapApiRO<K> for &'d LeveledMap
where
K: MapKey + fmt::Debug,
for<'him> &'him LevelData: MapApiRO<'him, K>,
for<'him> &'him LevelData: MapApiRO<K>,
{
type GetFut<'f, Q> = impl Future<Output = Marked<K::V>> + 'f
where
Expand Down Expand Up @@ -386,11 +381,11 @@ where
}
}

impl<'me, K> MapApi<'me, K> for &'me mut LeveledMap
impl<'me, K> MapApi<K> for &'me mut LeveledMap
where
K: MapKey,
for<'e> &'e LevelData: MapApiRO<'e, K>,
for<'him> &'him mut LevelData: MapApi<'him, K>,
for<'e> &'e LevelData: MapApiRO<K>,
for<'him> &'him mut LevelData: MapApi<K>,
{
type RO<'o> = LeveledRef<'o>
where Self: 'o;
Expand Down
24 changes: 9 additions & 15 deletions src/meta/raft-store/src/sm_v002/leveled_store/map_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ impl<V> MapValue for V where V: Clone + Send + Sync + Unpin + 'static {}
///
/// There is no lifetime constraint on the trait,
/// and it's the implementation's duty to specify a valid lifetime constraint.
pub(in crate::sm_v002) trait MapApiRO<'d, K>: Send + Sync
pub(in crate::sm_v002) trait MapApiRO<K>: Send + Sync
where K: MapKey
{
type GetFut<'f, Q>: Future<Output = Marked<K::V>>
where
Self: 'f,
'd: 'f,
K: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
Q: 'f;
Expand All @@ -78,7 +77,6 @@ where K: MapKey
type RangeFut<'f, Q, R>: Future<Output = BoxStream<'f, (K, Marked<K::V>)>>
where
Self: 'f,
'd: 'f,
K: Borrow<Q>,
R: RangeBounds<Q> + Send + Sync + Clone,
R: 'f,
Expand All @@ -97,10 +95,10 @@ where K: MapKey
}

/// Provide a read-write key-value map API set, used to access state machine data.
pub(in crate::sm_v002) trait MapApi<'d, K>: MapApiRO<'d, K>
pub(in crate::sm_v002) trait MapApi<K>: MapApiRO<K>
where K: MapKey
{
type RO<'o>: MapApiRO<'o, K>
type RO<'o>: MapApiRO<K>
where Self: 'o;

fn to_ro<'o>(&'o self) -> Self::RO<'o>;
Expand All @@ -124,7 +122,7 @@ impl MapApiExt {
) -> (Marked<K::V>, Marked<K::V>)
where
K: MapKey,
&'d mut T: MapApi<'d, K>,
&'d mut T: MapApi<K>,
{
//
let got = s.to_ro().get(&key).await;
Expand All @@ -147,7 +145,7 @@ impl MapApiExt {
) -> (Marked<K::V>, Marked<K::V>)
where
K: MapKey,
&'d mut T: MapApi<'d, K>,
&'d mut T: MapApi<K>,
{
let got = s.to_ro().get(&key).await;

Expand All @@ -161,37 +159,34 @@ impl MapApiExt {
}
}

impl<'ro_me, 'ro_d, K, T> MapApiRO<'ro_d, K> for &'ro_me mut T
impl<'ro_me, K, T> MapApiRO<K> for &'ro_me mut T
where
K: MapKey,
&'ro_me T: MapApiRO<'ro_d, K>,
&'ro_me T: MapApiRO<K>,
K: Ord + Send + Sync + 'static,
T: Send + Sync,
{
type GetFut<'f, Q> = <&'ro_me T as MapApiRO<'ro_d, K>>::GetFut<'f, Q>
type GetFut<'f, Q> = <&'ro_me T as MapApiRO<K>>::GetFut<'f, Q>
where
Self: 'f,
'ro_me: 'f,
'ro_d: 'f,
K: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
Q: 'f;

fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q>
where
'ro_me: 'f,
'ro_d: 'f,
K: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
{
(&*self).get(key)
}

type RangeFut<'f, Q, R> = <&'ro_me T as MapApiRO<'ro_d, K>>::RangeFut<'f, Q, R>
type RangeFut<'f, Q, R> = <&'ro_me T as MapApiRO<K>>::RangeFut<'f, Q, R>
where
Self: 'f,
'ro_me: 'f,
'ro_d: 'f,
K: Borrow<Q>,
R: RangeBounds<Q> + Send + Sync + Clone,
R: 'f,
Expand All @@ -201,7 +196,6 @@ where
fn range<'f, Q, R>(self, range: R) -> Self::RangeFut<'f, Q, R>
where
'ro_me: 'f,
'ro_d: 'f,
K: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
R: RangeBounds<Q> + Clone + Send + Sync,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,22 +62,20 @@ impl StaticLeveledMap {
}
}

impl<'d, K> MapApiRO<'d, K> for &'d StaticLeveledMap
impl<'d, K> MapApiRO<K> for &'d StaticLeveledMap
where
K: MapKey,
for<'him> &'him LevelData: MapApiRO<'him, K>,
for<'him> &'him LevelData: MapApiRO<K>,
{
type GetFut<'f, Q> = impl Future<Output = Marked<K::V>> + 'f
where
Self: 'f,
'd: 'f,
K: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
Q: 'f;

fn get<'f, Q>(self, key: &'f Q) -> Self::GetFut<'f, Q>
where
'd: 'f,
K: Borrow<Q>,
Q: Ord + Send + Sync + ?Sized,
Q: 'f,
Expand Down

0 comments on commit 66e321c

Please sign in to comment.