Skip to content

Commit 28bfd7a

Browse files
committed
Try to deduplicate layout_of query work
1 parent f316e44 commit 28bfd7a

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

compiler/rustc_ty_utils/src/layout.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use rustc_index::bit_set::BitSet;
44
use rustc_index::{IndexSlice, IndexVec};
55
use rustc_middle::mir::{GeneratorLayout, GeneratorSavedLocal};
66
use rustc_middle::query::Providers;
7+
use rustc_middle::traits::Reveal;
78
use rustc_middle::ty::layout::{
89
IntegerExt, LayoutCx, LayoutError, LayoutOf, TyAndLayout, MAX_SIMD_LANES,
910
};
@@ -51,7 +52,19 @@ fn layout_of<'tcx>(
5152
}
5253
};
5354

54-
if ty != unnormalized_ty {
55+
if ty == unnormalized_ty {
56+
// see comment in eval_to_allocation_raw_provider for what we're doing here
57+
if param_env.reveal() == Reveal::All {
58+
let mut query = query;
59+
query.param_env = param_env.with_user_facing();
60+
match tcx.layout_of(query) {
61+
// try again with reveal all as requested
62+
Err(LayoutError::Unknown(_) | LayoutError::NormalizationFailure(_, _)) => {}
63+
// deduplicate calls
64+
other => return other,
65+
}
66+
}
67+
} else {
5568
// Ensure this layout is also cached for the normalized type.
5669
return tcx.layout_of(param_env.and(ty));
5770
}

tests/ui/layout/layout-cycle.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ error[E0391]: cycle detected when computing layout of `S<S<()>>`
22
|
33
= note: ...which requires computing layout of `<S<()> as Tr>::I`...
44
= note: ...which again requires computing layout of `S<S<()>>`, completing the cycle
5+
= note: cycle used when computing layout of `S<S<()>>`
56
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
67

78
error: failed to get layout for S<S<()>>: a cycle occurred during layout computation

0 commit comments

Comments
 (0)