Rollup merge of #111097 - oli-obk:🚲_layout, r=compiler-errors
Avoid ICEing miri on layout query cycles
Miri has special logic for catching panics during interpretation. Raising a fatal error in rustc uses unwinding to abort compilation. Thus miri ends up catching that fatal error and thinks it saw an ICE. While we should probably change that to ignore `Fatal` payloads, I think it's also neat to continue compilation after a layout query cycle 😆
Query cycles now (in addition to reporting an error just like before), return `Err(Cycle)` instead of raising a fatal error. This allows the interpreter to wind down via the regular error paths.
r? `@RalfJung` for a first round, feel free to reroll for the compiler team once the miri side looks good
This commit is contained in:
commit
e87fcf979f
6 changed files with 119 additions and 44 deletions
|
@ -210,6 +210,7 @@ pub enum LayoutError<'tcx> {
|
|||
Unknown(Ty<'tcx>),
|
||||
SizeOverflow(Ty<'tcx>),
|
||||
NormalizationFailure(Ty<'tcx>, NormalizationError<'tcx>),
|
||||
Cycle,
|
||||
}
|
||||
|
||||
impl IntoDiagnostic<'_, !> for LayoutError<'_> {
|
||||
|
@ -230,6 +231,9 @@ impl IntoDiagnostic<'_, !> for LayoutError<'_> {
|
|||
diag.set_arg("failure_ty", e.get_type_for_failure());
|
||||
diag.set_primary_message(fluent::middle_cannot_be_normalized);
|
||||
}
|
||||
LayoutError::Cycle => {
|
||||
diag.set_primary_message(fluent::middle_cycle);
|
||||
}
|
||||
}
|
||||
diag
|
||||
}
|
||||
|
@ -250,6 +254,7 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
|
|||
t,
|
||||
e.get_type_for_failure()
|
||||
),
|
||||
LayoutError::Cycle => write!(f, "a cycle occurred during layout computation"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,6 +106,12 @@ impl<'tcx> Value<TyCtxt<'tcx>, DepKind> for ty::EarlyBinder<ty::Binder<'_, ty::F
|
|||
}
|
||||
}
|
||||
|
||||
impl<'tcx, T> Value<TyCtxt<'tcx>, DepKind> for Result<T, ty::layout::LayoutError<'_>> {
|
||||
fn from_cycle_error(_tcx: TyCtxt<'tcx>, _cycle: &[QueryInfo<DepKind>]) -> Self {
|
||||
Err(ty::layout::LayoutError::Cycle)
|
||||
}
|
||||
}
|
||||
|
||||
// item_and_field_ids should form a cycle where each field contains the
|
||||
// type in the next element in the list
|
||||
pub fn recursive_type_error(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue