Closed KamilaBorowska closed 3 years ago
cargo feature needs to be additive. see also https://github.com/crossbeam-rs/crossbeam/pull/638
This is additive I believe unless I'm missing something? A model
feature would add loom::model
function to an API, and that's it. It also would modify a lot of things to interact with model
, but the user-visible API wouldn't change, and enabling model
wouldn't make changes in other functions visible when not using model
function (other than making them slower).
Oh, I see, Loom functions expect loom::model
to be used first? Yeah, that is an issue. I wonder if it's possible to make them behave like normal functions when not in loom::model
scope.
This is additive I believe unless I'm missing something? A
model
feature would addloom::model
function to an API, and that's it. It also would modify a lot of things to interact withmodel
, but the user-visible API wouldn't change, and enablingmodel
wouldn't make changes in other functions visible when not usingmodel
function (other than making them slower).
Some of the features do not work outside of the loom::model function.
For example, removing this function's loom::model will cause a panic with "cannot access a scoped thread local variable without calling set
first".
A feature that can break most of the existing tests with panic should not be called "additive", even if it does not seem to break the API.
cargo vendor
vendors dependencies of loom.- Dependencies of
loom
are included in Cargo.lock when using a crate that depends on loom.cargo audit
includes dependencies of loom when using a crate that depends on loom.
The workaround for these problems is to make loom an optional dependency: https://github.com/crossbeam-rs/crossbeam/pull/666
Currently Loom recommends using target specific dependencies.
This works, however it has certain drawbacks:
RUSTFLAGS="--cfg loom"
requires rebuilding every dependency.cargo vendor
vendors dependencies of loom.loom
are included in Cargo.lock when using a crate that depends on loom.cargo audit
includes dependencies of loom when using a crate that depends on loom.RUSTFLAGS="--cfg loom"
to test crate with loom.Requiring an user to import loom or std types depending on whether loom is enabled.
All those issues would be solvable if
loom
did use a feature rather than a config flag. To clarify what I mean: the user could useloom
like this inCargo.toml
.Then import whatever they want by simply using
use
, without having to bother with#[cfg]
orcfg_if!
.That would work because Loom crate would provide a basic
AtomicUsize
implementation that directly uses methods fromstd
whenmodel
feature is not enabled. This means no performance cost when not usingmodel
feature.Some possible concerns:
#[cfg(test)]
themselves to mockloom
APIs, just like they have to right now.loom
in tests due to Cargo merging all features used within a crate? No, assuming new feature resolver is being used (Rust 1.51+, needs to be opted-in withresolver = "2"
oredition = "2021"
). That said, a note in documentation should be added recommending using new feature resolver for programs that use loom for testing themselves (it's not necessary for libraries or programs that happen to use libraries that use loom).