Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace triomphe::Arc with our own MiniArc type #47

Open
wants to merge 3 commits into
base: v0.11.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions .github/workflows/Loom.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Loom

on:
push:
paths-ignore:
- '.devcontainer/**'
- '.vscode/**'
- 'tests/**'
pull_request:
paths-ignore:
- '.devcontainer/**'
- '.vscode/**'
- 'tests/**'
schedule:
# Run against the last commit on the default branch on Friday at 8pm (UTC?)
- cron: '0 20 * * 5'

jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
# https://github.com/marketplace/actions/skip-duplicate-actions
uses: fkirc/skip-duplicate-actions@v5
with:
concurrent_skipping: 'same_content'
do_not_skip: '["pull_request", "workflow_dispatch", "schedule"]'

test:
needs: pre_job
if: needs.pre_job.outputs.should_skip != 'true'
runs-on: ubuntu-latest

steps:
- name: Checkout Mini Moka
uses: actions/checkout@v4

- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@master
with:
toolchain: stable

- name: Run tests in concurrent::arc module
run: cargo test --release --lib common::concurrent::arc::loom_tests
env:
RUSTFLAGS: '--cfg moka_loom'
15 changes: 14 additions & 1 deletion .github/workflows/Miri.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,18 @@ jobs:

- run: cargo clean

- name: Run Miri test (deque)
- name: Run Miri test on arc module using tree borrows
run: cargo miri test arc
env:
MIRIFLAGS: '-Zmiri-tree-borrows'

- name: Run Miri test on deque module using tree borrows
run: cargo miri test deque
env:
MIRIFLAGS: '-Zmiri-tree-borrows'

- name: Run Miri test on arc module using stacked borrows
run: cargo miri test arc

- name: Run Miri test on deque module using stacked borrows
run: cargo miri test deque
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ crossbeam-utils = "0.8"
smallvec = "1.8"
tagptr = "0.2"

# Opt-out serde and stable_deref_trait features
# https://github.com/Manishearth/triomphe/pull/5
triomphe = { version = "0.1.13", default-features = false }

# Optional dependencies (enabled by default)
dashmap = { version = "6.1", optional = true }

Expand All @@ -46,11 +42,15 @@ trybuild = "1.0"
features = []
rustdoc-args = ["--cfg", "docsrs"]

[target.'cfg(moka_loom)'.dependencies]
loom = "0.7"

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = [
"cfg(beta_clippy)",
"cfg(circleci)",
"cfg(kani)",
"cfg(moka_loom)",
"cfg(skeptic)",
"cfg(circleci)",
"cfg(trybuild)",
"cfg(beta_clippy)",
] }
2 changes: 1 addition & 1 deletion LICENSE-APACHE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2020 - 2024 Tatsuya Kawano
Copyright 2020 - 2025 Tatsuya Kawano

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 - 2024 Tatsuya Kawano
Copyright (c) 2020 - 2025 Tatsuya Kawano

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
[![dependency status][deps-rs-badge]][deps-rs]
<!-- [![coverage status][coveralls-badge]][coveralls] -->
[![license][license-badge]](#license)
<!-- [![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmoka-rs%2Fmini-moka.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Fmoka-rs%2Fmini-moka?ref=badge_shield) -->

Mini Moka is a fast, concurrent cache library for Rust. Mini Moka is a light edition
of [Moka][moka-git].
Expand All @@ -24,14 +23,12 @@ algorithm to determine which entries to evict when the capacity is exceeded.
[deps-rs-badge]: https://deps.rs/repo/github/moka-rs/mini-moka/status.svg
<!-- [coveralls-badge]: https://coveralls.io/repos/github/mini-moka-rs/moka/badge.svg?branch=main -->
[license-badge]: https://img.shields.io/crates/l/mini-moka.svg
<!-- [fossa-badge]: https://app.fossa.com/api/projects/git%2Bgithub.com%2Fmoka-rs%2Fmini-moka.svg?type=shield -->

[gh-actions]: https://github.com/moka-rs/mini-moka/actions?query=workflow%3ACI
[crate]: https://crates.io/crates/mini-moka
[docs]: https://docs.rs/mini-moka
[deps-rs]: https://deps.rs/repo/github/moka-rs/mini-moka
<!-- [coveralls]: https://coveralls.io/github/moka-rs/mini-moka?branch=main -->
<!-- [fossa]: https://app.fossa.com/projects/git%2Bgithub.com%2Fmoka-rs%2Fmini-moka?ref=badge_shield -->

[moka-git]: https://github.com/moka-rs/moka
[caffeine-git]: https://github.com/ben-manes/caffeine
Expand Down
35 changes: 17 additions & 18 deletions src/common/concurrent.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use crate::common::{deque::DeqNode, time::Instant};

use std::{ptr::NonNull, sync::Arc};
use tagptr::TagNonNull;
use triomphe::Arc as TrioArc;

pub(crate) mod arc;
pub(crate) mod constants;
pub(crate) mod deques;
pub(crate) mod entry_info;
pub(crate) mod housekeeper;

pub(crate) mod atomic_time;

use self::entry_info::EntryInfo;
use self::{arc::MiniArc, entry_info::EntryInfo};
use crate::common::{deque::DeqNode, time::Instant};

pub(crate) type Weigher<K, V> = Arc<dyn Fn(&K, &V) -> u32 + Send + Sync + 'static>;

Expand Down Expand Up @@ -44,14 +43,14 @@ impl<K> Clone for KeyHash<K> {

pub(crate) struct KeyDate<K> {
key: Arc<K>,
entry_info: TrioArc<EntryInfo<K>>,
entry_info: MiniArc<EntryInfo<K>>,
}

impl<K> KeyDate<K> {
pub(crate) fn new(key: Arc<K>, entry_info: &TrioArc<EntryInfo<K>>) -> Self {
pub(crate) fn new(key: Arc<K>, entry_info: &MiniArc<EntryInfo<K>>) -> Self {
Self {
key,
entry_info: TrioArc::clone(entry_info),
entry_info: MiniArc::clone(entry_info),
}
}

Expand All @@ -63,15 +62,15 @@ impl<K> KeyDate<K> {
pub(crate) struct KeyHashDate<K> {
key: Arc<K>,
hash: u64,
entry_info: TrioArc<EntryInfo<K>>,
entry_info: MiniArc<EntryInfo<K>>,
}

impl<K> KeyHashDate<K> {
pub(crate) fn new(kh: KeyHash<K>, entry_info: &TrioArc<EntryInfo<K>>) -> Self {
pub(crate) fn new(kh: KeyHash<K>, entry_info: &MiniArc<EntryInfo<K>>) -> Self {
Self {
key: kh.key,
hash: kh.hash,
entry_info: TrioArc::clone(entry_info),
entry_info: MiniArc::clone(entry_info),
}
}

Expand All @@ -90,11 +89,11 @@ impl<K> KeyHashDate<K> {

pub(crate) struct KvEntry<K, V> {
pub(crate) key: Arc<K>,
pub(crate) entry: TrioArc<ValueEntry<K, V>>,
pub(crate) entry: MiniArc<ValueEntry<K, V>>,
}

impl<K, V> KvEntry<K, V> {
pub(crate) fn new(key: Arc<K>, entry: TrioArc<ValueEntry<K, V>>) -> Self {
pub(crate) fn new(key: Arc<K>, entry: MiniArc<ValueEntry<K, V>>) -> Self {
Self { key, entry }
}
}
Expand Down Expand Up @@ -151,18 +150,18 @@ pub(crate) type KeyDeqNodeWo<K> = NonNull<DeqNode<KeyDate<K>>>;

pub(crate) struct ValueEntry<K, V> {
pub(crate) value: V,
info: TrioArc<EntryInfo<K>>,
info: MiniArc<EntryInfo<K>>,
}

impl<K, V> ValueEntry<K, V> {
pub(crate) fn new(value: V, entry_info: TrioArc<EntryInfo<K>>) -> Self {
pub(crate) fn new(value: V, entry_info: MiniArc<EntryInfo<K>>) -> Self {
Self {
value,
info: entry_info,
}
}

pub(crate) fn entry_info(&self) -> &TrioArc<EntryInfo<K>> {
pub(crate) fn entry_info(&self) -> &MiniArc<EntryInfo<K>> {
&self.info
}

Expand Down Expand Up @@ -216,7 +215,7 @@ impl<K, V> ValueEntry<K, V> {
}
}

impl<K, V> AccessTime for TrioArc<ValueEntry<K, V>> {
impl<K, V> AccessTime for MiniArc<ValueEntry<K, V>> {
#[inline]
fn last_accessed(&self) -> Option<Instant> {
self.info.last_accessed()
Expand All @@ -240,14 +239,14 @@ impl<K, V> AccessTime for TrioArc<ValueEntry<K, V>> {

pub(crate) enum ReadOp<K, V> {
// u64 is the hash of the key.
Hit(u64, TrioArc<ValueEntry<K, V>>, Instant),
Hit(u64, MiniArc<ValueEntry<K, V>>, Instant),
Miss(u64),
}

pub(crate) enum WriteOp<K, V> {
Upsert {
key_hash: KeyHash<K>,
value_entry: TrioArc<ValueEntry<K, V>>,
value_entry: MiniArc<ValueEntry<K, V>>,
old_weight: u32,
new_weight: u32,
},
Expand Down
Loading
Loading