rust-lang / hashbrown

Rust port of Google's SwissTable hash map
https://rust-lang.github.io/hashbrown
Apache License 2.0
2.46k stars 288 forks source link

hashbrown fails to compile on avr architectures because ahash does not yet support atomic-polyfill #356

Closed mutantbob closed 2 years ago

mutantbob commented 2 years ago

Even after patching hashbrown with #353 , AVR applications using hashbrown fail to compile because ahash fails:

error[E0432]: unresolved import `core::sync::atomic::AtomicUsize`
  --> /home/thoth/.cargo/registry/src/github.com-1ecc6299db9ec823/ahash-0.7.6/src/random_state.rs:33:26
   |
33 | use core::sync::atomic::{AtomicUsize, Ordering};
   |                          ^^^^^^^^^^^ no `AtomicUsize` in `sync::atomic`

tkaitchuck/aHash#124 would solve this issue, but for the 0.8.0 release of ahash.

Attempting to switch hashbrown to the 0.8 release of ahash results in a cascade of errors:

error[E0599]: the function or associated item `default` exists for struct `HashMap<K, V>`, but its trait bounds were not satisfied
    --> /home/thoth/vendor/hashbrown/src/map.rs:308:15
     |
188  | pub struct HashMap<K, V, S = DefaultHashBuilder, A: Allocator + Clone = Global> {
     | -------------------------------------------------------------------------------
     | |
     | function or associated item `default` not found for this struct
     | doesn't satisfy `HashMap<K, V>: Default`
...
308  |         Self::default()
     |               ^^^^^^^ function or associated item cannot be called on `HashMap<K, V>` due to unsatisfied trait bounds
     |
    ::: /home/thoth/vendor/aHash/src/random_state.rs:202:1
     |
202  | pub struct RandomState {
     | ---------------------- doesn't satisfy `RandomState: Default`
     |
note: trait bound `RandomState: Default` was not satisfied
    --> /home/thoth/vendor/hashbrown/src/map.rs:2117:8
     |
2115 | impl<K, V, S, A> Default for HashMap<K, V, S, A>
     |                  -------     -------------------
2116 | where
2117 |     S: Default,
     |        ^^^^^^^ unsatisfied trait bound introduced here
     = help: items from traits can only be used if the trait is implemented and in scope
     = note: the following trait defines an item `default`, perhaps you need to implement it:
             candidate #1: `Default`

error[E0599]: no function or associated item named `default` found for struct `RandomState` in the current scope
   --> /home/thoth/vendor/hashbrown/src/map.rs:326:70
    |
326 |         Self::with_capacity_and_hasher(capacity, DefaultHashBuilder::default())
    |                                                                      ^^^^^^^ function or associated item not found in `RandomState`

error[E0599]: no function or associated item named `default` found for struct `RandomState` in the current scope
   --> /home/thoth/vendor/hashbrown/src/map.rs:338:50
    |
338 |         Self::with_hasher_in(DefaultHashBuilder::default(), alloc)
    |                                                  ^^^^^^^ function or associated item not found in `RandomState`

error[E0599]: no function or associated item named `default` found for struct `RandomState` in the current scope
   --> /home/thoth/vendor/hashbrown/src/map.rs:347:73
    |
347 |         Self::with_capacity_and_hasher_in(capacity, DefaultHashBuilder::default(), alloc)
    |                                                                         ^^^^^^^ function or associated item not found in `RandomState`

error[E0277]: the trait bound `RandomState: Default` is not satisfied
    --> /home/thoth/vendor/hashbrown/src/map.rs:2189:25
     |
2189 |         arr.into_iter().collect()
     |                         ^^^^^^^ the trait `Default` is not implemented for `RandomState`
     |
     = help: the trait `FromIterator<(K, V)>` is implemented for `HashMap<K, V, S, A>`
note: required because of the requirements on the impl of `FromIterator<(K, V)>` for `HashMap<K, V, RandomState, A>`
    --> /home/thoth/vendor/hashbrown/src/map.rs:6333:18
     |
6333 | impl<K, V, S, A> FromIterator<(K, V)> for HashMap<K, V, S, A>
     |                  ^^^^^^^^^^^^^^^^^^^^     ^^^^^^^^^^^^^^^^^^^
note: required by a bound in `collect`
    --> /home/thoth/.rustup/toolchains/nightly-2022-07-10-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:1832:19
     |
1832 |     fn collect<B: FromIterator<Self::Item>>(self) -> B
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect`

error[E0277]: the trait bound `RandomState: Default` is not satisfied
    --> /home/thoth/vendor/hashbrown/src/set.rs:1220:25
     |
1220 |         arr.into_iter().collect()
     |                         ^^^^^^^ the trait `Default` is not implemented for `RandomState`
     |
     = help: the trait `FromIterator<T>` is implemented for `HashSet<T, S, A>`
note: required because of the requirements on the impl of `FromIterator<T>` for `HashSet<T, RandomState, A>`
    --> /home/thoth/vendor/hashbrown/src/set.rs:1189:15
     |
1189 | impl<T, S, A> FromIterator<T> for HashSet<T, S, A>
     |               ^^^^^^^^^^^^^^^     ^^^^^^^^^^^^^^^^
note: required by a bound in `collect`
    --> /home/thoth/.rustup/toolchains/nightly-2022-07-10-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/iter/traits/iterator.rs:1832:19
     |
1832 |     fn collect<B: FromIterator<Self::Item>>(self) -> B
     |                   ^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `collect`

I can imagine two ways forward:

  1. modify hashbrown to support ahash 0.8.0 and wait for tkaitchuck/aHash#124 to be merged
  2. ask ahash to release a patch version of 0.7 (0.7.7?) that solves its atomic-polyfill problem and depend on that ( I have a branch for that https://github.com/tkaitchuck/aHash/compare/master...mutantbob:aHash:atomic-polyfill0.7.6 but have not made a separate pull request because I already have an 0.8.0 pull request)
Amanieu commented 2 years ago

Fixed by #357.