Skip to content

Commit

Permalink
Try to deduplicate layout_of query work
Browse files Browse the repository at this point in the history
  • Loading branch information
oli-obk committed Sep 18, 2023
1 parent f316e44 commit 28bfd7a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
15 changes: 14 additions & 1 deletion compiler/rustc_ty_utils/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use rustc_index::bit_set::BitSet;
use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::mir::{GeneratorLayout, GeneratorSavedLocal};
use rustc_middle::query::Providers;
use rustc_middle::traits::Reveal;
use rustc_middle::ty::layout::{
IntegerExt, LayoutCx, LayoutError, LayoutOf, TyAndLayout, MAX_SIMD_LANES,
};
Expand Down Expand Up @@ -51,7 +52,19 @@ fn layout_of<'tcx>(
}
};

if ty != unnormalized_ty {
if ty == unnormalized_ty {
// see comment in eval_to_allocation_raw_provider for what we're doing here
if param_env.reveal() == Reveal::All {
let mut query = query;
query.param_env = param_env.with_user_facing();
match tcx.layout_of(query) {
// try again with reveal all as requested
Err(LayoutError::Unknown(_) | LayoutError::NormalizationFailure(_, _)) => {}
// deduplicate calls
other => return other,
}
}
} else {
// Ensure this layout is also cached for the normalized type.
return tcx.layout_of(param_env.and(ty));
}
Expand Down
1 change: 1 addition & 0 deletions tests/ui/layout/layout-cycle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ error[E0391]: cycle detected when computing layout of `S<S<()>>`
|
= note: ...which requires computing layout of `<S<()> as Tr>::I`...
= note: ...which again requires computing layout of `S<S<()>>`, completing the cycle
= note: cycle used when computing layout of `S<S<()>>`
= 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

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

0 comments on commit 28bfd7a

Please sign in to comment.