tokio-rs / loom

Concurrency permutation testing tool for Rust.
MIT License
2.09k stars 110 forks source link

Make atomic_int!'s `new` function const #170

Open cmnord opened 4 years ago

cmnord commented 4 years ago

I'm trying to test a spinlock that uses parking_lot's lock_api with Loom.

To implement lock_api's RawRwLock I need to supply a const initial value, as specified on this line. This works with the standard library's std::sync::atomic::AtomicUsize const fn new, but not with Loom's atomic_int! macro which generates a non-const fn new.

I get the following error when running RUSTFLAGS="--cfg loom" cargo test, where rin is one of the fields of the struct I initialize. It does not throw an error with regular cargo test (using std::sync::atomic).

error[E0015]: calls in constants are limited to constant functions, tuple structs and tuple variants
  --> src/lib.rs:50:14
   |
50 |         rin: AtomicUsize::new(0),
   |              ^^^^^^^^^^^^^^^^^^^

Is it possible to make loom::sync::atomic::AtomicUsize::new const, or can you recommend another workaround?

LucioFranco commented 3 years ago

This won't work because location! from track_caller requires some more const fn things to be stabilized.

cmnord commented 3 years ago

I see, I guess my project will have to wait then. Can you recommend any workaround?

LucioFranco commented 3 years ago

Not really aware of a work around, except for feature flagging the const aspects but that may be hard.