Skip to content

Commit e15359f

Browse files
committed
Auto merge of rust-lang#141039 - lqd:expensive-sanity, r=<try>
move expensive layout sanity check to debug assertions It is [hard to fix](rust-lang#141006 (comment)) the slowness in the uninhabitedness computation for very big types but we can fix the very specific case of them being called during the layout sanity checks, as described in rust-lang#140944. So this PR moves this uninhabitedness check to the other expensive layout sanity checks that are ran under `debug_assertions`. It makes building the `lemmy_api_routes` crate's self-profile `layout_of` query go from ``` +--------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+ | Item | Self time | % of total time | Time | Item count | Incremental result hashing time | +--------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+ | layout_of | 63.02s | 41.895 | 244.26s | 123703 | 50.30ms | +--------------------------------------------------------+-----------+-----------------+----------+------------+---------------------------------+ ``` on master (2m17s total), to ``` | layout_of | 330.21ms | 0.372 | 26.90s | 123703 | 53.19ms | ``` with this PR (1m15s total). (Note that the [perf run results](rust-lang#141039 (comment)) below look a bit better than [an earlier run](https://perf.rust-lang.org/compare.html?start=4eca99a18eab3d4e28ed1ce3ee620d442955a470&end=c4a00993f8ee02c7565e7be652608817ea2fb97d&stat=instructions:u) I did in another PR. There may be some positive noise there, or post-merge results could differ a bit) Since we discussed this today, r? `@compiler-errors` — and cc `@lcnr` and `@RalfJung.`
2 parents c4e05e5 + 102cc2f commit e15359f

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

compiler/rustc_ty_utils/src/layout/invariant.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@ use rustc_middle::ty::layout::{HasTyCtxt, LayoutCx, TyAndLayout};
88
pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayout<'tcx>) {
99
let tcx = cx.tcx();
1010

11-
// Type-level uninhabitedness should always imply ABI uninhabitedness.
12-
if layout.ty.is_privately_uninhabited(tcx, cx.typing_env) {
13-
assert!(
14-
layout.is_uninhabited(),
15-
"{:?} is type-level uninhabited but not ABI-uninhabited?",
16-
layout.ty
17-
);
18-
}
19-
2011
if layout.size.bytes() % layout.align.abi.bytes() != 0 {
2112
bug!("size is not a multiple of align, in the following layout:\n{layout:#?}");
2213
}
@@ -29,6 +20,19 @@ pub(super) fn layout_sanity_check<'tcx>(cx: &LayoutCx<'tcx>, layout: &TyAndLayou
2920
return;
3021
}
3122

23+
// Type-level uninhabitedness should always imply ABI uninhabitedness. This can be expensive on
24+
// big non-exhaustive types, and is [hard to
25+
// fix](https://github.com/rust-lang/rust/issues/141006#issuecomment-2883415000) in general.
26+
// Only doing this sanity check when debug assertions are turned on avoids the issue for the
27+
// very specific case of #140944.
28+
if layout.ty.is_privately_uninhabited(tcx, cx.typing_env) {
29+
assert!(
30+
layout.is_uninhabited(),
31+
"{:?} is type-level uninhabited but not ABI-uninhabited?",
32+
layout.ty
33+
);
34+
}
35+
3236
/// Yields non-ZST fields of the type
3337
fn non_zst_fields<'tcx, 'a>(
3438
cx: &'a LayoutCx<'tcx>,

0 commit comments

Comments
 (0)