Skip to content

Commit

Permalink
refactor: remove unstable feature let_chains and lint_reasons (#315)
Browse files Browse the repository at this point in the history
Signed-off-by: MrCroxx <mrcroxx@outlook.com>
  • Loading branch information
MrCroxx committed Apr 10, 2024
1 parent cd1da35 commit 0423ca0
Show file tree
Hide file tree
Showing 18 changed files with 73 additions and 59 deletions.
6 changes: 4 additions & 2 deletions foyer-common/src/code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,8 @@ pub trait Cursor<T>: Send + Sync + 'static + std::io::Read + std::fmt::Debug {
/// [`Key`] is required to implement [`Clone`].
///
/// If cloning a [`Key`] is expensive, wrap it with [`Arc`].
#[expect(unused_variables)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(unused_variables)]
pub trait Key:
Sized + Send + Sync + 'static + std::hash::Hash + Eq + PartialEq + Ord + PartialOrd + std::fmt::Debug + Clone
{
Expand All @@ -122,7 +123,8 @@ pub trait Key:
/// [`Value`] is required to implement [`Clone`].
///
/// If cloning a [`Value`] is expensive, wrap it with [`Arc`].
#[expect(unused_variables)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(unused_variables)]
pub trait Value: Sized + Send + Sync + 'static + std::fmt::Debug + Clone {
type Cursor: Cursor<Self> = UnimplementedCursor<Self>;

Expand Down
1 change: 0 additions & 1 deletion foyer-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

#![feature(trait_alias)]
#![feature(lint_reasons)]
#![feature(bound_map)]
#![feature(associated_type_defaults)]
#![feature(cfg_match)]
Expand Down
1 change: 0 additions & 1 deletion foyer-experimental/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// limitations under the License.

#![feature(cfg_match)]
#![feature(lint_reasons)]
#![feature(error_generic_member_access)]
#![feature(lazy_cell)]

Expand Down
4 changes: 2 additions & 2 deletions foyer-intrusive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

#![feature(ptr_metadata)]
#![feature(trait_alias)]
#![feature(lint_reasons)]
#![feature(offset_of)]
#![expect(clippy::new_without_default)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#![allow(clippy::new_without_default)]

pub use memoffset::offset_of;

Expand Down
12 changes: 6 additions & 6 deletions foyer-memory/src/eviction/s3fifo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ where
V: Value,
{
unsafe fn evict(&mut self) -> Option<NonNull<<S3Fifo<K, V> as Eviction>::Handle>> {
if self.small_charges > self.small_capacity
&& let Some(ptr) = self.evict_small()
{
Some(ptr)
} else {
self.evict_main()
// TODO(MrCroxx): Use `let_chains` here after it is stable.
if self.small_charges > self.small_capacity {
if let Some(ptr) = self.evict_small() {
return Some(ptr);
}
}
self.evict_main()
}

unsafe fn evict_small(&mut self) -> Option<NonNull<<S3Fifo<K, V> as Eviction>::Handle>> {
Expand Down
3 changes: 2 additions & 1 deletion foyer-memory/src/eviction/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
use super::Eviction;
use crate::handle::Handle;

#[expect(clippy::type_complexity)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(clippy::type_complexity)]
pub trait TestEviction: Eviction {
fn dump(&self) -> Vec<(<Self::Handle as Handle>::Key, <Self::Handle as Handle>::Value)>;
}
18 changes: 12 additions & 6 deletions foyer-memory/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ struct CacheSharedState<T, L> {
listener: L,
}

#[expect(clippy::type_complexity)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(clippy::type_complexity)]
struct CacheShard<K, V, H, E, I, L, S>
where
K: Key,
Expand Down Expand Up @@ -198,9 +199,12 @@ where
}

unsafe fn evict(&mut self, charge: usize, last_reference_entries: &mut Vec<(K, V, H::Context, usize)>) {
while self.usage.load(Ordering::Relaxed) + charge > self.capacity
&& let Some(evicted) = self.eviction.pop()
{
// TODO(MrCroxx): Use `let_chains` here after it is stable.
while self.usage.load(Ordering::Relaxed) + charge > self.capacity {
let evicted = match self.eviction.pop() {
Some(evicted) => evicted,
None => break,
};
self.state.metrics.evict.fetch_add(1, Ordering::Relaxed);
let base = evicted.as_ref().base();
debug_assert!(base.is_in_indexer());
Expand Down Expand Up @@ -304,7 +308,8 @@ where
pub event_listener: L,
}

#[expect(clippy::type_complexity)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(clippy::type_complexity)]
pub enum GenericEntry<K, V, H, E, I, L, S, ER>
where
K: Key,
Expand Down Expand Up @@ -364,7 +369,8 @@ where
}
}

#[expect(clippy::type_complexity)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(clippy::type_complexity)]
pub struct GenericCache<K, V, H, E, I, L, S = RandomState>
where
K: Key,
Expand Down
3 changes: 0 additions & 3 deletions foyer-memory/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![feature(let_chains)]
#![feature(lint_reasons)]

//! This crate provides a concurrent in-memory cache component that supports replaceable eviction algorithm.
//!
//! # Motivation
Expand Down
23 changes: 11 additions & 12 deletions foyer-storage-bench/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![feature(let_chains)]
#![feature(lint_reasons)]

mod analyze;
mod export;
mod rate;
Expand Down Expand Up @@ -754,13 +751,14 @@ async fn write(
}

let idx = id + step * c;
// TODO(MrCroxx): Use random content?
let entry_size = OsRng.gen_range(context.entry_size_range.clone());
let data = Arc::new(text(idx as usize, entry_size));
if let Some(limiter) = &mut limiter
&& let Some(wait) = limiter.consume(entry_size as f64)
{
tokio::time::sleep(wait).await;

// TODO(MrCroxx): Use `let_chains` here after it is stable.
if let Some(limiter) = &mut limiter {
if let Some(wait) = limiter.consume(entry_size as f64) {
tokio::time::sleep(wait).await;
}
}

let time = Instant::now();
Expand Down Expand Up @@ -849,10 +847,11 @@ async fn read(
}
context.metrics.get_bytes.fetch_add(entry_size, Ordering::Relaxed);

if let Some(limiter) = &mut limiter
&& let Some(wait) = limiter.consume(entry_size as f64)
{
tokio::time::sleep(wait).await;
// TODO(MrCroxx): Use `let_chains` here after it is stable.
if let Some(limiter) = &mut limiter {
if let Some(wait) = limiter.consume(entry_size as f64) {
tokio::time::sleep(wait).await;
}
}
} else {
if let Err(e) = context.metrics.get_miss_lats.write().record(lat) {
Expand Down
3 changes: 1 addition & 2 deletions foyer-storage/src/admission/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ where
}
}

#[expect(unused_variables)]
pub trait AdmissionPolicy: Send + Sync + 'static + Debug {
type Key: Key;
type Value: Value;

fn init(&self, context: AdmissionContext<Self::Key, Self::Value>) {}
fn init(&self, context: AdmissionContext<Self::Key, Self::Value>);

fn judge(&self, key: &Self::Key, weight: usize) -> bool;

Expand Down
3 changes: 2 additions & 1 deletion foyer-storage/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,8 @@ where
/// # Format
///
/// | header | value (compressed) | key | <padding> |
#[expect(clippy::uninit_vec)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(clippy::uninit_vec)]
pub async fn write(
&mut self,
Entry {
Expand Down
22 changes: 12 additions & 10 deletions foyer-storage/src/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ where
item.inserted = Some(Instant::now());
guard.insert(key.clone(), item)
};
if let Some(old) = old
&& let Index::Inflight { .. } = old.index()
{
self.metrics
.inner_op_duration_entry_flush
.observe(old.inserted.unwrap().elapsed().as_secs_f64());
// TODO(MrCroxx): Use `let_chains` here after it is stable.
if let Some(old) = old {
if let Index::Inflight { .. } = old.index() {
self.metrics
.inner_op_duration_entry_flush
.observe(old.inserted.unwrap().elapsed().as_secs_f64());
}
}
}

Expand All @@ -147,10 +148,11 @@ where
pub fn remove(&self, key: &K) -> Option<Item<K, V>> {
let shard = self.shard(key);
let info: Option<Item<K, V>> = self.items[shard].write().remove(key);
if let Some(info) = &info
&& let Index::Region { view } = &info.index
{
self.regions[*view.id() as usize].lock().remove(key);
// TODO(MrCroxx): Use `let_chains` here after it is stable.
if let Some(info) = &info {
if let Index::Region { view } = &info.index {
self.regions[*view.id() as usize].lock().remove(key);
}
}
info
}
Expand Down
6 changes: 4 additions & 2 deletions foyer-storage/src/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,8 @@ where

let (flushers_stop_tx, _) = broadcast::channel(DEFAULT_BROADCAST_CAPACITY);
let flusher_stop_rxs = (0..config.flushers).map(|_| flushers_stop_tx.subscribe()).collect_vec();
#[expect(clippy::type_complexity)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(clippy::type_complexity)]
let (flusher_entry_txs, flusher_entry_rxs): (
Vec<mpsc::UnboundedSender<Entry<K, V>>>,
Vec<mpsc::UnboundedReceiver<Entry<K, V>>>,
Expand Down Expand Up @@ -1081,7 +1082,8 @@ mod tests {
type TestStoreConfig = GenericStoreConfig<u64, Vec<u8>, FsDevice, Fifo<RegionEpItemAdapter<FifoLink>>>;

#[tokio::test]
#[expect(clippy::identity_op)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(clippy::identity_op)]
async fn test_recovery() {
const KB: usize = 1024;
const MB: usize = 1024 * 1024;
Expand Down
2 changes: 0 additions & 2 deletions foyer-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@
#![feature(strict_provenance)]
#![feature(trait_alias)]
#![feature(get_mut_unchecked)]
#![feature(let_chains)]
#![feature(error_generic_member_access)]
#![feature(lazy_cell)]
#![feature(lint_reasons)]
#![feature(box_into_inner)]
#![feature(try_trait_v2)]
#![feature(offset_of)]
Expand Down
9 changes: 6 additions & 3 deletions foyer-storage/src/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ pub struct RegionInner<A>
where
A: BufferAllocator,
{
#[expect(clippy::type_complexity)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(clippy::type_complexity)]
waits: BTreeMap<(usize, usize), Vec<oneshot::Sender<Result<Arc<Vec<u8, A>>>>>>,
}

Expand Down Expand Up @@ -152,7 +153,8 @@ where
}

/// Load region data by view from device.
#[expect(clippy::type_complexity)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(clippy::type_complexity)]
#[tracing::instrument(skip(self, view))]
pub async fn load(&self, view: RegionView) -> Result<Option<Arc<Vec<u8, D::IoBufferAllocator>>>> {
let res = self
Expand All @@ -164,7 +166,8 @@ where
}

/// Load region data with given `range` from device.
#[expect(clippy::type_complexity)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#[allow(clippy::type_complexity)]
#[tracing::instrument(skip(self, range), fields(start, end))]
pub async fn load_range(
&self,
Expand Down
3 changes: 1 addition & 2 deletions foyer-storage/src/reinsertion/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,11 @@ where
}
}

#[expect(unused_variables)]
pub trait ReinsertionPolicy: Send + Sync + 'static + Debug {
type Key: Key;
type Value: Value;

fn init(&self, context: ReinsertionContext<Self::Key, Self::Value>) {}
fn init(&self, context: ReinsertionContext<Self::Key, Self::Value>);

fn judge(&self, key: &Self::Key, weight: usize) -> bool;

Expand Down
9 changes: 8 additions & 1 deletion foyer-storage/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ use std::{collections::HashSet, marker::PhantomData};
use foyer_common::code::{Key, Value};
use parking_lot::Mutex;

use crate::{admission::AdmissionPolicy, reinsertion::ReinsertionPolicy};
use crate::{
admission::{AdmissionContext, AdmissionPolicy},
reinsertion::{ReinsertionContext, ReinsertionPolicy},
};

#[derive(Debug, Clone)]
pub enum Record<K: Key> {
Expand Down Expand Up @@ -83,6 +86,8 @@ where

type Value = V;

fn init(&self, _: AdmissionContext<Self::Key, Self::Value>) {}

fn judge(&self, key: &K, _weight: usize) -> bool {
self.records.lock().push(Record::Admit(key.clone()));
true
Expand All @@ -102,6 +107,8 @@ where

type Value = V;

fn init(&self, _: ReinsertionContext<Self::Key, Self::Value>) {}

fn judge(&self, key: &K, _weight: usize) -> bool {
self.records.lock().push(Record::Evict(key.clone()));
false
Expand Down
4 changes: 2 additions & 2 deletions foyer-storage/tests/storage_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#![feature(lint_reasons)]
#![expect(clippy::identity_op)]
// TODO(MrCroxx): use `expect` after `lint_reasons` is stable.
#![allow(clippy::identity_op)]

use std::{path::PathBuf, sync::Arc, time::Duration};

Expand Down

0 comments on commit 0423ca0

Please sign in to comment.