Open saethlin opened 9 months ago
Try changing the monomorphic check function from #[inline(never)] to some new attribute that makes them inlinable by LLVM, but not by the MIR inliner. Perhaps we call this #[inline(only_post_mono)]?
There is the rust-cold calling convention. That probably shouldn't be inlined by the mir inliner since we want to tell LLVM that's coldcc.
The LLVM LangRef documents this about coldcc:
Furthermore the inliner doesn’t consider such function calls for inlining.
So I don't think that does the post-mono-only inlining that I described.
What's this?
For a long time, we've been trickling support into the standard library for detecting at runtime calls to unsafe functions that violate their documented preconditions. These checks have become way more interesting with https://github.com/rust-lang/rust/pull/120594 because they can now trip in default
cargo run/test
. Some nice people recently prompted me to list what improvements I want to make on top of that PR, so I'm going to track them here.If you're interested in working on this topic, this issue can be a hub for coordinating that effort. I am not offering mentoring per se but I'd be happy to discuss work on this topic.
Things to do next
debug_assert_nounwind
to use the new intrinsic. https://github.com/rust-lang/rust/pull/120863get_unchecked
should useintrinsics::unreachable
instead ofhint::unreachable_unchecked
and comment why.--emit=llvm-ir
and searching the IR for the check calls.debug_assert_nounwind
andassert_unsafe_precondition
, while ensuring that Library UB checks are checked in Miri/const-eval as described in this comment: https://github.com/rust-lang/rust/pull/121583#issuecomment-1963168186 PR is up at https://github.com/rust-lang/rust/pull/121662const
. This might produce less MIR (and thus improve compile times) but the implementation complexity inside the compiler might not be worth it. (This idea has been obviated by lowering the intrinsic function to aMir::NullOp
, which has very nearly the same effect)#[inline(never)]
to prevent monomorphizing them many times, but that attribute also means LLVM cannot see what is being checked and optimize on it. Try changing the monomorphic check function from#[inline(never)]
to some new attribute that makes them inlinable by LLVM, but not by the MIR inliner. Perhaps we call this#[inline(only_post_mono)]
? https://github.com/rust-lang/rust/pull/121114SimplifyCfg
but aren't. https://github.com/rust-lang/rust/pull/120650 targets this pattern, but we should try to revive the strategy in https://github.com/rust-lang/rust/pull/91222 as well: https://github.com/rust-lang/rust/pull/121421NonNull::new_unchecked
, I'm sure there are others.Implementation history