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

Unable to use moka when miri testing #407

Open
Skye-31 opened this issue Mar 20, 2024 · 3 comments
Open

Unable to use moka when miri testing #407

Skye-31 opened this issue Mar 20, 2024 · 3 comments

Comments

@Skye-31
Copy link

Skye-31 commented Mar 20, 2024

Hi, I've recently been setting up a project with moka, thanks for all of your work on it!

As part of this, I've been looking at setting up miri testing, but it seems that it's impossible to use miri tests with any moka code at the moment. Using the example code at https://docs.rs/moka/latest/moka/future/struct.Cache.html#example-insert-get-and-invalidate, running cargo +nightly miri run --target x86_64-unknown-linux-gnu results in the following.

error: unsupported operation: inline assembly is not supported
  --> /Users/skye/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/x86/cpuid.rs:77:9
   |
77 | /         asm!(
78 | |             "mov {0:r}, rbx",
79 | |             "cpuid",
80 | |             "xchg {0:r}, rbx",
...  |
85 | |             options(nostack, preserves_flags),
86 | |         );
   | |_________^ inline assembly is not supported
   |
   = help: this is likely not a bug in the program; it indicates that the program performed an operation that the interpreter does not support
   = note: BACKTRACE:
   = note: inside `std::arch::x86_64::__cpuid_count` at /Users/skye/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/../../stdarch/crates/core_arch/src/x86/cpuid.rs:77:9: 86:10
   = note: inside `raw_cpuid::native_cpuid::cpuid_count` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raw-cpuid-11.0.1/src/lib.rs:88:31: 88:62
   = note: inside `<raw_cpuid::native_cpuid::CpuIdReaderNative as raw_cpuid::CpuIdReader>::cpuid2` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raw-cpuid-11.0.1/src/lib.rs:104:13: 104:34
   = note: inside `<raw_cpuid::native_cpuid::CpuIdReaderNative as raw_cpuid::CpuIdReader>::cpuid1` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raw-cpuid-11.0.1/src/lib.rs:182:9: 182:28
   = note: inside `raw_cpuid::CpuId::<raw_cpuid::native_cpuid::CpuIdReaderNative>::with_cpuid_reader` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raw-cpuid-11.0.1/src/lib.rs:339:27: 339:59
   = note: inside `raw_cpuid::CpuId::<raw_cpuid::native_cpuid::CpuIdReaderNative>::with_cpuid_fn` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raw-cpuid-11.0.1/src/lib.rs:355:9: 355:43
   = note: inside `<raw_cpuid::CpuId<raw_cpuid::native_cpuid::CpuIdReaderNative> as std::default::Default>::default` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raw-cpuid-11.0.1/src/lib.rs:241:9: 241:48
   = note: inside `raw_cpuid::CpuId::<raw_cpuid::native_cpuid::CpuIdReaderNative>::new` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/raw-cpuid-11.0.1/src/lib.rs:252:9: 252:25
   = note: inside `quanta::detection::has_counter_support` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/quanta-0.12.2/src/detection.rs:4:17: 4:40
   = note: inside `quanta::Clock::new` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/quanta-0.12.2/src/lib.rs:318:24: 318:56
   = note: inside `<fn() -> quanta::Clock {quanta::Clock::new} as std::ops::FnOnce<()>>::call_once - shim(fn() -> quanta::Clock {quanta::Clock::new})` at /Users/skye/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:250:5: 250:71
   = note: inside closure at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/lib.rs:1120:57: 1120:60
   = note: inside closure at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/imp_std.rs:72:23: 72:26
   = note: inside `std::ops::function::impls::<impl std::ops::FnMut<()> for &mut dyn std::ops::FnMut() -> bool>::call_mut` at /Users/skye/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:294:13: 294:35
   = note: inside `once_cell::imp::initialize_or_wait` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/imp_std.rs:196:20: 196:26
   = note: inside `once_cell::imp::OnceCell::<quanta::Clock>::initialize::<{closure@once_cell::sync::OnceCell<quanta::Clock>::get_or_init<fn() -> quanta::Clock {quanta::Clock::new}>::{closure#0}}, once_cell::sync::OnceCell<T>::get_or_init::Void>` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/imp_std.rs:68:9: 83:10
   = note: inside `once_cell::sync::OnceCell::<quanta::Clock>::get_or_try_init::<{closure@once_cell::sync::OnceCell<quanta::Clock>::get_or_init<fn() -> quanta::Clock {quanta::Clock::new}>::{closure#0}}, once_cell::sync::OnceCell<T>::get_or_init::Void>` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/lib.rs:1161:13: 1161:33
   = note: inside `once_cell::sync::OnceCell::<quanta::Clock>::get_or_init::<fn() -> quanta::Clock {quanta::Clock::new}>` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/once_cell-1.19.0/src/lib.rs:1120:19: 1120:62
   = note: inside `quanta::get_now` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/quanta-0.12.2/src/lib.rs:512:9: 512:45
   = note: inside `quanta::instant::Instant::now` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/quanta-0.12.2/src/instant.rs:42:9: 42:25
   = note: inside `moka::common::time::Instant::now` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/common/time.rs:33:17: 33:38
   = note: inside `moka::future::base_cache::Inner::<usize, std::string::String, std::hash::RandomState>::new` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/future/base_cache.rs:1223:19: 1223:33
   = note: inside `moka::future::base_cache::BaseCache::<usize, std::string::String>::new` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/future/base_cache.rs:185:30: 197:10
   = note: inside `moka::future::Cache::<usize, std::string::String>::with_everything` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/future/cache.rs:826:19: 836:14
   = note: inside `moka::future::Cache::<usize, std::string::String>::new` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/future/cache.rs:784:9: 794:10
note: inside closure
  --> src/main.rs:13:17
   |
13 |     let cache = Cache::new(10_000);
   |                 ^^^^^^^^^^^^^^^^^^
   = note: inside closure at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/park.rs:281:63: 281:87
   = note: inside `tokio::runtime::coop::with_budget::<std::task::Poll<()>, {closure@tokio::runtime::park::CachedParkThread::block_on<{async block@src/main.rs:3:1: 3:15}>::{closure#0}}>` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:107:5: 107:8
   = note: inside `tokio::runtime::coop::budget::<std::task::Poll<()>, {closure@tokio::runtime::park::CachedParkThread::block_on<{async block@src/main.rs:3:1: 3:15}>::{closure#0}}>` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/coop.rs:73:5: 73:38
   = note: inside `tokio::runtime::park::CachedParkThread::block_on::<{async block@src/main.rs:3:1: 3:15}>` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/park.rs:281:31: 281:88
   = note: inside `tokio::runtime::context::blocking::BlockingRegionGuard::block_on::<{async block@src/main.rs:3:1: 3:15}>` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/context/blocking.rs:66:9: 66:25
   = note: inside closure at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/scheduler/multi_thread/mod.rs:87:13: 87:38
   = note: inside `tokio::runtime::scheduler::multi_thread::MultiThread::block_on::<{async block@src/main.rs:3:1: 3:15}>` at /Users/skye/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tokio-1.36.0/src/runtime/scheduler/multi_thread/mod.rs:86:9: 88:11
note: inside `main`
  --> src/main.rs:44:5
   |
44 | /     for key in 0..(NUM_TASKS * NUM_KEYS_PER_TASK) {
45 | |         if key % 4 == 0 {
46 | |             assert_eq!(cache.get(&key).await, None);
47 | |         } else {
48 | |             assert_eq!(cache.get(&key).await, Some(value(key)));
49 | |         }
50 | |     }
   | |_____^

note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace

error: aborting due to 1 previous error

This seems to be coming from it's use of quanta, as something as simple as quanta::Clock::new(); reproduces the underlying error.

Additional info:

  • Host OS: aarch64-apple-darwin (macbook pro M3)
  • Cargo Version: cargo 1.79.0-nightly (2fe739fcf 2024-03-15)

Please let me know if there's any other information I can provide! 🙂

@tatsuya6502
Copy link
Member

Hi. Sorry for the late reply. I got COVID-19 for the first time in the middle of March. I was treated for pneumonia in the hospital but had a high fever for 10+ days. I am still recovering, and am slowly getting better.

moka depends on quanta and crossbeam-epoch crates, and they are not compatible with Miri.

  • quanta uses inline assembly on x86_64 and Arm platforms, but Miri does not support inline assembly.
  • Miri has some issues with crossbeam-epoch, and requires a couple of flags to run it.

Let me show you workarounds so that you can run Miri on your project that depends on moka.

quanta

As for quanta, I tried to disable the inline assembly code when testing with Miri:

It did not work as expected. While the above change allows cargo +nightly miri test to run directly on quanta, it still fails when running the same command on a project that depends on quanta. It seems #[cfg(all(..., not(miri)))] is not working for the latter case.

I will ask Miri developers for help. So for now, you need to disable the quanta feature of moka to run Miri tests on your project. Change your Cargo.toml as followings:

[dependencies]
# Disable the default features including quanta.
# Please choose sync and/or future as you need.
moka = { version = "0.12.5", default-features = false, features = ["sync", "future"] }

crossbeam-epoch

To run Miri tests on crossbeam-epoch, you need to add the following Miri flags:

$ MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tree-borrows" cargo +nightly miri test

Here are some explanations on the Stack Borrows and Tree Borrows:

https://github.com/rust-lang/miri/blob/master/README.md#miri

Example

I created a small example project to demonstrate how to run Miri tests with the above workarounds:

Cargo.toml

[dependencies]
moka = { version = "0.12.5", default-features = false, features = ["sync"] }

src/main.rs

fn main() {
    println!("Hello, world!");
}

#[cfg(test)]
mod tests {
    #[test]
    fn test_crud() {
        let key = "key1".to_string();

        let cache = moka::sync::Cache::new(10);
        cache.insert(key.clone(), "value1".to_string());
        assert_eq!(cache.get(&key), Some("value1".to_string()));
        cache.invalidate(&key);
        assert!(!cache.contains_key(&key));
    }
}

Run the Miri test:

$ MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tree-borrows" cargo +nightly miri test

It emitted some warnings on crossbeam-epoch but the test itself passed:

ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
$ MIRIFLAGS="-Zmiri-ignore-leaks -Zmiri-tree-borrows" cargo +nightly miri test
Preparing a sysroot for Miri (target: aarch64-apple-darwin)... done
WARNING: Ignoring `RUSTC_WRAPPER` environment variable, Miri does not support wrapping.
    Finished `test` profile [unoptimized + debuginfo] target(s) in 0.06s
     Running unittests src/main.rs (target/miri/aarch64-apple-darwin/debug/deps/repro-6d94b64cac11a07b)

running 1 test
test tests::test_crud ... warning: integer-to-pointer cast
   --> /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/atomic.rs:204:11
    |
204 |         &*(ptr as *const T)
    |           ^^^^^^^^^^^^^^^^^ integer-to-pointer cast
    |
    = help: This program is using integer-to-pointer casts or (equivalently) `ptr::from_exposed_addr`,
    = help: which means that Miri might miss pointer bugs in this program.
    = help: See https://doc.rust-lang.org/nightly/std/ptr/fn.from_exposed_addr.html for more details on that operation.
    = help: To ensure that Miri does not miss bugs in your program, use Strict Provenance APIs (https://doc.rust-lang.org/nightly/std/ptr/index.html#strict-provenance, https://crates.io/crates/sptr) instead.
    = help: You can then pass the `-Zmiri-strict-provenance` flag to Miri, to ensure you are not relying on `from_exposed_addr` semantics.
    = help: Alternatively, the `-Zmiri-permissive-provenance` flag disables this warning.
    = note: BACKTRACE on thread `tests::test_crud`:
    = note: inside `<crossbeam_epoch::internal::Local as crossbeam_epoch::atomic::Pointable>::deref::<'_>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/atomic.rs:204:11: 204:28
    = note: inside `crossbeam_epoch::atomic::Shared::<'_, crossbeam_epoch::internal::Local>::deref` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/atomic.rs:1421:9: 1421:22
    = note: inside `crossbeam_epoch::sync::list::List::<crossbeam_epoch::internal::Local>::insert` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/sync/list.rs:176:41: 176:58
    = note: inside `crossbeam_epoch::internal::Local::register` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/internal.rs:330:13: 330:65
    = note: inside `crossbeam_epoch::collector::Collector::register` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/collector.rs:45:9: 45:30
    = note: inside `crossbeam_epoch::default::HANDLE::__init` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/default.rs:34:34: 34:56
    = note: inside closure at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/thread_local/fast_local.rs:102:25: 102:33
    = note: inside `std::sys::thread_local::lazy::LazyKeyInner::<crossbeam_epoch::collector::LocalHandle>::initialize::<{closure@crossbeam_epoch::default::HANDLE::__getit::{closure#0}}>` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/thread_local/mod.rs:54:25: 54:31
    = note: inside `std::thread::local_impl::Key::<crossbeam_epoch::collector::LocalHandle>::try_initialize::<{closure@crossbeam_epoch::default::HANDLE::__getit::{closure#0}}>` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/thread_local/fast_local.rs:193:27: 193:54
    = note: inside `std::thread::local_impl::Key::<crossbeam_epoch::collector::LocalHandle>::get::<{closure@crossbeam_epoch::default::HANDLE::__getit::{closure#0}}>` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/thread_local/fast_local.rs:176:25: 176:50
    = note: inside `crossbeam_epoch::default::HANDLE::__getit` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/thread_local/fast_local.rs:93:21: 103:23
    = note: inside `std::thread::LocalKey::<crossbeam_epoch::collector::LocalHandle>::try_with::<{closure@crossbeam_epoch::default::with_handle<{closure@crossbeam_epoch::default::pin::{closure#0}}, crossbeam_epoch::guard::Guard>::{closure#0}}, crossbeam_epoch::guard::Guard>` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:283:32: 283:50
    = note: inside `crossbeam_epoch::default::with_handle::<{closure@crossbeam_epoch::default::pin::{closure#0}}, crossbeam_epoch::guard::Guard>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/default.rs:59:5: 60:28
    = note: inside `crossbeam_epoch::default::pin` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/default.rs:40:5: 40:39
    = note: inside `moka::cht::map::bucket_array_ref::BucketArrayRef::<'_, std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>, std::hash::RandomState>::insert_with_or_modify_entry_and::<triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#1}}, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#2}}, {closure@moka::cht::segment::HashMap<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::insert_with_or_modify<{closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#1}}, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#2}}>::{closure#0}}>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/cht/map/bucket_array_ref.rs:206:22: 206:44
    = note: inside `moka::cht::segment::HashMap::<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::insert_with_or_modify_entry_and::<triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#1}}, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#2}}, {closure@moka::cht::segment::HashMap<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::insert_with_or_modify<{closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#1}}, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#2}}>::{closure#0}}>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/cht/segment.rs:439:22: 445:10
    = note: inside `moka::cht::segment::HashMap::<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::insert_with_or_modify::<{closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#1}}, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#2}}>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/cht/segment.rs:415:9: 415:96
    = note: inside `moka::sync_base::base_cache::BaseCache::<std::string::String, std::string::String>::do_insert_with_hash` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/sync_base/base_cache.rs:511:9: 536:10
    = note: inside `moka::sync::Cache::<std::string::String, std::string::String>::insert_with_hash` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/sync/cache.rs:1497:25: 1497:72
    = note: inside `moka::sync::Cache::<std::string::String, std::string::String>::insert` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/sync/cache.rs:1489:9: 1489:48
note: inside `tests::test_crud`
   --> src/main.rs:12:9
    |
12  |         cache.insert(key.clone(), "value1".to_string());
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
   --> src/main.rs:8:19
    |
7   |     #[test]
    |     ------- in this procedural macro expansion
8   |     fn test_crud() {
    |                   ^
    = note: this warning originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: integer-to-pointer cast
    --> /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/atomic.rs:1345:9
     |
1345 |         raw as *const _
     |         ^^^^^^^^^^^^^^^ integer-to-pointer cast
     |
     = note: BACKTRACE on thread `tests::test_crud`:
     = note: inside `crossbeam_epoch::atomic::Shared::<'_, crossbeam_epoch::internal::Local>::as_raw` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/atomic.rs:1345:9: 1345:24
     = note: inside `crossbeam_epoch::internal::Local::register` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/internal.rs:332:24: 332:38
     = note: inside `crossbeam_epoch::collector::Collector::register` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/collector.rs:45:9: 45:30
     = note: inside `crossbeam_epoch::default::HANDLE::__init` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/default.rs:34:34: 34:56
     = note: inside closure at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/thread_local/fast_local.rs:102:25: 102:33
     = note: inside `std::sys::thread_local::lazy::LazyKeyInner::<crossbeam_epoch::collector::LocalHandle>::initialize::<{closure@crossbeam_epoch::default::HANDLE::__getit::{closure#0}}>` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/thread_local/mod.rs:54:25: 54:31
     = note: inside `std::thread::local_impl::Key::<crossbeam_epoch::collector::LocalHandle>::try_initialize::<{closure@crossbeam_epoch::default::HANDLE::__getit::{closure#0}}>` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/thread_local/fast_local.rs:193:27: 193:54
     = note: inside `std::thread::local_impl::Key::<crossbeam_epoch::collector::LocalHandle>::get::<{closure@crossbeam_epoch::default::HANDLE::__getit::{closure#0}}>` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/thread_local/fast_local.rs:176:25: 176:50
     = note: inside `crossbeam_epoch::default::HANDLE::__getit` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/sys/thread_local/fast_local.rs:93:21: 103:23
     = note: inside `std::thread::LocalKey::<crossbeam_epoch::collector::LocalHandle>::try_with::<{closure@crossbeam_epoch::default::with_handle<{closure@crossbeam_epoch::default::pin::{closure#0}}, crossbeam_epoch::guard::Guard>::{closure#0}}, crossbeam_epoch::guard::Guard>` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:283:32: 283:50
     = note: inside `crossbeam_epoch::default::with_handle::<{closure@crossbeam_epoch::default::pin::{closure#0}}, crossbeam_epoch::guard::Guard>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/default.rs:59:5: 60:28
     = note: inside `crossbeam_epoch::default::pin` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/default.rs:40:5: 40:39
     = note: inside `moka::cht::map::bucket_array_ref::BucketArrayRef::<'_, std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>, std::hash::RandomState>::insert_with_or_modify_entry_and::<triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#1}}, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#2}}, {closure@moka::cht::segment::HashMap<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::insert_with_or_modify<{closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#1}}, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#2}}>::{closure#0}}>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/cht/map/bucket_array_ref.rs:206:22: 206:44
     = note: inside `moka::cht::segment::HashMap::<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::insert_with_or_modify_entry_and::<triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#1}}, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#2}}, {closure@moka::cht::segment::HashMap<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::insert_with_or_modify<{closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#1}}, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#2}}>::{closure#0}}>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/cht/segment.rs:439:22: 445:10
     = note: inside `moka::cht::segment::HashMap::<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::insert_with_or_modify::<{closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#1}}, {closure@moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>::do_insert_with_hash::{closure#2}}>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/cht/segment.rs:415:9: 415:96
     = note: inside `moka::sync_base::base_cache::BaseCache::<std::string::String, std::string::String>::do_insert_with_hash` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/sync_base/base_cache.rs:511:9: 536:10
     = note: inside `moka::sync::Cache::<std::string::String, std::string::String>::insert_with_hash` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/sync/cache.rs:1497:25: 1497:72
     = note: inside `moka::sync::Cache::<std::string::String, std::string::String>::insert` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/sync/cache.rs:1489:9: 1489:48
note: inside `tests::test_crud`
    --> src/main.rs:12:9
     |
12   |         cache.insert(key.clone(), "value1".to_string());
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
    --> src/main.rs:8:19
     |
7    |     #[test]
     |     ------- in this procedural macro expansion
8    |     fn test_crud() {
     |                   ^
     = note: this warning originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: integer-to-pointer cast
   --> /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/atomic.rs:208:15
    |
208 |         &mut *(ptr as *mut T)
    |               ^^^^^^^^^^^^^^^ integer-to-pointer cast
    |
    = note: BACKTRACE on thread `tests::test_crud`:
    = note: inside `<moka::cht::map::bucket::Bucket<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>> as crossbeam_epoch::atomic::Pointable>::deref_mut::<'_>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/atomic.rs:208:15: 208:30
    = note: inside `crossbeam_epoch::atomic::Shared::<'_, moka::cht::map::bucket::Bucket<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>>::deref_mut` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/atomic.rs:1463:9: 1463:26
    = note: inside `moka::cht::map::bucket::defer_destroy_tombstone::<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/cht/map/bucket.rs:701:27: 701:42
    = note: inside `moka::cht::map::bucket_array_ref::BucketArrayRef::<'_, std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>, std::hash::RandomState>::remove_entry_if_and::<(std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>), {closure@moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>::remove_entry<std::string::String>::{closure#0}}, {closure@moka::cht::segment::HashMap<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::remove_entry<{closure@moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>::remove_entry<std::string::String>::{closure#0}}>::{closure#0}}, {closure@moka::cht::segment::HashMap<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::remove_entry_if_and<(std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>), {closure@moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>::remove_entry<std::string::String>::{closure#0}}, {closure@moka::cht::segment::HashMap<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::remove_entry<{closure@moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>::remove_entry<std::string::String>::{closure#0}}>::{closure#0}}, {closure@moka::cht::segment::HashMap<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::remove_entry<{closure@moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>::remove_entry<std::string::String>::{closure#0}}>::{closure#1}}>::{closure#0}}>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/cht/map/bucket_array_ref.rs:105:34: 105:93
    = note: inside `moka::cht::segment::HashMap::<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::remove_entry_if_and::<(std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>), {closure@moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>::remove_entry<std::string::String>::{closure#0}}, {closure@moka::cht::segment::HashMap<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::remove_entry<{closure@moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>::remove_entry<std::string::String>::{closure#0}}>::{closure#0}}, {closure@moka::cht::segment::HashMap<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::remove_entry<{closure@moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>::remove_entry<std::string::String>::{closure#0}}>::{closure#1}}>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/cht/segment.rs:385:9: 390:15
    = note: inside `moka::cht::segment::HashMap::<std::sync::Arc<std::string::String>, triomphe::arc::Arc<moka::common::concurrent::ValueEntry<std::string::String, std::string::String>>>::remove_entry::<{closure@moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>::remove_entry<std::string::String>::{closure#0}}>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/cht/segment.rs:345:9: 345:87
    = note: inside `moka::sync_base::base_cache::Inner::<std::string::String, std::string::String, std::hash::RandomState>::remove_entry::<std::string::String>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/sync_base/base_cache.rs:1151:9: 1152:63
    = note: inside `moka::sync_base::base_cache::BaseCache::<std::string::String, std::string::String>::remove_entry::<std::string::String>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/sync_base/base_cache.rs:384:9: 384:43
    = note: inside `moka::sync::Cache::<std::string::String, std::string::String>::invalidate_with_hash::<std::string::String>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/sync/cache.rs:1614:15: 1614:48
    = note: inside `moka::sync::Cache::<std::string::String, std::string::String>::invalidate::<std::string::String>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/sync/cache.rs:1570:9: 1570:52
note: inside `tests::test_crud`
   --> src/main.rs:14:9
    |
14  |         cache.invalidate(&key);
    |         ^^^^^^^^^^^^^^^^^^^^^^
note: inside closure
   --> src/main.rs:8:19
    |
7   |     #[test]
    |     ------- in this procedural macro expansion
8   |     fn test_crud() {
    |                   ^
    = note: this warning originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: integer-to-pointer cast
   --> /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/atomic.rs:212:28
    |
212 |         drop(Box::from_raw(ptr as *mut T));
    |                            ^^^^^^^^^^^^^ integer-to-pointer cast
    |
    = note: BACKTRACE on thread `tests::test_crud`:
    = note: inside `<crossbeam_epoch::sync::queue::Node<crossbeam_epoch::internal::SealedBag> as crossbeam_epoch::atomic::Pointable>::drop` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/atomic.rs:212:28: 212:41
    = note: inside `<crossbeam_epoch::atomic::Owned<crossbeam_epoch::sync::queue::Node<crossbeam_epoch::internal::SealedBag>> as std::ops::Drop>::drop` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/atomic.rs:1204:13: 1204:25
    = note: inside `std::ptr::drop_in_place::<crossbeam_epoch::atomic::Owned<crossbeam_epoch::sync::queue::Node<crossbeam_epoch::internal::SealedBag>>> - shim(Some(crossbeam_epoch::atomic::Owned<crossbeam_epoch::sync::queue::Node<crossbeam_epoch::internal::SealedBag>>))` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:514:1: 514:56
    = note: inside `std::mem::drop::<crossbeam_epoch::atomic::Owned<crossbeam_epoch::sync::queue::Node<crossbeam_epoch::internal::SealedBag>>>` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/mem/mod.rs:938:24: 938:25
    = note: inside closure at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/guard.rs:193:47: 193:56
    = note: inside `crossbeam_epoch::deferred::Deferred::new::call::<{closure@crossbeam_epoch::guard::Guard::defer_unchecked<{closure@crossbeam_epoch::guard::Guard::defer_destroy<crossbeam_epoch::sync::queue::Node<crossbeam_epoch::internal::SealedBag>>::{closure#0}}, crossbeam_epoch::atomic::Owned<crossbeam_epoch::sync::queue::Node<crossbeam_epoch::internal::SealedBag>>>::{closure#0}}>` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/deferred.rs:53:21: 53:24
    = note: inside `crossbeam_epoch::deferred::Deferred::call` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/deferred.rs:86:18: 86:59
    = note: inside `<crossbeam_epoch::internal::Bag as std::ops::Drop>::drop` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/internal.rs:122:13: 122:34
    = note: inside `std::ptr::drop_in_place::<crossbeam_epoch::internal::Bag> - shim(Some(crossbeam_epoch::internal::Bag))` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:514:1: 514:56
    = note: inside `std::ptr::drop_in_place::<crossbeam_epoch::internal::SealedBag> - shim(Some(crossbeam_epoch::internal::SealedBag))` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:514:1: 514:56
    = note: inside `std::mem::drop::<crossbeam_epoch::internal::SealedBag>` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/mem/mod.rs:938:24: 938:25
    = note: inside `crossbeam_epoch::internal::Global::collect` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/internal.rs:214:37: 214:53
    = note: inside `crossbeam_epoch::internal::Local::flush` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/internal.rs:376:9: 376:37
    = note: inside `crossbeam_epoch::guard::Guard::flush` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/crossbeam-epoch-0.9.18/src/guard.rs:294:13: 294:30
    = note: inside `<moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState> as std::ops::Drop>::drop` at /Users/tatsuya/.cargo/registry/src/index.crates.io-6f17d22bba15001f/moka-0.12.5/src/sync_base/base_cache.rs:921:13: 921:43
    = note: inside `std::ptr::drop_in_place::<moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>> - shim(Some(moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>))` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:514:1: 514:56
    = note: inside `std::sync::Arc::<moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>>::drop_slow` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/sync.rs:1804:18: 1804:67
    = note: inside `<std::sync::Arc<moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>> as std::ops::Drop>::drop` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/sync.rs:2462:13: 2462:29
    = note: inside `std::ptr::drop_in_place::<std::sync::Arc<moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>>> - shim(Some(std::sync::Arc<moka::sync_base::base_cache::Inner<std::string::String, std::string::String, std::hash::RandomState>>))` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:514:1: 514:56
    = note: inside `std::ptr::drop_in_place::<moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>> - shim(Some(moka::sync_base::base_cache::BaseCache<std::string::String, std::string::String>))` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:514:1: 514:56
    = note: inside `std::ptr::drop_in_place::<moka::sync::Cache<std::string::String, std::string::String>> - shim(Some(moka::sync::Cache<std::string::String, std::string::String>))` at /Users/tatsuya/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/library/core/src/ptr/mod.rs:514:1: 514:56
note: inside `tests::test_crud`
   --> src/main.rs:16:5
    |
16  |     }
    |     ^
note: inside closure
   --> src/main.rs:8:19
    |
7   |     #[test]
    |     ------- in this procedural macro expansion
8   |     fn test_crud() {
    |                   ^
    = note: this warning originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)

ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out

@Skye-31
Copy link
Author

Skye-31 commented Apr 8, 2024

Hey, don't worry at all! I hope you're recovering well.

Thank you for investigating this, it looks like we might be able to run these tests after all! What are the implications of disabling the quanta flag, will it affect performance in any way?

@tatsuya6502
Copy link
Member

tatsuya6502 commented Apr 10, 2024

What are the implications of disabling the quanta flag, will it affect performance in any way?

There are two downsides of disabling the quanta feature:

  1. Per-cached-entry memory overhead increases.
  2. Cache read and write performance can slightly decrease.
    • This will be only noticeable in high-throughput scenarios.

As for 1, moka@v0.12.x stores three instances of internal AtomicInstant type for a cached entry to track the following information of the entry:

  1. The last modified time
  2. The last access time
  3. The expiration time

https://github.com/moka-rs/moka/blob/v0.12.5/src/common/concurrent/entry_info.rs#L20-L22

The last modified time is used by invalidate_all and invalidate_entries_if methods, and all three are used by expirations such as time-to-live. (To reduce the overhead, a future version of moka could store the last accessed and expiration times only when cache has expiration enabled. But as of v0.12.x, it always stores all three times for all entries)

The size of AtomicInstant is 8 bytes when the quanta feature is enabled, and it will be bigger than that when disabled. This is because AtomicInstant is just a std::sync::atomic::AtomicU64 when the quanta feature is enabled, and it is a parking_lot::RwLock<std::time::Instant> when disabled.

The size of parking_lot::RwLock<std::time::Instant> varies by platform. It is 24 bytes on Linux x86_64, for example.

Here is how I got the numbers:

Modified src/sync/cache.rs of moka as follows:

diff --git a/src/sync/cache.rs b/src/sync/cache.rs
index fc5e5b4..c1cc5f7 100644
--- a/src/sync/cache.rs
+++ b/src/sync/cache.rs
@@ -686,6 +686,12 @@ impl<K, V, S> Cache<K, V, S> {
     pub fn weighted_size(&self) -> u64 {
         self.base.weighted_size()
     }
+
+    /// Returns the size of the `AtomicInstant` in bytes.
+    pub fn size_of_atomic_instant() -> usize {
+        use crate::common::concurrent::atomic_time::AtomicInstant;
+        std::mem::size_of::<AtomicInstant>()
+    }
 }

 impl<K, V> Cache<K, V, RandomState>

Added examples/show_size_of_atomic_instant.rs:

fn main() {
    let byte_size = moka::sync::Cache::<(), ()>::size_of_atomic_instant();
    println!("Size of AtomicInstant: {} bytes", byte_size);
}

Ran it with and without the quanta feature:

## With the `quanta` feature.
$ cargo run -F sync --example show_size_of_atomic_instant
Size of AtomicInstant: 8 bytes

## Without the `quanta` feature.
$ cargo run --no-default-features -F sync --example show_size_of_atomic_instant
Size of AtomicInstant: 24 bytes

As for 2, getting the current instant (monotonically increasing time) using quanta is expected to be faster than using std::time::Instant. This is because quanta uses inline assembly to read CPU core's timestamp counter (TSC) when available. This is a very fast operation, and it will be generally faster than reading the system's instant using the system library.

However, the performance difference will be negligible in most cases. So this will be only noticeable in high-throughput scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants