-
Notifications
You must be signed in to change notification settings - Fork 984
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
Remove panics in Deref
impl of QueueWriteBufferView
and BufferViewMut
#3336
Conversation
Sorry I'm chiming in a bit late, didn't see #3134. Considering we can read from the Thoughts @teoxoy @cwfitzgerald ? |
I'd say that this is quite difficult to document since @nical are you concerned about the ergonomics being slightly worse? |
I am having trouble coming to a conclusion of which option I actually like more. Deref* makes it really easy to use - lets it slot into various apis that take anything that impls Deref (notably Encase). And it's not like we don't have other giant performance footguns that you can easily write. At the end of the day, as long as the panic goes away (as that is notably unidomatic. I think we'll be fine. |
Codecov Report
@@ Coverage Diff @@
## master #3336 +/- ##
==========================================
- Coverage 64.70% 64.49% -0.21%
==========================================
Files 66 86 +20
Lines 37336 42721 +5385
==========================================
+ Hits 24159 27554 +3395
- Misses 13177 15167 +1990
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
In my opinion it's irrelevant whether someone ends up calling Deref or DerefMut (explicitly or implicitly), what matters is that they don't read form the (& or &mut) reference. AsMut has the same problem, it doesn't prevent or discourage reading, it just forces you to type "as_mut()" before doing so. As a result we still need to document that reading has likely undesired effects (potentially slow uncached memory reads and not providing access to the real buffer data). Deref could be useful, here. We should not panic because it is not idiomatic, but we can log a performance warning. If we remove that hook, it will be as easy for accidental reads to happen but we won'be able to put a red flag on some of them.
Yes-ish. My primary concern is that I don't think the way we are trying to paper over the issue helps (I don't think Rust can let us express something that would be helpful for this). The ergonomics cost is not something I'll lose sleep over but at the same time since I'm unconvinced that it helps in a meaningful way, my preference would be to keep things simple. The problem isn't important enough to press further so if my arguments have not swayed you, don't feel bad about merging this as is. |
I'm in the same boat as @cwfitzgerald (don't think there is a satisfactory solution).
This sounds better to me if we keep the @botahamec how do you feel about keeping the current API and logging a warning instead of panicking? |
@teoxoy That works for me. I assume that's referring to |
I'd say let them both have the familiar |
@nical Does that make sense for |
I believe it will give something resembling the correct data, just may be horrendously slow to read from. |
Yep, like @cwfitzgerald said. It makes sense for |
cc0530e
to
510dff6
Compare
I added back |
Oh I guess |
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.
One nit, then g2g
What about logging out warnings? We don't seem to do that yet but was what we previously talked about. |
@teoxoy Oh yes! You're right, I completely forgot. I'll get to 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.
LGTM, thanks!
@botahamec looks like CI is unhappy |
Hmm, it's weird that my editor didn't show any problems. Maybe that's a sign to put less faith in rust-analyzer. Hopefully it works now. |
Ok, coincidentally, |
QueueWriteBufferView
and BufferViewMut
Deref
impl of QueueWriteBufferView
and BufferViewMut
Checklist
cargo clippy
.RUSTFLAGS=--cfg=web_sys_unstable_apis cargo clippy --target wasm32-unknown-unknown
if applicable.Connections
closes #3134
Description
According to the documentation for
Queue::write_buffer_with
:According to the documentation for
Deref
:A similar problem appears in
BufferViewMut
.The way I solved this problem was to get rid of the implementations of
Deref
andDerefMut
for each, implementAsMut
forQueueWriteBufferView
, and add theread
method toBufferViewMut
Testing
I ran
cargo nextest run
.