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

Fix clippy lints on Rust 1.72 #1108

Merged
merged 1 commit into from
Sep 4, 2023
Merged

Fix clippy lints on Rust 1.72 #1108

merged 1 commit into from
Sep 4, 2023

Conversation

ids1024
Copy link
Member

@ids1024 ids1024 commented Aug 30, 2023

Should fix CI build.

I'm not sure about the use of Arc in MemoryRenderBuffer. It seems MemoryRenderBufferInner isn't Send because Box<dyn Any>> isn't. Send can be added there if a Send bound is added on TextureId. But then GlesTexture isn't Send so that presumably isn't desired in general.

@ids1024 ids1024 force-pushed the clippy branch 2 times, most recently from 6699361 to 2b08e4a Compare August 30, 2023 23:25
@codecov-commenter
Copy link

codecov-commenter commented Aug 30, 2023

Codecov Report

Patch coverage: 7.14% and project coverage change: -0.03% ⚠️

Comparison is base (c569c87) 24.01% compared to head (225f0a6) 23.98%.
Report is 7 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1108      +/-   ##
==========================================
- Coverage   24.01%   23.98%   -0.03%     
==========================================
  Files         140      140              
  Lines       21591    21581      -10     
==========================================
- Hits         5184     5176       -8     
+ Misses      16407    16405       -2     
Flag Coverage Δ
wlcs-buffer 21.00% <7.14%> (-0.03%) ⬇️
wlcs-core 20.63% <7.14%> (-0.03%) ⬇️
wlcs-output 8.46% <0.00%> (+<0.01%) ⬆️
wlcs-pointer-input 22.68% <7.14%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Changed Coverage Δ
src/backend/egl/display.rs 0.00% <0.00%> (ø)
src/backend/renderer/element/memory.rs 0.00% <0.00%> (ø)
src/utils/clock.rs 42.55% <0.00%> (+1.31%) ⬆️
src/wayland/tablet_manager/tablet_seat.rs 4.72% <0.00%> (ø)
src/wayland/shell/xdg/mod.rs 30.97% <100.00%> (-0.63%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Drakulix
Copy link
Member

It seems MemoryRenderBufferInner isn't Send because Box> isn't. Send can be added there if a Send bound is added on TextureId. But then GlesTexture isn't Send so that presumably isn't desired in general.

Good point, given this is a trait object (and has to be), we also can't implement Send if the texture is Send, so it looks like anything dealing with textures in this way is currently not Send anyway. So we could just use an Rc here. @cmeissl what do you think of this lint? I guess it would make sense to convert it?

@cmeissl
Copy link
Collaborator

cmeissl commented Aug 31, 2023

It seems MemoryRenderBufferInner isn't Send because Box> isn't. Send can be added there if a Send bound is added on TextureId. But then GlesTexture isn't Send so that presumably isn't desired in general.

Good point, given this is a trait object (and has to be), we also can't implement Send if the texture is Send, so it looks like anything dealing with textures in this way is currently not Send anyway. So we could just use an Rc here. @cmeissl what do you think of this lint? I guess it would make sense to convert it?

Okay, so the only reason I see why we need the inner buffer (and be able to clone it) is to access the data in the render element. I think we can get rid of that completely by removing the memory buffer render element and (re-)using the texture render element. IIRC we did something similar in the wayland render element.

But replacing the Arc with Rc will also work for now and is fine by me.
(I have to continue working on the single pixel buffer PR, this already replaces the wayland render element with a texture render element. So I could extend that and apply the same to the other render elements?)

@@ -335,6 +335,7 @@ impl Instance {
info!("Created new instance");
info!("Enabled instance extensions: {:?}", inner.enabled_extensions);

#[allow(clippy::arc_with_non_send_sync)]
Copy link
Member

Choose a reason for hiding this comment

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

I think this raises a question, do we want to mark the private inner types as send and Sync or add a bunch of allow attributes for these types of cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think in this case it would be reasonable to implement Send and Sync for the inner type. For the use in EGLBufferReader::new we can't do that since it's a *mut wl_display that it reference counts. (Though that could possibly be done in a different way.)

Copy link
Member Author

Choose a reason for hiding this comment

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

 // SAFETY (Host Synchronization): InstanceInner is always stored in an Arc, therefore destruction is
 // synchronized (since the inner value of an Arc is always dropped on a single thread).
// SAFETY: Destruction is externally synchronized (using an internal Arc).
unsafe impl Send for Instance {}
unsafe impl Sync for Instance {}

I think this is safe, though it isn't really related to the fact an Arc is used. Without Arc you'd still only be able to destroy the object once, from one thread.

Copy link
Member

Choose a reason for hiding this comment

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

Dropping an InstanceInner would be safe since it assumes it owns the underlying ash::Instance. Plus if it's Send and Sync the call to vkDestroyInstance is still externally synchronized (by the borrow checker). And ash makes that function unsafe, so you'd need to know the semantics of InstanceInner to not cause undefined behavior.

I think we can mark InstanceInner as Send + Sync and then remove the manual Send + Sync impls on Instance.

Should fix CI build.

Uses `Rc<RefCell<_>>` instead of `Arc<Mutex<_>` in `MemoryRenderBuffer`.
`MemoryRenderBufferInner` isn't `Send` because `Box<dyn Any>>` isn't.
`Send` can be added there if a `Send` bound is added on `TextureId`.
But then `GlesTexture` isn't `Send` so that presumably isn't desired in
general.
@ids1024
Copy link
Member Author

ids1024 commented Aug 31, 2023

Okay, changed to Rc<RefCell<MemoryRenderBufferInner>> if it's not going to be Send or Sync anyway, and updated InstanceInner to be Send + Sync.

Copy link
Member

@Drakulix Drakulix left a comment

Choose a reason for hiding this comment

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

Looks good to me, lets get CI going again.

@Drakulix Drakulix merged commit e0c3a9b into Smithay:master Sep 4, 2023
36 checks passed
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.

5 participants