-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add debug assertions to some unsafe functions #92686
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
It already does get used in the standard library. rust/library/core/src/intrinsics.rs Lines 2077 to 2083 in 02fe61b
|
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 2ecff4e203cc4d32cc0c9f94f3099e01736c9c28 with merge 90cd1c65761dc97f1b34902129d8ffd8a10b5226... |
(The perf run is for the non-debug-assertion-related changes.) |
This comment has been minimized.
This comment has been minimized.
💔 Test failed - checks-actions |
Ah, oops. Please do kick off a perf run once CI passes. |
2ecff4e
to
131a0d1
Compare
This comment has been minimized.
This comment has been minimized.
131a0d1
to
55a9a6e
Compare
@rustbot ready |
@bors try @rust-timer queue |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
⌛ Trying commit 55a9a6e7b3137824cd5b046a3029b8c24782ceda with merge 2e0638c4c955492789a8401d1e2ed15779d55dba... |
☀️ Try build successful - checks-actions |
Queued 2e0638c4c955492789a8401d1e2ed15779d55dba with parent e19ca1d, future comparison URL. |
Finished benchmarking commit (2e0638c4c955492789a8401d1e2ed15779d55dba): comparison url. Summary: This benchmark run did not return any relevant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR led to changes in compiler perf. @bors rollup=never |
I ran some performance tests on debug builds of a local codebase that uses @bors r+ |
📌 Commit 6e6d0cb has been approved by |
☀️ Test successful - checks-actions |
Finished benchmarking commit (168a020): comparison url. Summary:
If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression Footnotes |
…homcc Add a forgotten check for NonNull::new_unchecked's precondition Looks like I forgot this function a while ago in rust-lang#92686 r? `@thomcc`
…homcc Add a forgotten check for NonNull::new_unchecked's precondition Looks like I forgot this function a while ago in rust-lang#92686 r? ``@thomcc``
…homcc Add a forgotten check for NonNull::new_unchecked's precondition Looks like I forgot this function a while ago in rust-lang#92686 r? ```@thomcc```
940: Fix get_unchecked panic by raw pointer calculation r=taiki-e a=sticnarf It is related to #878 but doesn't fix it. Miri still complains with this PR. It fixes the panic on recent toolchains (after rust-lang/rust#92686) when using `-Zbuild-std`. ``` $ RUST_BACKTRACE=1 cargo test -p crossbeam-skiplist -Zbuild-std --target x86_64-unknown-linux-gnu --test map -- smoke Finished test [unoptimized + debuginfo] target(s) in 0.03s Running tests/map.rs (target/x86_64-unknown-linux-gnu/debug/deps/map-509dc855f6125f07) running 1 test thread 'smoke' panicked at 'unsafe precondition(s) violated: slice::get_unchecked requires that the index is within the slice', /home/yilin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:87:58 stack backtrace: 0: rust_begin_unwind at /home/yilin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/panicking.rs:575:5 1: core::panicking::panic_str_nounwind at /home/yilin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/panicking.rs:90:14 2: <usize as core::slice::index::SliceIndex<[T]>>::get_unchecked::runtime at /home/yilin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/intrinsics.rs:2284:21 3: <usize as core::slice::index::SliceIndex<[T]>>::get_unchecked at /home/yilin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/index.rs:236:13 4: core::slice::<impl [T]>::get_unchecked at /home/yilin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/slice/mod.rs:399:20 5: <crossbeam_skiplist::base::Tower<K,V> as core::ops::index::Index<usize>>::index at ./src/base.rs:39:18 6: crossbeam_skiplist::base::SkipList<K,V>::search_position at ./src/base.rs:781:24 7: crossbeam_skiplist::base::SkipList<K,V>::insert_internal at ./src/base.rs:871:26 8: crossbeam_skiplist::base::SkipList<K,V>::insert at ./src/base.rs:1085:9 9: crossbeam_skiplist::map::SkipMap<K,V>::insert at ./src/map.rs:375:20 10: map::smoke at ./tests/map.rs:9:5 11: map::smoke::{{closure}} at ./tests/map.rs:7:12 12: core::ops::function::FnOnce::call_once at /home/yilin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:507:5 13: core::ops::function::FnOnce::call_once at /home/yilin/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:507:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. thread panicked while panicking. aborting. error: test failed, to rerun pass `-p crossbeam-skiplist --test map` Caused by: process didn't exit successfully: `/home/yilin/Repos/crossbeam/target/x86_64-unknown-linux-gnu/debug/deps/map-509dc855f6125f07 smoke` (signal: 6, SIGABRT: process abort signal) ``` 941: Fix newly added clippy warnings r=taiki-e a=taiki-e Co-authored-by: Yilin Chen <[email protected]> Co-authored-by: Taiki Endo <[email protected]>
Add a forgotten check for NonNull::new_unchecked's precondition Looks like I forgot this function a while ago in rust-lang/rust#92686 r? ```@thomcc```
As suggested by #51713
Some similar code callsabort()
instead ofpanic!()
but aborting doesn't work in aconst fn
, and the intrinsic for doing dispatch based on whether execution is in a const is unstable.This picked up some invalid uses of
get_unchecked
in the compiler, and fixes them.I can confirm that they do in fact pick up invalid uses of
get_unchecked
in the wild, though the user experience is less-than-awesome:As best I can tell these changes produce a 6% regression in the runtime of./x.py test
when[rust] debug = true
is set.Latest commit (6894d55) brings the additional overhead from this PR down to 0.5%, while also adding a few more assertions. I think this actually covers all the places in
core
that it is reasonable to check for safety requirements at runtime.Thoughts?