-
Notifications
You must be signed in to change notification settings - Fork 770
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
require #[pyclass]
to be Sync
#4566
Conversation
I rebased this and am looking at resolving the test failures. The first thing I hit was
Let me know if anyone thinks alternate approaches would be better. |
Although that said, this might also be a separate issue:
|
46ca2df
to
a1437c3
Compare
The latest push switches members that use |
CodSpeed Performance ReportMerging #4566 will not alter performanceComparing Summary
|
If I add an |
4a701cc
to
862b882
Compare
This ultimately comes down to the implementation of the I think a way forward is to expand this machinery to recognize fields that are atomics (maybe via a macro to generate all the necessary code for each atomic type?). I'm going to stop here because this is getting pretty far afield and someone with more rust expertise might be able to give an alternate path forward. |
Can you try implementing |
I think the problem will be what kind of atomic ordering should we use? I guess |
I tried adding impls for both and am still getting the same error, see last push. I get the same error if I do the impl for either of or both |
Actually this is not the same error. We fixed the issue in the GetterGenerator but now there's a different issue in the argument extraction. |
8316e1f
to
0b8d5fa
Compare
Actually, I had a better idea; let's not worry about atomics in this PR and instead just add |
Opened #4668 for the atomics question. For now @ngoldbaum I force-pushed here. I think there is copy that needs to be added to the migration guide and also maybe |
Thanks for taking this on! I added a WIP changelog entry that should link to this. Should the changelog entry give a brief explanation for why we're doing this? |
Woohoo, tests are green! Just needs docs I think. I may try to write something if David doesn't get to it. |
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.
I don't like the stderr output; it's a lot of text. Is there a way to reduce that?
// Safety: `Coroutine` is allowed to be `Sync` even though the future is not, | ||
// because the future is polled with `&mut self` receiver | ||
unsafe impl Sync for Coroutine {} |
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.
Is this the same logic that Exclusive uses? If so, I would prefer that we use that (or our own version of it) rather than this impl.
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.
I marked this ready for review, but I think this hasn't been looked at yet. I'll leave that to David since I'm not sure if using Exclusive
makes sense.
src/impl_/pyclass/assertions.rs
Outdated
diagnostic::on_unimplemented( | ||
message = "the trait `Sync` is not implemented for `{Self}`", | ||
label = "needs to implement `Sync` to be `#[pyclass]`", | ||
note = "to opt-out of threading support, use `#[pyclass(unsendable)]`", |
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.
I'd prefer "replace non-Sync things by Sync things" - not sure on the wording for that.
src/impl_/pyclass/assertions.rs
Outdated
diagnostic_namespace, | ||
diagnostic::on_unimplemented( | ||
message = "the trait `Sync` is not implemented for `{Self}`", | ||
label = "needs to implement `Sync` to be `#[pyclass]`", |
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.
I'd like the tone to be more rustc-y. Also, I feel like "needs to implement Sync" could be understood as "I need to unsafe impl Sync for MyClass" - we should avoid that.
label = "needs to implement `Sync` to be `#[pyclass]`", | |
note = "required by `#[pyclass]`", |
I think the most straightforward way to get a shorter error message is to mark the Perhaps it's possible to refactor this so that there's a little less indirection and maybe get rid of one of the frames in the error message? I don't immediately see how. |
I tried refactoring this to avoid the long error and couldn't figure it out. I hoped that if I made |
I think the big to-do here is docs. @davidhewitt would you like me to take a look at that sometime this week or do you still want to take a crack at it yourself? |
I hope to make various progress on release prep & final pass over docs tomorrow, but feel free to push here if you have time. Otherwise maybe I'll merge this PR as is and we can have one or more docs follow ups to round off the release 😁 |
examples/decorator/src/lib.rs
Outdated
@@ -10,7 +10,7 @@ pub struct PyCounter { | |||
// Keeps track of how many calls have gone through. | |||
// | |||
// See the discussion at the end for why `Cell` is used. |
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 you please update (or maybe delete) this line and the discussion it references? I'm fine with docs being added in followup PRs but it's bad form to leave docs in a wrong (rather than just incomplete or missing) state.
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.
Done, thanks for pointing out that I missed that.
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.
Super, thanks. Let's merge this and then we can parallelise finishing work on docs for 0.23 👍
For #4265
A brief attempt to add a compile error to require
#[pyclass]
values to beSync
. I allow this constraint to be opted-out with the existing#[pyclass(unsendable)]
option.Mostly here I've focused on implementing the compile error with a reasonable diagnostic, I think there's a lot of documentation to add too.