fix: Do not alias fields of tracked_struct Values when updating#741
fix: Do not alias fields of tracked_struct Values when updating#741Veykril merged 2 commits intosalsa-rs:masterfrom
tracked_struct Values when updating#741Conversation
✅ Deploy Preview for salsa-rs canceled.
|
9bfedd4 to
0cf0cc7
Compare
CodSpeed Performance ReportMerging #741 will improve performance by 7.17%Comparing Summary
Benchmarks breakdown
|
tracked_struct Values when updating
|
Does this fix an unsoundness because it otherwise seems to regress perf a little bit. |
|
I believe (if I understand the code correctly) this fixes a theoretical unsoundness when a user leaks a tracked struct value across threads. In that scenario we might try to acquire the read lock and write lock at the same time which could cause aliasing (before we inevitably panic). The perf regression likely comes from taking the read lock in |
|
I'll see if we can craft a test that actually hits that lock setup resulting in a panic (to check if miri might be able to diagnose the theoretical issue) |
8a61975 to
aa3446d
Compare
b9b5e91 to
ba4f5c6
Compare
ba4f5c6 to
b0680ac
Compare
tracked_struct Values when updatingtracked_struct Values when updating
|
I think I'm running into the aliasing bug with Red Knot's WASM based playground. We see instances where it panics with I rebased your PR and I'm no longer seeing the same panic (or it at least makes it much less likely to reproduce 😆) I forgot the specifics of what's left. Should I take this PR from you? |
|
Just whatever is left regarding the review comments I've put up I think, though I am not sure that what you observe would be fixed by this PR (unless we are in fact running into UB!). Feel free to take it over, I'm busy this week with a rust-analyzer refactor |
84e9a6b to
3bc9d3a
Compare
|
@ibraheemdev you're probably the better reviewer for this than I. @Veykril it seems that this PR uses some unstable language features. We could upgrade the MSRV if that helps (I think we're now on 1.85) |
|
That would, iirc raw borrows were stabilized in 1.81 |
ibraheemdev
left a comment
There was a problem hiding this comment.
I think this code could be simplified by using an UnsafeCell on the fields that may be exclusively borrowed, to avoid the pointer casting. I did something similar with interned values. Do you mind if I pick this up?
|
Go ahead |
3bc9d3a to
ae59d83
Compare
ae59d83 to
8f4669f
Compare
|
Rebased and changed the revisions to be atomic. (things got simpler since last time I touched this PR) |
09702f6 to
922f8d2
Compare
|
I did not go with the |
922f8d2 to
ce33fee
Compare
ce33fee to
c2a4c00
Compare
c2a4c00 to
9f47a9e
Compare
|
I think this PR regressed memory usage for ty because, if I understand it correctly, we now store the |
|
We stored it before too though |
|
The |
No description provided.