-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Fix a dangling reference in rustc_thread_pool
#146799
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
Conversation
// SAFETY: Once we call `set` on the internal `latch`, | ||
// the target may proceed and invalidate `this`! | ||
match unsafe { &(*this).kind } { |
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.
A safety comment here should explain why it is safe to create a reference out of (*this).kind
. That it does not seem to do that, may be the reason it is a NOTE.
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.
Well, we added the NOTE in rayon before there was much consensus on proper SAFETY comments. It's definitely a safety-relevant comment, even if it's not directly justifying this unsafe
.
(Personally, I would have used a single unsafe
block around all of this, but this was also added after the port from rayon. Originally, it's still using the unsafe fn
context for inner unsafe
too.)
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.
r=me after safety comment
57382b2
to
389a502
Compare
Thanks for the review -- I added another SAFETY comment as requested. @bors r=lcnr |
Fix a dangling reference in `rustc_thread_pool` This diverged from `rayon` in rust-lang#142384, where a cleanup commit turned the matched `worker_index` into a reference, which is read _after_ the `set` that may kill it. I've moved that read beforehand, and I hope the new comments will emphasize the subtlety of this unsafe code. Hopefully fixes rust-lang#146677.
Rollup of 13 pull requests Successful merges: - #146632 (Fix uses of "adaptor") - #146731 (test: Use SVG for terminal url test) - #146775 (fixes for numerous clippy warnings) - #146784 ([win] Use find-msvc-tools instead of cc to find the linker and rc on Windows) - #146799 (Fix a dangling reference in `rustc_thread_pool`) - #146802 (mbe: Simplifications and refactoring) - #146806 (add private module override re-export test) - #146827 (Linker-plugin-based LTO: update list of good combinations (inc. beta + nightly)) - #146875 (tests/run-make/crate-loading: Rename source files for clarity) - #146896 (rustc-dev-guide subtree update) - #146898 (Update books) - #146899 (Fix a crash/mislex when more than one frontmatter closing possibility is considered) - #146907 (add regression test for issue 146537) r? `@ghost` `@rustbot` modify labels: rollup
Rollup of 10 pull requests Successful merges: - #146632 (Fix uses of "adaptor") - #146731 (test: Use SVG for terminal url test) - #146775 (fixes for numerous clippy warnings) - #146784 ([win] Use find-msvc-tools instead of cc to find the linker and rc on Windows) - #146799 (Fix a dangling reference in `rustc_thread_pool`) - #146802 (mbe: Simplifications and refactoring) - #146806 (add private module override re-export test) - #146827 (Linker-plugin-based LTO: update list of good combinations (inc. beta + nightly)) - #146875 (tests/run-make/crate-loading: Rename source files for clarity) - #146877 (prevent line number from being copied in chrome) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #146799 - cuviper:dangling-count-latch, r=lcnr Fix a dangling reference in `rustc_thread_pool` This diverged from `rayon` in #142384, where a cleanup commit turned the matched `worker_index` into a reference, which is read _after_ the `set` that may kill it. I've moved that read beforehand, and I hope the new comments will emphasize the subtlety of this unsafe code. Hopefully fixes #146677.
Fix a dangling reference in `rustc_thread_pool` This diverged from `rayon` in rust-lang#142384, where a cleanup commit turned the matched `worker_index` into a reference, which is read _after_ the `set` that may kill it. I've moved that read beforehand, and I hope the new comments will emphasize the subtlety of this unsafe code. Hopefully fixes rust-lang#146677.
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#146632 (Fix uses of "adaptor") - rust-lang#146731 (test: Use SVG for terminal url test) - rust-lang#146775 (fixes for numerous clippy warnings) - rust-lang#146784 ([win] Use find-msvc-tools instead of cc to find the linker and rc on Windows) - rust-lang#146799 (Fix a dangling reference in `rustc_thread_pool`) - rust-lang#146802 (mbe: Simplifications and refactoring) - rust-lang#146806 (add private module override re-export test) - rust-lang#146827 (Linker-plugin-based LTO: update list of good combinations (inc. beta + nightly)) - rust-lang#146875 (tests/run-make/crate-loading: Rename source files for clarity) - rust-lang#146877 (prevent line number from being copied in chrome) r? `@ghost` `@rustbot` modify labels: rollup
This diverged from
rayon
in #142384, where a cleanup commit turned the matchedworker_index
into a reference, which is read after theset
that may kill it. I've moved that read beforehand, and I hope the new comments will emphasize the subtlety of this unsafe code.Hopefully fixes #146677.