Skip to content

Commit 338323b

Browse files
authored
Merge branch 'japaric:master' into bheap_into_vec
2 parents 7f53e74 + 4431ae1 commit 338323b

25 files changed

+1077
-331
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
- nightly
5454
features:
5555
- ""
56+
- "cas"
5657
- "serde"
5758
steps:
5859
- name: Checkout
@@ -92,7 +93,7 @@ jobs:
9293
with:
9394
use-cross: false
9495
command: check
95-
args: --target=${{ matrix.target }} --features=${{ matrix.features }}
96+
args: --target=${{ matrix.target }} --no-default-features --features=${{ matrix.features }}
9697

9798
# Run cpass tests
9899
testcpass:
@@ -290,50 +291,6 @@ jobs:
290291
- name: Run miri
291292
run: MIRIFLAGS=-Zmiri-ignore-leaks cargo miri test
292293

293-
# Only runs when pushing to master branch
294-
deploy:
295-
name: deploy
296-
runs-on: ubuntu-20.04
297-
needs:
298-
- style
299-
- check
300-
- testcpass
301-
- testtsan
302-
- testcfail
303-
# Only run this when pushing to master branch
304-
if: github.ref == 'refs/heads/master'
305-
steps:
306-
- uses: actions/checkout@v2
307-
308-
- name: Set up Python 3.x
309-
uses: actions/setup-python@v2
310-
with:
311-
# Semantic version range syntax or exact version of a Python version
312-
python-version: '3.x'
313-
# Optional - x64 or x86 architecture, defaults to x64
314-
architecture: 'x64'
315-
316-
# You can test your matrix by printing the current Python version
317-
- name: Display Python version
318-
run: python -c "import sys; print(sys.version)"
319-
320-
- name: mdBook Action
321-
uses: peaceiris/[email protected]
322-
with:
323-
mdbook-version: 'latest'
324-
325-
- name: Remove cargo-config
326-
run: rm -f .cargo/config
327-
328-
- name: Build docs
329-
run: cargo doc
330-
331-
- name: Deploy to GH-pages
332-
uses: peaceiris/actions-gh-pages@v3
333-
with:
334-
github_token: ${{ secrets.GITHUB_TOKEN }}
335-
publish_dir: ./target/doc
336-
337294
# Refs: https://github.com/rust-lang/crater/blob/9ab6f9697c901c4a44025cf0a39b73ad5b37d198/.github/workflows/bors.yml#L125-L149
338295
#
339296
# ALL THE PREVIOUS JOBS NEEDS TO BE ADDED TO THE `needs` SECTION OF THIS JOB!

.github/workflows/changelog.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Check that the changelog is updated for all changes.
2+
#
3+
# This is only run for PRs.
4+
5+
on:
6+
pull_request:
7+
# opened, reopened, synchronize are the default types for pull_request.
8+
# labeled, unlabeled ensure this check is also run if a label is added or removed.
9+
types: [opened, reopened, labeled, unlabeled, synchronize]
10+
11+
name: Changelog
12+
13+
jobs:
14+
changelog:
15+
name: Changelog
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout sources
19+
uses: actions/checkout@v2
20+
21+
- name: Check that changelog updated
22+
uses: dangoslen/changelog-enforcer@v3
23+
with:
24+
changeLogPath: CHANGELOG.md
25+
skipLabels: 'needs-changelog, skip-changelog'
26+
missingUpdateErrorMessage: 'Please add a changelog entry in the CHANGELOG.md file.'
27+
env:
28+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,56 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
### Added
11+
12+
### Changed
13+
14+
### Fixed
15+
16+
## [v0.7.12] - 2022-05-12
17+
18+
### Added
19+
20+
* Added support for AVR architecture.
21+
* Add `entry` API to `IndexMap`
22+
* Implement `IntoIterator` trait for `Indexmap`
23+
* Implement `FromIterator` for `String`
24+
* Add `first` and `last` methods to `IndexMap` and `IndexSet`
25+
* Add `pop_{front_back}_unchecked` methods to `Deque`
26+
27+
### Changed
28+
29+
* Optimize the codegen of `Vec::clone`
30+
* `riscv32i` and `riscv32imc` targets unconditionally (e.g. `build --no-default-features`) depends on `atomic-polyfill`
31+
32+
### Fixed
33+
34+
* Inserting an item that replaces an already present item will no longer
35+
fail with an error
36+
37+
## [v0.7.11] - 2022-05-09
38+
39+
### Fixed
40+
41+
* Fixed `pool` example in docstring.
42+
* Fixed undefined behavior in `Vec::truncate()`, `Vec::swap_remove_unchecked()`,
43+
and `Hole::move_to()` (internal to the binary heap implementation).
44+
* Fixed `BinaryHeap` elements are being dropped twice
45+
46+
## [v0.7.10] - 2022-01-21
47+
48+
### Fixed
49+
50+
- `cargo test` can now run on non-`x86` hosts
51+
52+
### Added
53+
54+
- Added `OldestOrdered` iterator for `HistoryBuffer`
55+
56+
### Changed
57+
58+
- `atomic-polyfill` is now enabled and used for `cas` atomic emulation on `riscv` targets
59+
1060
## [v0.7.9] - 2021-12-16
1161

1262
### Fixed
@@ -430,7 +480,10 @@ architecture.
430480

431481
- Initial release
432482

433-
[Unreleased]: https://github.com/japaric/heapless/compare/v0.7.9...HEAD
483+
[Unreleased]: https://github.com/japaric/heapless/compare/v0.7.12...HEAD
484+
[v0.7.12]: https://github.com/japaric/heapless/compare/v0.7.11...v0.7.12
485+
[v0.7.11]: https://github.com/japaric/heapless/compare/v0.7.10...v0.7.11
486+
[v0.7.10]: https://github.com/japaric/heapless/compare/v0.7.9...v0.7.10
434487
[v0.7.9]: https://github.com/japaric/heapless/compare/v0.7.8...v0.7.9
435488
[v0.7.8]: https://github.com/japaric/heapless/compare/v0.7.7...v0.7.8
436489
[v0.7.7]: https://github.com/japaric/heapless/compare/v0.7.6...v0.7.7

Cargo.toml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ keywords = ["static", "no-heap"]
1212
license = "MIT OR Apache-2.0"
1313
name = "heapless"
1414
repository = "https://github.com/japaric/heapless"
15-
version = "0.7.9"
15+
version = "0.7.12"
1616

1717
[features]
1818
default = ["cas"]
@@ -27,12 +27,15 @@ mpmc_large = []
2727
# This flag has no version guarantee, the `defmt` dependency can be updated in a patch release
2828
defmt-impl = ["defmt"]
2929

30-
[target.'cfg(any(target_arch = "x86_64", target_arch = "x86"))'.dev-dependencies]
31-
scoped_threadpool = "0.1.8"
32-
3330
[target.thumbv6m-none-eabi.dependencies]
3431
atomic-polyfill = { version = "0.1.2", optional = true }
3532

33+
[target.riscv32i-unknown-none-elf.dependencies]
34+
atomic-polyfill = { version = "0.1.4" }
35+
36+
[target.riscv32imc-unknown-none-elf.dependencies]
37+
atomic-polyfill = { version = "0.1.4" }
38+
3639
[dependencies]
3740
hash32 = "0.2.1"
3841

@@ -58,3 +61,9 @@ version = "0.1"
5861
[dependencies.defmt]
5962
version = ">=0.2.0,<0.4"
6063
optional = true
64+
65+
[build-dependencies]
66+
rustc_version = "0.4.0"
67+
68+
[package.metadata.docs.rs]
69+
all-features = true

build.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
use std::{env, error::Error};
44

5+
use rustc_version::Channel;
6+
57
fn main() -> Result<(), Box<dyn Error>> {
68
let target = env::var("TARGET")?;
79

@@ -21,23 +23,57 @@ fn main() -> Result<(), Box<dyn Error>> {
2123
println!("cargo:rustc-cfg=armv7a");
2224
}
2325

24-
// built-in targets with no atomic / CAS support as of nightly-2019-12-17
26+
// built-in targets with no atomic / CAS support as of nightly-2022-01-13
27+
// AND not supported by the atomic-polyfill crate
2528
// see the `no-atomics.sh` / `no-cas.sh` script sitting next to this file
2629
match &target[..] {
27-
"msp430-none-elf" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {}
30+
"avr-unknown-gnu-atmega328"
31+
| "bpfeb-unknown-none"
32+
| "bpfel-unknown-none"
33+
| "msp430-none-elf"
34+
// | "riscv32i-unknown-none-elf" // supported by atomic-polyfill
35+
// | "riscv32imc-unknown-none-elf" // supported by atomic-polyfill
36+
| "thumbv4t-none-eabi"
37+
// | "thumbv6m-none-eabi" // supported by atomic-polyfill
38+
=> {}
2839

2940
_ => {
3041
println!("cargo:rustc-cfg=has_cas");
3142
}
3243
};
3344

3445
match &target[..] {
35-
"msp430-none-elf" | "riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {}
46+
"avr-unknown-gnu-atmega328"
47+
| "msp430-none-elf"
48+
// | "riscv32i-unknown-none-elf" // supported by atomic-polyfill
49+
// | "riscv32imc-unknown-none-elf" // supported by atomic-polyfill
50+
=> {}
3651

3752
_ => {
3853
println!("cargo:rustc-cfg=has_atomics");
3954
}
4055
};
4156

57+
// Let the code know if it should use atomic-polyfill or not, and what aspects
58+
// of polyfill it requires
59+
match &target[..] {
60+
"riscv32i-unknown-none-elf" | "riscv32imc-unknown-none-elf" => {
61+
println!("cargo:rustc-cfg=full_atomic_polyfill");
62+
println!("cargo:rustc-cfg=cas_atomic_polyfill");
63+
}
64+
65+
"thumbv6m-none-eabi" => {
66+
println!("cargo:rustc-cfg=cas_atomic_polyfill");
67+
}
68+
_ => {}
69+
}
70+
71+
if !matches!(
72+
rustc_version::version_meta().unwrap().channel,
73+
Channel::Stable | Channel::Beta
74+
) {
75+
println!("cargo:rustc-cfg=unstable_channel");
76+
}
77+
4278
Ok(())
4379
}

src/binary_heap.rs

Lines changed: 69 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
// n)` in-place heapsort.
1010

1111
use core::{
12+
cmp::Ordering,
1213
fmt,
1314
marker::PhantomData,
1415
mem::{self, ManuallyDrop},
1516
ops::{Deref, DerefMut},
1617
ptr, slice,
1718
};
1819

19-
use crate::sealed::binary_heap::Kind;
2020
use crate::vec::Vec;
2121

2222
/// Min-heap
@@ -25,6 +25,32 @@ pub enum Min {}
2525
/// Max-heap
2626
pub enum Max {}
2727

28+
/// The binary heap kind: min-heap or max-heap
29+
pub trait Kind: private::Sealed {
30+
#[doc(hidden)]
31+
fn ordering() -> Ordering;
32+
}
33+
34+
impl Kind for Min {
35+
fn ordering() -> Ordering {
36+
Ordering::Less
37+
}
38+
}
39+
40+
impl Kind for Max {
41+
fn ordering() -> Ordering {
42+
Ordering::Greater
43+
}
44+
}
45+
46+
/// Sealed traits
47+
mod private {
48+
pub trait Sealed {}
49+
}
50+
51+
impl private::Sealed for Max {}
52+
impl private::Sealed for Min {}
53+
2854
/// A priority queue implemented with a binary heap.
2955
///
3056
/// This can be either a min-heap or a max-heap.
@@ -410,8 +436,9 @@ impl<'a, T> Hole<'a, T> {
410436
unsafe fn move_to(&mut self, index: usize) {
411437
debug_assert!(index != self.pos);
412438
debug_assert!(index < self.data.len());
413-
let index_ptr: *const _ = self.data.get_unchecked(index);
414-
let hole_ptr = self.data.get_unchecked_mut(self.pos);
439+
let ptr = self.data.as_mut_ptr();
440+
let index_ptr: *const _ = ptr.add(index);
441+
let hole_ptr = ptr.add(self.pos);
415442
ptr::copy_nonoverlapping(index_ptr, hole_ptr, 1);
416443
self.pos = index;
417444
}
@@ -518,12 +545,6 @@ where
518545
}
519546
}
520547

521-
impl<T, K, const N: usize> Drop for BinaryHeap<T, K, N> {
522-
fn drop(&mut self) {
523-
unsafe { ptr::drop_in_place(self.data.as_mut_slice()) }
524-
}
525-
}
526-
527548
impl<T, K, const N: usize> fmt::Debug for BinaryHeap<T, K, N>
528549
where
529550
K: Kind,
@@ -558,6 +579,45 @@ mod tests {
558579
static mut _B: BinaryHeap<i32, Min, 16> = BinaryHeap::new();
559580
}
560581

582+
#[test]
583+
fn drop() {
584+
droppable!();
585+
586+
{
587+
let mut v: BinaryHeap<Droppable, Max, 2> = BinaryHeap::new();
588+
v.push(Droppable::new()).ok().unwrap();
589+
v.push(Droppable::new()).ok().unwrap();
590+
v.pop().unwrap();
591+
}
592+
593+
assert_eq!(Droppable::count(), 0);
594+
595+
{
596+
let mut v: BinaryHeap<Droppable, Max, 2> = BinaryHeap::new();
597+
v.push(Droppable::new()).ok().unwrap();
598+
v.push(Droppable::new()).ok().unwrap();
599+
}
600+
601+
assert_eq!(Droppable::count(), 0);
602+
603+
{
604+
let mut v: BinaryHeap<Droppable, Min, 2> = BinaryHeap::new();
605+
v.push(Droppable::new()).ok().unwrap();
606+
v.push(Droppable::new()).ok().unwrap();
607+
v.pop().unwrap();
608+
}
609+
610+
assert_eq!(Droppable::count(), 0);
611+
612+
{
613+
let mut v: BinaryHeap<Droppable, Min, 2> = BinaryHeap::new();
614+
v.push(Droppable::new()).ok().unwrap();
615+
v.push(Droppable::new()).ok().unwrap();
616+
}
617+
618+
assert_eq!(Droppable::count(), 0);
619+
}
620+
561621
#[test]
562622
fn min() {
563623
let mut heap = BinaryHeap::<_, Min, 16>::new();

0 commit comments

Comments
 (0)