Skip to content

Commit 7bde1fe

Browse files
committed
Reuse cached layout from PostAnalysis when possible.
1 parent 426f187 commit 7bde1fe

File tree

5 files changed

+17
-4
lines changed

5 files changed

+17
-4
lines changed

compiler/rustc_ty_utils/src/layout.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ fn layout_of<'tcx>(
6262
return tcx.layout_of(typing_env.as_query_input(ty));
6363
}
6464

65+
if let ty::TypingMode::Codegen = typing_env.typing_mode {
66+
let with_postanalysis = ty::TypingEnv {
67+
typing_mode: ty::TypingMode::PostAnalysis,
68+
param_env: typing_env.param_env,
69+
};
70+
let res = tcx.layout_of(with_postanalysis.as_query_input(ty));
71+
match res {
72+
Err(LayoutError::TooGeneric(_)) => {}
73+
_ => return res,
74+
};
75+
}
76+
6577
let cx = LayoutCx::new(tcx, typing_env);
6678

6779
let layout = layout_of_uncached(&cx, ty)?;

tests/ui/layout/layout-cycle.stderr

Lines changed: 1 addition & 0 deletions
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

tests/ui/recursion_limit/zero-overflow.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//~ ERROR overflow evaluating the requirement `&mut Self: DispatchFromDyn<&mut RustaceansAreAwesome>
1+
//~ ERROR queries overflow the depth limit!
22
//~| HELP consider increasing the recursion limit
33
//@ build-fail
44

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
error[E0275]: overflow evaluating the requirement `&mut Self: DispatchFromDyn<&mut RustaceansAreAwesome>`
1+
error: queries overflow the depth limit!
22
|
33
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "2"]` attribute to your crate (`zero_overflow`)
4+
= note: query depth increased by 2 when computing layout of `isize`
45

56
error: aborting due to 1 previous error
67

7-
For more information about this error, try `rustc --explain E0275`.

tests/ui/transmutability/structs/repr/transmute_infinitely_recursive_type.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | struct ExplicitlyPadded(Box<ExplicitlyPadded>);
1212
error[E0391]: cycle detected when computing layout of `should_pad_explicitly_packed_field::ExplicitlyPadded`
1313
|
1414
= note: ...which immediately requires computing layout of `should_pad_explicitly_packed_field::ExplicitlyPadded` again
15-
= note: cycle used when evaluating trait selection obligation `(): core::mem::transmutability::TransmuteFrom<should_pad_explicitly_packed_field::ExplicitlyPadded, ValTree(Branch([Leaf(0x00), Leaf(0x00), Leaf(0x00), Leaf(0x00)]): core::mem::transmutability::Assume)>`
15+
= note: cycle used when computing layout of `should_pad_explicitly_packed_field::ExplicitlyPadded`
1616
= 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
1717

1818
error: aborting due to 2 previous errors

0 commit comments

Comments
 (0)