Skip to content

Commit bd32ab8

Browse files
authoredApr 22, 2021
Merge pull request #198 from japaric/const_generics
Const generics port
2 parents 8c2fd3b + 8754c3d commit bd32ab8

29 files changed

+2062
-1824
lines changed
 

‎.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ jobs:
105105
toolchain:
106106
- stable
107107
- nightly
108-
- 1.36.0
108+
- 1.51.0
109109
features:
110110
- serde
111111
buildtype:
@@ -242,7 +242,7 @@ jobs:
242242
- name: Install Rust
243243
uses: actions-rs/toolchain@v1
244244
with:
245-
toolchain: 1.36.0
245+
toolchain: 1.51.0
246246
target: x86_64-unknown-linux-gnu
247247
override: true
248248

‎CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Changed
11+
12+
- [breaking-change] Converted all data structures to use the `const generics` MVP
13+
- [breaking-change] `HistoryBuffer` is now working with const constructors and non-`Copy` data
14+
- [breaking-change] `HistoryBuffer::as_slice` and others now only return initialized values
15+
- [breaking-change] `MultiCore`/`SingleCore` is now removed from `spsc::Queue`
16+
- [breaking-change] `spsc::Queue` is now `usize` only
17+
- [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
18+
- `Pool` and `MPMC` now works on `thumbv6m`
19+
- [breaking-change] `String` has had `utf8` related methods removed as this can be done via `str`
20+
- [breaking-change] No data structures implement `AsSlice` traits any more, now using `AsRef` and `AsMut`
21+
- `IndexMap::new()` is now a `const-fn`
22+
1023
## [v0.6.1] - 2021-03-02
1124

1225
### Fixed

‎Cargo.toml

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
authors = [
33
"Jorge Aparicio <jorge@japaric.io>",
44
"Per Lindgren <per.lindgren@ltu.se>",
5+
"Emil Fresk <emil.fresk@gmail.com>",
56
]
67
categories = [
78
"data-structures",
@@ -31,10 +32,11 @@ __trybuild = []
3132
[target.x86_64-unknown-linux-gnu.dev-dependencies]
3233
scoped_threadpool = "0.1.8"
3334

35+
[target.thumbv6m-none-eabi.dependencies]
36+
atomic-polyfill = "0.1.2"
37+
3438
[dependencies]
35-
as-slice = "0.1.5"
36-
generic-array = "0.14.4"
37-
hash32 = "0.1.0"
39+
hash32 = "0.2.1"
3840

3941
[dependencies.serde]
4042
version = "1"

‎build.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ fn main() -> Result<(), Box<dyn Error>> {
2424
// built-in targets with no atomic / CAS support as of nightly-2019-12-17
2525
// see the `no-atomics.sh` / `no-cas.sh` script sitting next to this file
2626
match &target[..] {
27-
"thumbv6m-none-eabi"
28-
| "msp430-none-elf"
29-
| "riscv32i-unknown-none-elf"
30-
| "riscv32imc-unknown-none-elf" => {}
27+
"msp430-none-elf" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {}
3128

3229
_ => {
3330
println!("cargo:rustc-cfg=has_cas");

‎cfail/ui/freeze.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use heapless::{consts, spsc::Queue};
1+
use heapless::spsc::Queue;
22

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

66
let (_p, mut _c) = q.split();
77
q.enqueue(0).unwrap();

‎cfail/ui/not-send.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
use core::marker::PhantomData;
44

55
use heapless::{
6-
consts,
76
spsc::{Consumer, Producer, Queue},
7+
HistoryBuffer, Vec,
88
};
99

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

1818
fn main() {
19-
is_send::<Consumer<NotSend, consts::U4>>();
20-
is_send::<Producer<NotSend, consts::U4>>();
21-
is_send::<Queue<NotSend, consts::U4>>();
22-
is_send::<heapless::Vec<NotSend, consts::U4>>();
19+
is_send::<Consumer<NotSend, 4>>();
20+
is_send::<Producer<NotSend, 4>>();
21+
is_send::<Queue<NotSend, 4>>();
22+
is_send::<Vec<NotSend, 4>>();
23+
is_send::<HistoryBuffer<NotSend, 4>>();
2324
}

‎cfail/ui/not-send.stderr

+69-63
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,89 @@
11
error[E0277]: `*const ()` cannot be sent between threads safely
22
--> $DIR/not-send.rs:19:5
33
|
4-
19 | is_send::<Consumer<NotSend, consts::U4>>();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
4+
12 | fn is_send<T>()
5+
| ------- required by a bound in this
6+
13 | where
7+
14 | T: Send,
8+
| ---- required by this bound in `is_send`
9+
...
10+
19 | is_send::<Consumer<NotSend, 4>>();
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
612
|
7-
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
8-
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
9-
= 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>>`
10-
note: required by `is_send`
11-
--> $DIR/not-send.rs:12:1
12-
|
13-
12 | / fn is_send<T>()
14-
13 | | where
15-
14 | | T: Send,
16-
15 | | {
17-
16 | | }
18-
| |_^
13+
= help: within `PhantomData<*const ()>`, the trait `Send` is not implemented for `*const ()`
14+
= note: required because it appears within the type `PhantomData<*const ()>`
15+
= note: required because of the requirements on the impl of `Send` for `Consumer<'_, PhantomData<*const ()>, 4_usize>`
1916

2017
error[E0277]: `*const ()` cannot be sent between threads safely
2118
--> $DIR/not-send.rs:20:5
2219
|
23-
20 | is_send::<Producer<NotSend, consts::U4>>();
24-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
25-
|
26-
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
27-
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
28-
= 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>>`
29-
note: required by `is_send`
30-
--> $DIR/not-send.rs:12:1
20+
12 | fn is_send<T>()
21+
| ------- required by a bound in this
22+
13 | where
23+
14 | T: Send,
24+
| ---- required by this bound in `is_send`
25+
...
26+
20 | is_send::<Producer<NotSend, 4>>();
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
3128
|
32-
12 | / fn is_send<T>()
33-
13 | | where
34-
14 | | T: Send,
35-
15 | | {
36-
16 | | }
37-
| |_^
29+
= help: within `PhantomData<*const ()>`, the trait `Send` is not implemented for `*const ()`
30+
= note: required because it appears within the type `PhantomData<*const ()>`
31+
= note: required because of the requirements on the impl of `Send` for `Producer<'_, PhantomData<*const ()>, 4_usize>`
3832

3933
error[E0277]: `*const ()` cannot be sent between threads safely
4034
--> $DIR/not-send.rs:21:5
4135
|
42-
21 | is_send::<Queue<NotSend, consts::U4>>();
43-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
44-
|
45-
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
46-
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
47-
= 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>>`
48-
= 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>>>`
49-
= 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>>>`
50-
= 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>>>`
51-
= 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>>`
52-
note: required by `is_send`
53-
--> $DIR/not-send.rs:12:1
36+
12 | fn is_send<T>()
37+
| ------- required by a bound in this
38+
13 | where
39+
14 | T: Send,
40+
| ---- required by this bound in `is_send`
41+
...
42+
21 | is_send::<Queue<NotSend, 4>>();
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
5444
|
55-
12 | / fn is_send<T>()
56-
13 | | where
57-
14 | | T: Send,
58-
15 | | {
59-
16 | | }
60-
| |_^
45+
= help: within `Queue<PhantomData<*const ()>, 4_usize>`, the trait `Send` is not implemented for `*const ()`
46+
= note: required because it appears within the type `PhantomData<*const ()>`
47+
= note: required because it appears within the type `ManuallyDrop<PhantomData<*const ()>>`
48+
= note: required because it appears within the type `MaybeUninit<PhantomData<*const ()>>`
49+
= note: required because it appears within the type `UnsafeCell<MaybeUninit<PhantomData<*const ()>>>`
50+
= note: required because it appears within the type `[UnsafeCell<MaybeUninit<PhantomData<*const ()>>>; 4]`
51+
= note: required because it appears within the type `Queue<PhantomData<*const ()>, 4_usize>`
6152

6253
error[E0277]: `*const ()` cannot be sent between threads safely
6354
--> $DIR/not-send.rs:22:5
6455
|
65-
22 | is_send::<heapless::Vec<NotSend, consts::U4>>();
66-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
56+
12 | fn is_send<T>()
57+
| ------- required by a bound in this
58+
13 | where
59+
14 | T: Send,
60+
| ---- required by this bound in `is_send`
61+
...
62+
22 | is_send::<Vec<NotSend, 4>>();
63+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
64+
|
65+
= help: within `heapless::Vec<PhantomData<*const ()>, 4_usize>`, the trait `Send` is not implemented for `*const ()`
66+
= note: required because it appears within the type `PhantomData<*const ()>`
67+
= note: required because it appears within the type `[PhantomData<*const ()>; 4]`
68+
= note: required because it appears within the type `ManuallyDrop<[PhantomData<*const ()>; 4]>`
69+
= note: required because it appears within the type `MaybeUninit<[PhantomData<*const ()>; 4]>`
70+
= note: required because it appears within the type `heapless::Vec<PhantomData<*const ()>, 4_usize>`
71+
72+
error[E0277]: `*const ()` cannot be sent between threads safely
73+
--> $DIR/not-send.rs:23:5
6774
|
68-
= help: within `std::marker::PhantomData<*const ()>`, the trait `std::marker::Send` is not implemented for `*const ()`
69-
= note: required because it appears within the type `std::marker::PhantomData<*const ()>`
70-
= 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>>`
71-
= 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>>>`
72-
= 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>>>`
73-
= 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>>>`
74-
= 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>>`
75-
note: required by `is_send`
76-
--> $DIR/not-send.rs:12:1
75+
12 | fn is_send<T>()
76+
| ------- required by a bound in this
77+
13 | where
78+
14 | T: Send,
79+
| ---- required by this bound in `is_send`
80+
...
81+
23 | is_send::<HistoryBuffer<NotSend, 4>>();
82+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*const ()` cannot be sent between threads safely
7783
|
78-
12 | / fn is_send<T>()
79-
13 | | where
80-
14 | | T: Send,
81-
15 | | {
82-
16 | | }
83-
| |_^
84+
= help: within `HistoryBuffer<PhantomData<*const ()>, 4_usize>`, the trait `Send` is not implemented for `*const ()`
85+
= note: required because it appears within the type `PhantomData<*const ()>`
86+
= note: required because it appears within the type `ManuallyDrop<PhantomData<*const ()>>`
87+
= note: required because it appears within the type `MaybeUninit<PhantomData<*const ()>>`
88+
= note: required because it appears within the type `[MaybeUninit<PhantomData<*const ()>>; 4]`
89+
= note: required because it appears within the type `HistoryBuffer<PhantomData<*const ()>, 4_usize>`

0 commit comments

Comments
 (0)
Please sign in to comment.