-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Send sync implementation on iterators #27615
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
Conversation
We'd only need Send + Sync on I had another question for you, do you know why |
@bluss it ptr::read's out K,V pairs. Not sure if that necessitates it... this code has seen a lot of changes in the Phantom story. RawBuckets should... basically be fine to impl for? Doesn't really matter since it's internal. |
So... What should I add/remove/update ? |
@gankro It matters if all the things using RawBuckets would automatically inherit Send + Sync |
Nothing in hashmap uses shared state/internal mutability so it's all trivially thread-safe, as far as I know. |
@GuillaumeGomez If you impl Send + Sync for RawBuckets instead, all the rest should be inherited automatically. |
Can you add the iterators to sync-send-iterators-in-libcollections.rs? (Or are they somewhere else?) |
@bluss: sure ! |
fa4bc81
to
829e209
Compare
I added the test. |
3500eeb
to
cf763a0
Compare
Thanks! I'd prefer you squash the commits together to clean it up. r=me with squash |
164f7cf
to
c040c20
Compare
@@ -741,6 +741,9 @@ struct RawBuckets<'a, K, V> { | |||
marker: marker::PhantomData<&'a ()>, | |||
} | |||
|
|||
unsafe impl<'a, K: Send, V: Send> Send for RawBuckets<'a, K, V> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, it's not obvious to me that this is the right thing. Maybe this should be K: Sync, V: Sync
? Basically, I'm asking what reference/value semantics does RawBuckets
have with K
and V
?
Giving this issue to huon, who is much more experienced in the details of correct |
So, my plan make this easier by impl on For reference, see this comment for the different cases. The guidelines should be directly applicable since the We only need to impl
|
c040c20
to
c04a084
Compare
@@ -764,18 +764,27 @@ pub struct Iter<'a, K: 'a> { | |||
iter: Keys<'a, K, ()> | |||
} | |||
|
|||
unsafe impl<'a, K: Sync> Sync for Iter<'a, K> {} | |||
unsafe impl<'a, K: Send> Send for Iter<'a, K> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be K: Sync
, since Iter
yields/behaves like &K
.
97ee72b
to
2709683
Compare
@@ -764,18 +764,27 @@ pub struct Iter<'a, K: 'a> { | |||
iter: Keys<'a, K, ()> | |||
} | |||
|
|||
unsafe impl<'a, K: Sync> Sync for Iter<'a, K> {} | |||
unsafe impl<'a, K: Sync> Send for Iter<'a, K> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can these be automatically inferred by applying the traits to the underlying Keys
iterator?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Er actually, all of the modifications in this file should not be necessary as they're built on top of the map iterators
2709683
to
cecd436
Compare
3b8bff2
to
f2f4a5c
Compare
@bors r+ |
📌 Commit f2f4a5c has been approved by |
Part of #22709.
cc @Veedrac
r? @bluss