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

Const generics port #198

Merged
merged 44 commits into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
e4580da
x86_64: "practically" thread-safe Pool
japaric Aug 20, 2018
596a1f0
fix warnings
japaric May 3, 2020
b9d7128
x86: put Sync impl behind a Cargo feature
japaric May 3, 2020
b0129f5
1.36.0 compatibility
japaric May 4, 2020
357a312
Preparing for v0.5.5
korken89 May 4, 2020
87917e0
Make Producer<..., SingleCore> Send, like Consumer
BryanKadzban Apr 12, 2020
1790c4f
indexmap: expose PowerOfTwo, Bucket and Pos
willem66745 Apr 22, 2020
0ab806d
readme: add instructions for tests
andresv May 9, 2020
26dcfa3
histbuf: replace slow modulo operatins
andresv May 9, 2020
9e08514
histbuf: fix style
andresv May 9, 2020
0364e05
Vec: add set_len
samlich Jul 24, 2020
6ba462e
String: add as_mut_vec
samlich Jul 24, 2020
f962e3a
Initial conversion to const generics
perlindgren Aug 20, 2020
6dcedb8
Fixes for min const generics
korken89 Mar 25, 2021
8ba71d4
Merge branch 'master' into const_generics
korken89 Mar 25, 2021
305de71
Fixed warnings
korken89 Mar 25, 2021
3de878b
Cleanup
korken89 Mar 25, 2021
f7cb3e5
Fix fmt
kpp Mar 28, 2021
a3f4d8f
Update minimal Rust version from 1.31 to 1.51
kpp Mar 28, 2021
92cc062
Fix cargo test without cargo features enabled
kpp Mar 28, 2021
7fb276f
Fix warnings in src/indexmap.rs
kpp Mar 28, 2021
5bde47c
Fix cfail tests
kpp Mar 28, 2021
aee0817
Merge pull request #199 from kpp/const_generics
korken89 Mar 30, 2021
1444990
Cleanup and HistoryBuffer is now const and using MaybeUninit
korken89 Apr 1, 2021
73d209a
Merge branch 'master' into const_generics
korken89 Apr 1, 2021
12682bd
Removed unnecessary String interface, already covered by `core`
korken89 Apr 1, 2021
870a925
Removed SingeCore and MultiCore, relies on atomics now
korken89 Apr 1, 2021
e0b3b3a
remove as_slice dependency
burrbull Apr 2, 2021
622eba9
Merge pull request #200 from burrbull/const_generics
korken89 Apr 2, 2021
618eebf
AsRef, AsMut for pool
burrbull Apr 2, 2021
fbf8c4d
Merge pull request #201 from burrbull/const_generics
korken89 Apr 3, 2021
a507b8e
Fix cfail tests in const generics
kpp Apr 3, 2021
5d294a7
Merge pull request #202 from kpp/fix_cfail
korken89 Apr 3, 2021
6bee0f8
Simplify code in histbuf
kpp Apr 3, 2021
e21c402
Merge pull request #203 from kpp/simplify_histbuf
korken89 Apr 4, 2021
2bfe3fe
Restore tests for SPSC as close as we can
korken89 Apr 4, 2021
1fac593
Added unsafe and docs to Queue::{u8(), u16()}
korken89 Apr 4, 2021
2c248a3
Fixed so pool and MPMC works on thumbv6
korken89 Apr 4, 2021
0ffef8f
Cleanup of comments
korken89 Apr 8, 2021
dfa5d50
Updated changelog
korken89 Apr 8, 2021
6fdcc4f
New SPSC queue, now safe and much simpler
korken89 Apr 18, 2021
58cb279
IndexMap::new() is now a const-fn
korken89 Apr 19, 2021
bf6728e
Clarification in changelog
korken89 Apr 20, 2021
8754c3d
Added missing `{enqueue, dequeue}_unchecked` interfaces
korken89 Apr 20, 2021
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
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ jobs:
toolchain:
- stable
- nightly
- 1.36.0
- 1.51.0
features:
- serde
buildtype:
Expand Down Expand Up @@ -242,7 +242,7 @@ jobs:
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: 1.36.0
toolchain: 1.51.0
target: x86_64-unknown-linux-gnu
override: true

Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Changed

- [breaking-change] Converted all data structures to use the `const generics` MVP
- [breaking-change] `HistoryBuffer` is now working with const constructors and non-`Copy` data
- [breaking-change] `HistoryBuffer::as_slice` and others now only return initialized values
- [breaking-change] `MultiCore`/`SingleCore` is now removed from `spsc::Queue`
- [breaking-change] `spsc::Queue` is now `usize` only
- [breaking-change] `spsc::Queue` now sacrifices one element for correctness (see issue #207), i.e. it creates an `N - 1` sized queue instead of the old that generated an size `N` queue
korken89 marked this conversation as resolved.
Show resolved Hide resolved
- `Pool` and `MPMC` now works on `thumbv6m`
- [breaking-change] `String` has had `utf8` related methods removed as this can be done via `str`
- [breaking-change] No data structures implement `AsSlice` traits any more, now using `AsRef` and `AsMut`
- `IndexMap::new()` is now a `const-fn`

## [v0.6.1] - 2021-03-02

### Fixed
Expand Down
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
authors = [
"Jorge Aparicio <jorge@japaric.io>",
"Per Lindgren <per.lindgren@ltu.se>",
"Emil Fresk <emil.fresk@gmail.com>",
]
categories = [
"data-structures",
Expand Down Expand Up @@ -31,10 +32,11 @@ __trybuild = []
[target.x86_64-unknown-linux-gnu.dev-dependencies]
scoped_threadpool = "0.1.8"

[target.thumbv6m-none-eabi.dependencies]
atomic-polyfill = "0.1.2"

[dependencies]
as-slice = "0.1.5"
generic-array = "0.14.4"
hash32 = "0.1.0"
hash32 = "0.2.1"

[dependencies.serde]
version = "1"
Expand Down
5 changes: 1 addition & 4 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ fn main() -> Result<(), Box<dyn Error>> {
// built-in targets with no atomic / CAS support as of nightly-2019-12-17
// see the `no-atomics.sh` / `no-cas.sh` script sitting next to this file
match &target[..] {
"thumbv6m-none-eabi"
| "msp430-none-elf"
| "riscv32i-unknown-none-elf"
| "riscv32imc-unknown-none-elf" => {}
"msp430-none-elf" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {}

_ => {
println!("cargo:rustc-cfg=has_cas");
Expand Down
4 changes: 2 additions & 2 deletions cfail/ui/freeze.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use heapless::{consts, spsc::Queue};
use heapless::spsc::Queue;

fn main() {
let mut q: Queue<u8, consts::U4> = Queue::new();
let mut q: Queue<u8, 4> = Queue::new();

let (_p, mut _c) = q.split();
q.enqueue(0).unwrap();
Expand Down
11 changes: 6 additions & 5 deletions cfail/ui/not-send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use core::marker::PhantomData;

use heapless::{
consts,
spsc::{Consumer, Producer, Queue},
HistoryBuffer, Vec,
};

type NotSend = PhantomData<*const ()>;
Expand All @@ -16,8 +16,9 @@ where
}

fn main() {
is_send::<Consumer<NotSend, consts::U4>>();
is_send::<Producer<NotSend, consts::U4>>();
is_send::<Queue<NotSend, consts::U4>>();
is_send::<heapless::Vec<NotSend, consts::U4>>();
is_send::<Consumer<NotSend, 4>>();
is_send::<Producer<NotSend, 4>>();
is_send::<Queue<NotSend, 4>>();
is_send::<Vec<NotSend, 4>>();
is_send::<HistoryBuffer<NotSend, 4>>();
}
132 changes: 69 additions & 63 deletions cfail/ui/not-send.stderr
Original file line number Diff line number Diff line change
@@ -1,83 +1,89 @@
error[E0277]: `*const ()` cannot be sent between threads safely
--> $DIR/not-send.rs:19:5
|
19 | is_send::<Consumer<NotSend, consts::U4>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
12 | fn is_send<T>()
| ------- required by a bound in this
13 | where
14 | T: Send,
| ---- required by this bound in `is_send`
...
19 | is_send::<Consumer<NotSend, 4>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
|
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
= note: required because of the requirements on the impl of `std::marker::Send` for `heapless::spsc::split::Consumer<'_, std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
note: required by `is_send`
--> $DIR/not-send.rs:12:1
|
12 | / fn is_send<T>()
13 | | where
14 | | T: Send,
15 | | {
16 | | }
| |_^
= help: within `PhantomData<*const ()>`, the trait `Send` is not implemented for `*const ()`
= note: required because it appears within the type `PhantomData<*const ()>`
= note: required because of the requirements on the impl of `Send` for `Consumer<'_, PhantomData<*const ()>, 4_usize>`

error[E0277]: `*const ()` cannot be sent between threads safely
--> $DIR/not-send.rs:20:5
|
20 | is_send::<Producer<NotSend, consts::U4>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
|
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
= note: required because of the requirements on the impl of `std::marker::Send` for `heapless::spsc::split::Producer<'_, std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
note: required by `is_send`
--> $DIR/not-send.rs:12:1
12 | fn is_send<T>()
| ------- required by a bound in this
13 | where
14 | T: Send,
| ---- required by this bound in `is_send`
...
20 | is_send::<Producer<NotSend, 4>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
|
12 | / fn is_send<T>()
13 | | where
14 | | T: Send,
15 | | {
16 | | }
| |_^
= help: within `PhantomData<*const ()>`, the trait `Send` is not implemented for `*const ()`
= note: required because it appears within the type `PhantomData<*const ()>`
= note: required because of the requirements on the impl of `Send` for `Producer<'_, PhantomData<*const ()>, 4_usize>`

error[E0277]: `*const ()` cannot be sent between threads safely
--> $DIR/not-send.rs:21:5
|
21 | is_send::<Queue<NotSend, consts::U4>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
|
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
= note: required because of the requirements on the impl of `std::marker::Send` for `generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
= note: required because it appears within the type `std::mem::ManuallyDrop<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
= note: required because it appears within the type `std::mem::MaybeUninit<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
= note: required because it appears within the type `heapless::i::Queue<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
= note: required because it appears within the type `heapless::spsc::Queue<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
note: required by `is_send`
--> $DIR/not-send.rs:12:1
12 | fn is_send<T>()
| ------- required by a bound in this
13 | where
14 | T: Send,
| ---- required by this bound in `is_send`
...
21 | is_send::<Queue<NotSend, 4>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
|
12 | / fn is_send<T>()
13 | | where
14 | | T: Send,
15 | | {
16 | | }
| |_^
= help: within `Queue<PhantomData<*const ()>, 4_usize>`, the trait `Send` is not implemented for `*const ()`
= note: required because it appears within the type `PhantomData<*const ()>`
= note: required because it appears within the type `ManuallyDrop<PhantomData<*const ()>>`
= note: required because it appears within the type `MaybeUninit<PhantomData<*const ()>>`
= note: required because it appears within the type `UnsafeCell<MaybeUninit<PhantomData<*const ()>>>`
= note: required because it appears within the type `[UnsafeCell<MaybeUninit<PhantomData<*const ()>>>; 4]`
= note: required because it appears within the type `Queue<PhantomData<*const ()>, 4_usize>`

error[E0277]: `*const ()` cannot be sent between threads safely
--> $DIR/not-send.rs:22:5
|
22 | is_send::<heapless::Vec<NotSend, consts::U4>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
12 | fn is_send<T>()
| ------- required by a bound in this
13 | where
14 | T: Send,
| ---- required by this bound in `is_send`
...
22 | is_send::<Vec<NotSend, 4>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
|
= help: within `heapless::Vec<PhantomData<*const ()>, 4_usize>`, the trait `Send` is not implemented for `*const ()`
= note: required because it appears within the type `PhantomData<*const ()>`
= note: required because it appears within the type `[PhantomData<*const ()>; 4]`
= note: required because it appears within the type `ManuallyDrop<[PhantomData<*const ()>; 4]>`
= note: required because it appears within the type `MaybeUninit<[PhantomData<*const ()>; 4]>`
= note: required because it appears within the type `heapless::Vec<PhantomData<*const ()>, 4_usize>`

error[E0277]: `*const ()` cannot be sent between threads safely
--> $DIR/not-send.rs:23:5
|
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
= note: required because of the requirements on the impl of `std::marker::Send` for `generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
= note: required because it appears within the type `std::mem::ManuallyDrop<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
= note: required because it appears within the type `std::mem::MaybeUninit<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
= note: required because it appears within the type `heapless::i::Vec<generic_array::GenericArray<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>>`
= note: required because it appears within the type `heapless::vec::Vec<std::marker::PhantomData<*const ()>, typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UInt<typenum::uint::UTerm, typenum::bit::B1>, typenum::bit::B0>, typenum::bit::B0>>`
note: required by `is_send`
--> $DIR/not-send.rs:12:1
12 | fn is_send<T>()
| ------- required by a bound in this
13 | where
14 | T: Send,
| ---- required by this bound in `is_send`
...
23 | is_send::<HistoryBuffer<NotSend, 4>>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
|
12 | / fn is_send<T>()
13 | | where
14 | | T: Send,
15 | | {
16 | | }
| |_^
= help: within `HistoryBuffer<PhantomData<*const ()>, 4_usize>`, the trait `Send` is not implemented for `*const ()`
= note: required because it appears within the type `PhantomData<*const ()>`
= note: required because it appears within the type `ManuallyDrop<PhantomData<*const ()>>`
= note: required because it appears within the type `MaybeUninit<PhantomData<*const ()>>`
= note: required because it appears within the type `[MaybeUninit<PhantomData<*const ()>>; 4]`
= note: required because it appears within the type `HistoryBuffer<PhantomData<*const ()>, 4_usize>`
Loading