-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Experiment: force debug_assertions in consteval context #97467
Experiment: force debug_assertions in consteval context #97467
Conversation
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
r? @scottmcm (rust-highfive has picked a reviewer for you, use r? to override) |
(Thanks @scottmcm for noticing regardless and nominating it. I have no idea whether the compiler & lang teams should also be involved on this, and mostly just pinged Oli since I know he was helping out solve this issue via other means.) |
Most of the standard library's UB-detecting debug assertions use this macro, which you didn't update: rust/library/core/src/intrinsics.rs Line 2003 in 2aae802
If you update that macro and this PR works as advertised, you should be able to get a compile error from #95332 |
So I will admit that I saw that macro and just left it alone because I wasn't sure what it was trying to accomplish. But in hindsight, those calls could probably just be replaced with |
Whether or not you can, you shouldn't, per the comment in that macro. |
Right, the macro uses abort instead of panicking to reduce code size. I'm not sure why though, since it's intended to be run only on debug builds. |
Making debug builds even slower can make them useless, so some amount of code quality matters even for them. In particular for the extremely common operations that this macro is used in. |
Probably because libstd is built without debug assertions in CI? Technically your code should still emit them in const contexts, but I didn't give it a thorough reading yet. @bors try @rust-timer queue |
⌛ Trying commit fb55d43 with merge de9eef9c0d94a63b720e98be8eafa11f5a5e967f... |
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
☀️ Try build successful - checks-actions |
Queued de9eef9c0d94a63b720e98be8eafa11f5a5e967f with parent 19abca1, future comparison URL. |
Finished benchmarking commit (de9eef9c0d94a63b720e98be8eafa11f5a5e967f): comparison url. Instruction count
Max RSS (memory usage)Results
CyclesResults
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 may lead to changes in compiler perf. Next Steps: If you can justify the regressions found in this try perf run, please indicate this with @bors rollup=never Footnotes |
It's intended to be run on builds with debug assertions enabled. That's not the same as builds with optimizations disabled because runtime doesn't matter. I know of two crates off the top of my head which enable optimizations in the dev and test profiles because |
We talked about this in today's @rust-lang/libs meeting. We felt that this level of performance hit isn't something we'd be able to merge, at all. We're open to the possibility of a conditional mechanism for this, if that would provide value for debugging, and if that didn't have any substantial performance hit when not enabled. |
I assumed as much; when I saw the benchmark I basically assumed this was a non-starter. Will close this since I think more in-depth discussion is necessary before a proper change is proposed. |
This is probably very cursed, but, I saw this as a potential avenue to problems like #95332 and decided to just try and implement it since it felt comically simple.
A lot of unsafe code uses debug assertions to verify safety constraints in debug mode, even though they're removed in release mode. Since compile time is expected to be longer in release mode anyway due to optimisations… why not enable these assertions when doing consteval, since we're expecting compile times to be longer anyway, if it means that we'll catch more problems? While a fully featured UB check is helpful, it's way easier to just use all of the checks we already use to make sure unsafe code is working correctly.
Of course, I have no idea how well this will work, or if it will cause a serious dip in performance, but the code is so small I figured I'd open a PR anyway and see what people think about this idea.
I did try testing and noticed a few UI tests that explicitly try to look for the UB-checker behaviour and try to disable the debug-assert behaviour, and I'm not sure how to deal with these. But other than that, it looks like everything works with this turned on.
Note: I think that a full implementation of this would involve modifying conditional compilation in constants to make
cfg!(debug_assertions)
actually just return true always in consteval, but that's way more complicated since it would mean actually compiling things twice for consteval. Plus, even if we technically modify thecfg!
macro, it will leave#[cfg]
unchanged.This is basically a hack to just apply this to
debug_assert!
for now, and we can figure out the finer details later.Okay, I'm genuinely unsure how tests managed to pass for this when
./x.py test --stage 1
failed locally. But 🤷🏻, cool.