Skip to content
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 PySliceContainer implement Sync #469

Merged
merged 1 commit into from
Nov 20, 2024
Merged

make PySliceContainer implement Sync #469

merged 1 commit into from
Nov 20, 2024

Conversation

Icxolu
Copy link
Contributor

@Icxolu Icxolu commented Nov 19, 2024

Prepares for the pyo3 upgrade to 0.23 in #457.

This contains two changes:

  • This implements Sync for PySliceContainer which is used as the underlying backing object for Rust allocated numpy arrays.
    Since PySliceContainer "virtually" does hold elements of type T (which is cast away due to the no-generics limitation), construction is only allowed from Ts that are Sync themselves. (Ideally we would have unsafe impl<T: Sync> Sync for PySliceContainer<T> {}).

  • I think it will hand out references into that buffer in place, so we need to require all Elements to be Sync as well. In any case I think this could only be too strong, which would not be unsound.

@Icxolu Icxolu requested a review from Copilot November 19, 2024 21:41

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no suggestions.

@Icxolu Icxolu mentioned this pull request Nov 19, 2024
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. cc @ngoldbaum, I wonder if you have opinions on this?

Comment on lines 16 to 24
unsafe impl Send for PySliceContainer {}
unsafe impl Sync for PySliceContainer {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we add some // Safety comments here to justify (both) traits?

@ngoldbaum
Copy link

Forgive my lack of context here: is T the rust type corresponding to an array dtype or something else?

@davidhewitt
Copy link
Member

Yes, exactly that, it'll usually be f64 or similar but can also be basic compound types.

@ngoldbaum
Copy link

In that case yes I agree we should ensure T is Sync.

@Icxolu
Copy link
Contributor Author

Icxolu commented Nov 20, 2024

Thank you both for taking a look. I'll go ahead an merge this then.

@Icxolu Icxolu merged commit 71a82a3 into PyO3:main Nov 20, 2024
64 checks passed
@Icxolu Icxolu deleted the sync branch November 20, 2024 18:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants