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

feat: impl Send for InnerStarReference for clippy #80

Merged
merged 1 commit into from
Jul 16, 2024

Conversation

sjackman
Copy link
Contributor

@sjackman sjackman commented Jul 15, 2024

  • impl Send for InnerStarReference to fix the clippy lint:
    Error: error: usage of an `Arc` that is not `Send` and `Sync`
    
  • Remove unused impl Send for StarRef
  • Needed to bump RUST_VERSION from 1.65.0 to 1.79.0

Fix the clippy lint:

Error: error: usage of an `Arc` that is not `Send` and `Sync`
  --> src/lib.rs:66:20
   |
66 |             inner: Arc::new(inner),
   |                    ^^^^^^^^^^^^^^^
   |
   = note: `Arc<InnerStarReference>` is not `Send` and `Sync` as `InnerStarReference` is not `Send`
   = help: if the `Arc` will not used be across threads replace it with an `Rc`
   = help: otherwise make `InnerStarReference` `Send` and `Sync` or consider a wrapper type such as `Mutex`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync
   = note: `-D clippy::arc-with-non-send-sync` implied by `-D clippy::suspicious`
   = help: to override `-D clippy::suspicious` add `#[allow(clippy::arc_with_non_send_sync)]`

See https://rust-lang.github.io/rust-clippy/master/index.html#arc_with_non_send_sync

@@ -24,6 +24,7 @@ struct InnerStarReference {
header_view: HeaderView,
}

unsafe impl Send for InnerStarReference {}

Choose a reason for hiding this comment

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

We may want to leave a comment here that this is currently only known to be safe because cellranger runs the destructor on the same thread that creates it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

init_star_ref calls new StarRef and destroy_ref calls delete StarRef

const StarRef* init_star_ref(int argc, const char* const argv[]) {
return new StarRef(argc, argv);
}
Aligner* init_aligner_from_ref(const StarRef* sr) {
return new Aligner(sr);
}
void destroy_aligner(Aligner *a) {
delete a;
}
void destroy_ref(const StarRef* sr) {
delete sr;
}

Chris wrote…

If there's no thread-scoped data magic going on, it's probably safe

@adam-azarchs
Copy link
Member

I'm still a little confused here about why you need reference counting at all here. Why not just use e.g. a Box?

@macklin-10x
Copy link

Given that this underlying object is now marked Send, you may be able to remove a bunch more of the manual Send and Sync impls and let the compiler infer them.

@sjackman
Copy link
Contributor Author

sjackman commented Jul 15, 2024

Adam wrote…

I'm still a little confused here about why you need reference counting at all here. Why not just use e.g. a Box?

Chris wrote in Slack…

if there's no need to synchronize access to BindRef, why are we using Arc in the first place? Instead we should instantiate InnerStarReference in some kind of container that never leaves the invoking thread, and hand out &InnerStarReference, thus guaranteeing that the bindings are never destructed on the wrong thread

I replied…

Passing around the STAR reference by reference makes sense to me, since access to it ought to be read only. I'll leave that to another PR though.

My aim with this PR to clean up the Clippy lint with a minimal change to permit bumping RUST_VERSION from 1.65.0 to 1.79.0 so that dependency versions can be updated in PR

`impl Send for InnerStarReference` to fix the clippy lint:
Error: error: usage of an `Arc` that is not `Send` and `Sync`
@sjackman sjackman force-pushed the s/clippy-Send-InnerStarReference branch from e4aa77e to 7c5bf5e Compare July 15, 2024 20:41
@sjackman
Copy link
Contributor Author

Given that this underlying object is now marked Send, you may be able to remove a bunch more of the manual Send and Sync impls and let the compiler infer them.

I've removed the unused impl Send for StarRef.

Removing unsafe impl Send for StarAligner does not work, because it also contains a pointer *mut BindAligner.

@macklin-10x macklin-10x self-requested a review July 16, 2024 04:38
@sjackman sjackman merged commit 8678758 into master Jul 16, 2024
1 check passed
@sjackman sjackman deleted the s/clippy-Send-InnerStarReference branch July 16, 2024 16:35
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