-
Notifications
You must be signed in to change notification settings - Fork 31
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
no_std support, more minimal and less intrusive version #93
Conversation
Reading through the changes, I must say I kind of like them. The overall feeling is it is kind of elegant and nice. I do have few details to discuss, though:
As for the old build… I think you can still build the crate if you delete the lock file. The lock file is not used when the crate is just a dependency. |
The The
I pushed a commit that renames the feature flag
I pushed a commit that replaces all occurences of
Yes, I didn't think of it. I'll do this last, when the other questions are resolved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :-)
Few more things, though…
I pushed a commit that replaces all occurences of --all-features in the CI scripts with an explcit list of features without experimental-thread-support.
I think we also should have (at least one) test where it does compile with this one.
As for the rw_lock. It should be enabled only under the internal-test-strategies
feature flag (if it is compiled without that feature, then it's a bug… but I believe it's at least not exported in that case), which is not shown anywhere in the documentation and it very clearly says not to be used from outside in the Cargo.toml, that there are no stability guarantees for that one. I'd say we don't need another feature flag for that one, but maybe having an explicit error message if both feature flags are enabled at once might be nice.
b77d6ba
to
cefbdaf
Compare
I think I fixed pretty much everything and added some documentation. Concerning the rw-lock thing, could you check that I did what you were expecting? Especially the conditional compilation in Thanks :) |
Sorry for the delay on my end; this looks good. But the CI tests are currently failing due to some problem in proc-macro2 vs. newest nightly compiler. It is already resolved on master, so a rebase might help. Also, when I do |
- Adds a new feature `no-std` that enables building for no_std targets. If this feature is not enabled, the crate is identical as before, still allowing for compilation using Rust stable >= 1.38.0. - The `no-std` feature makes use of experimental features `thread_local` and `lazy_cell`, thus requiring a nightly Rust compiler. - Support for `std::sync::RwLock` is dropped in no_std builds.
cefbdaf
to
d544787
Compare
I fixed compilation of the tests when running
Looking at a stack trace, it looks like there is a recursive function that calls |
Alright, I fixed the tests by using |
OK. Before I go ahead and merge it, do you want to do some cleanup of the history? Because there's a lot of „changes due to review“ commits (which are kind of annoying in future browsing of the history, bisects, etc) instead some kind of per-topic commits. I can either squash it as a whole to a single commit, or you can sort it into something „nice“. |
If you don't want to keep the current history, I think it's fine to just squash everything in a single commit. |
Thank you, I've done a release. |
This PR proposes a non-invasive, relatively minimal implementation of
no_std
support for thearc-swap
crate. The aim of this PR is to enableno_std
without much effort for specific use-cases such as embedded or os dev, which are often already using a nightly compiler anyways, without disturbing the existing functionning of the crate. I saw the previous PR for no_std support (#56) which was not merged due to lack of activity. If possible I'd like to do the necessary work so that we can have no_std support in arc-swap soon.This PR is minimally invaisve: if the
no-std
feature is not enabled then the build is pretty much exactly the same. The crate could successfully be compiled with Rust as low asv1.38.0
(same as before, see below).Compiling with the
no-std
feature requires a nightly Rust compiler, due to the use of unstable featuresthread_local
andlazy_cell
. No additionnal dependencies are added. Suppor forRwLock
is dropped inno_std
mode.This PR does not require additionnal OS dependencies and does not introducing more locking or synchronization points (it doesn't use the
static_init
crate as in no_std #56). Due to lesser requirements, it is probably usefull on more platforms than no_std #56, as long as support for compiler-generated thread local variables is available. FWIW, thetls-mode=emulated
makes it quite easy to add support for these thread-local variables on a variety of platforms even without OS/kernel support, without having to delve into the intricacies of linkers and symbol relocation (example in C from the Clang source code).To answer questions from the other thread (PR #56):
In this PR, we are using only the experimental
#[thread_local]
tag of the nightly compiler. This compiles down to LLVM thread local primitives, which are supposedly one of the fastest possible underlying implementation for std'sthread_local!
macro, so no performance penalty on that side is to be expected. Custom implementations can also be made easily without locks. The thread local variable itself that is used byarc-swap
is aLazyCell
which is notSync
, so there is no mutex or synchronizaton penalty on initialization.This is the case with this PR, albeit the lowest supported version is 1.38.0, which is not related to changes in this PR. Versions <=1.37.0 failed with the following error, which was already the case on the master branch:
Not an issue in this PR.
Unfortunately, this is not doable easily in the current state of the Rust ecosystem, at least not with a lot of additional effort. This PR is a minimal try to land
no_std
support in thearc-swap
crate as simply as possible, so it naturally comes with some restriction. I tried to have as little restrictions as possible, and basically there are only two conditions for this to be used: use a nightly compiler, and have support for compiler-generated thread local variables.I'd be glad to have your comments and advice on how we can make this into something that can be merged into
arc-swap
.