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

Make the Entry API of HashMap<K, V> Sync and Send (fixes #45219) #58369

Open
wants to merge 1 commit into
base: master
from

Conversation

Projects
None yet
5 participants
@nox
Copy link
Contributor

nox commented Feb 11, 2019

No description provided.

@rust-highfive

This comment was marked as outdated.

Copy link
Collaborator

rust-highfive commented Feb 11, 2019

r? @Mark-Simulacrum

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Feb 11, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:00faed26:start=1549882393560818984,finish=1549882467197551580,duration=73636732596
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
[00:03:47]    Compiling alloc v0.0.0 (/checkout/src/liballoc)
[00:03:47]    Compiling panic_abort v0.0.0 (/checkout/src/libpanic_abort)
[00:03:47]    Compiling rustc-demangle v0.1.10
[00:03:53]    Compiling panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
[00:03:54] error[E0119]: conflicting implementations of trait `core::marker::Send` for type `collections::hash::map::OccupiedEntry<'_, _, _>`:
[00:03:54]      |
[00:03:54]      |
[00:03:54] 2343 | unsafe impl<'a, K: Send, V: Send> Send for OccupiedEntry<'a, K, V> {}
[00:03:54]      | ------------------------------------------------------------------ first implementation here
[00:03:54] ...
[00:03:54] 2367 | unsafe impl<'a, K: Send, V: Send> Send for OccupiedEntry<'a, K, V> {}
[00:03:54]      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `collections::hash::map::OccupiedEntry<'_, _, _>`
[00:03:54] 
[00:03:54] error[E0119]: conflicting implementations of trait `core::marker::Sync` for type `collections::hash::map::OccupiedEntry<'_, _, _>`:
[00:03:54]      |
[00:03:54]      |
[00:03:54] 2342 | unsafe impl<'a, K: Sync, V: Sync> Sync for OccupiedEntry<'a, K, V> {}
[00:03:54]      | ------------------------------------------------------------------ first implementation here
[00:03:54] ...
[00:03:54] 2366 | unsafe impl<'a, K: Sync, V: Sync> Sync for OccupiedEntry<'a, K, V> {}
[00:03:54]      | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `collections::hash::map::OccupiedEntry<'_, _, _>`
[00:03:55] error: aborting due to 2 previous errors
[00:03:55] 
[00:03:55] For more information about this error, try `rustc --explain E0119`.
[00:03:55] error: Could not compile `std`.
[00:03:55] error: Could not compile `std`.
[00:03:55] 
[00:03:55] To learn more, run the command again with --verbose.
[00:03:55] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:03:55] expected success, got: exit code: 101
[00:03:55] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:03:55] Build completed unsuccessfully in 0:00:43
[00:03:55] make: *** [all] Error 1
[00:03:55] Makefile:18: recipe for target 'all' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:2b12766f
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Mon Feb 11 10:58:31 UTC 2019
---
travis_time:end:06e70fd8:start=1549882712448112337,finish=1549882712454029310,duration=5916973
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:01237e53
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:03649e7c
travis_time:start:03649e7c
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0e11e039
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@nox nox force-pushed the nox:sync-hash-map-entry branch from 5b84f65 to fafe8ce Feb 11, 2019

@rust-highfive

This comment was marked as resolved.

Copy link
Collaborator

rust-highfive commented Feb 11, 2019

The job x86_64-gnu-llvm-6.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:07765be8:start=1549883109322738929,finish=1549883205873991314,duration=96551252385
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#pull-requests-and-security-restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-6.0
---
[00:06:40]    Compiling panic_unwind v0.0.0 (/checkout/src/libpanic_unwind)
[00:06:45] error: This node does not have a stability attribute
[00:06:45]     --> src/libstd/collections/hash/map.rs:2342:1
[00:06:45]      |
[00:06:45] 2342 | unsafe impl<'a, K: 'a + Sync, V: 'a + Sync> Sync for OccupiedEntry<'a, K, V> {}
[00:06:45] 
[00:06:45] error: This node does not have a stability attribute
[00:06:45]     --> src/libstd/collections/hash/map.rs:2343:1
[00:06:45]      |
[00:06:45]      |
[00:06:45] 2343 | unsafe impl<'a, K: 'a + Send, V: 'a + Send> Send for OccupiedEntry<'a, K, V> {}
[00:06:45] 
[00:06:45] error: This node does not have a stability attribute
[00:06:45]     --> src/libstd/collections/hash/map.rs:2366:1
[00:06:45]      |
[00:06:45]      |
[00:06:45] 2366 | unsafe impl<'a, K: 'a + Sync, V: 'a + Sync> Sync for VacantEntry<'a, K, V> {}
[00:06:45] 
[00:06:45] error: This node does not have a stability attribute
[00:06:45]     --> src/libstd/collections/hash/map.rs:2367:1
[00:06:45]      |
[00:06:45]      |
[00:06:45] 2367 | unsafe impl<'a, K: 'a + Send, V: 'a + Send> Send for VacantEntry<'a, K, V> {}
[00:06:45] 
[00:06:45] error: aborting due to 4 previous errors
[00:06:45] 
[00:06:45] error: Could not compile `std`.
[00:06:45] error: Could not compile `std`.
[00:06:45] 
[00:06:45] To learn more, run the command again with --verbose.
[00:06:45] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "build" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--features" "panic-unwind backtrace" "--manifest-path" "/checkout/src/libstd/Cargo.toml" "--message-format" "json"
[00:06:45] expected success, got: exit code: 101
[00:06:45] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:06:45] Build completed unsuccessfully in 0:00:46
[00:06:45] Makefile:18: recipe for target 'all' failed
[00:06:45] make: *** [all] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:0e86bba4
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Mon Feb 11 11:13:40 UTC 2019
---
travis_time:end:0050c1fc:start=1549883620966935299,finish=1549883620972276615,duration=5341316
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:1bdb3441
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0db17cd6
travis_time:start:0db17cd6
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:13edd330
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@nox nox force-pushed the nox:sync-hash-map-entry branch from fafe8ce to 1bcb6b3 Feb 11, 2019

@Mark-Simulacrum

This comment has been minimized.

Copy link
Member

Mark-Simulacrum commented Feb 11, 2019

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Feb 11, 2019

Would it be possible to place these impls at the root cause of why they're not send/sync today? Placing them so high up looks pretty tricky and error prone

@nox

This comment has been minimized.

Copy link
Contributor Author

nox commented Feb 11, 2019

Not really, see my comment in the issue:

If we make table::RawBucket Send and Sync itself, then table::Iter will have an auto implementation of Send where K: Send, V: Send, which is incorrect. I would rather have additional impls on the leafs (here OccupiedEntry and VacantEntry) than implementation at the root which can then cause error-prone auto implementations on other leaves.

@nox

This comment has been minimized.

Copy link
Contributor Author

nox commented Feb 11, 2019

BTreeMap avoids this issue through a marker on NodeRef, but hash tables lack such a concept.

unsafe impl<'a, K: Sync + 'a, V: Sync + 'a, Type> Send
for NodeRef<marker::Immut<'a>, K, V, Type> { }
unsafe impl<'a, K: Send + 'a, V: Send + 'a, Type> Send
for NodeRef<marker::Mut<'a>, K, V, Type> { }

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Feb 12, 2019

@Amanieu having likely looked at the internals here more recently than I, would you be willing to review this?

@Amanieu

This comment has been minimized.

Copy link
Contributor

Amanieu commented Feb 12, 2019

Entry is already Send+Sync in hashbrown, so this change looks fine to me.

Do we want to gate this behind a feature or should we just make it immediately stable? I don't think this change is very controversial.

@alexcrichton

This comment has been minimized.

Copy link
Member

alexcrichton commented Feb 13, 2019

We don't have a way to gate impls like these currently, so it'll be insta-stable. In that case though I'll...

r? @Amanieu

@Amanieu

This comment has been minimized.

Copy link
Contributor

Amanieu commented Feb 13, 2019

@nox Can you remove the unstable feature and just mark the Send/Sync impls as stable?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment