Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,11 +1135,7 @@ impl<'tcx> FnAbiOfHelpers<'tcx> for CodegenCx<'_, 'tcx> {
fn_abi_request: FnAbiRequest<'tcx>,
) -> ! {
match err {
FnAbiError::Layout(
LayoutError::SizeOverflow(_)
| LayoutError::Cycle(_)
| LayoutError::InvalidSimd { .. },
) => {
FnAbiError::Layout(LayoutError::SizeOverflow(_) | LayoutError::InvalidSimd { .. }) => {
self.tcx.dcx().emit_fatal(Spanned { span, node: err });
}
_ => match fn_abi_request {
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_const_eval/src/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ impl<'tcx, M: Machine<'tcx>> LayoutOfHelpers<'tcx> for InterpCx<'tcx, M> {
| LayoutError::SizeOverflow(_)
| LayoutError::InvalidSimd { .. }
| LayoutError::TooGeneric(_)
| LayoutError::ReferencesError(_)
| LayoutError::Cycle(_) => {}
| LayoutError::ReferencesError(_) => {}
}
err_inval!(Layout(err))
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,7 @@ fn should_emit_layout_error<'tcx>(abi: ExternAbi, layout_err: &'tcx LayoutError<
| SizeOverflow(..)
| InvalidSimd { .. }
| NormalizationFailure(..)
| ReferencesError(..)
| Cycle(..) => {
| ReferencesError(..) => {
false // not our job to report these
}
}
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_middle/src/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,6 @@ pub enum LayoutError<'tcx> {
NormalizationFailure(Ty<'tcx>, NormalizationError<'tcx>),
/// A non-layout error is reported elsewhere.
ReferencesError(ErrorGuaranteed),
/// A type has cyclic layout, i.e. the type contains itself without indirection.
Cycle(ErrorGuaranteed),
}

impl<'tcx> fmt::Display for LayoutError<'tcx> {
Expand All @@ -286,7 +284,6 @@ impl<'tcx> fmt::Display for LayoutError<'tcx> {
t,
e.get_type_for_failure()
),
LayoutError::Cycle(_) => write!(f, "a cycle occurred during layout computation"),
LayoutError::ReferencesError(_) => write!(f, "the type has an unknown layout"),
}
}
Expand Down Expand Up @@ -358,8 +355,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
Err(err @ LayoutError::TooGeneric(_)) => err,
// We can't extract SizeSkeleton info from other layout errors
Err(
e @ LayoutError::Cycle(_)
| e @ LayoutError::Unknown(_)
e @ LayoutError::Unknown(_)
| e @ LayoutError::SizeOverflow(_)
| e @ LayoutError::InvalidSimd { .. }
| e @ LayoutError::NormalizationFailure(..)
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_query_impl/src/from_cycle_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use rustc_middle::dep_graph::DepKind;
use rustc_middle::queries::{QueryVTables, TaggedQueryKey};
use rustc_middle::query::CycleError;
use rustc_middle::query::erase::erase_val;
use rustc_middle::ty::layout::LayoutError;
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::{bug, span_bug};
use rustc_span::def_id::{DefId, LocalDefId};
Expand Down Expand Up @@ -226,8 +225,7 @@ fn layout_of<'tcx>(
|| report_cycle(tcx, &cycle_error),
);

let guar = diag.emit();
tcx.arena.alloc(LayoutError::Cycle(guar))
diag.emit().raise_fatal()
}

// item_and_field_ids should form a cycle where each field contains the
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_transmute/src/layout/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ pub(crate) mod rustc {
| LayoutError::InvalidSimd { .. }
| LayoutError::NormalizationFailure(..) => Self::UnknownLayout,
LayoutError::SizeOverflow(..) => Self::SizeOverflow,
LayoutError::Cycle(err) => Self::TypeError(*err),
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions src/librustdoc/html/templates/type_layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ <h2 id="layout" class="section-header"> {# #}
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
the type failed to be normalized. {# #}
</p>
{% when Err(LayoutError::Cycle(_)) %}
<p> {# #}
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
the type's layout depended on the type's layout itself. {# #}
</p>
{% when Err(LayoutError::InvalidSimd {..}) %}
<p> {# #}
<strong>Note:</strong> Encountered an error during type layout; {#+ #}
Expand Down
7 changes: 6 additions & 1 deletion src/tools/miri/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::{iter, thread};

use rustc_abi::ExternAbi;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::FatalErrorMarker;
use rustc_hir::def::Namespace;
use rustc_hir::def_id::DefId;
use rustc_middle::ty::layout::{HasTyCtxt, HasTypingEnv, LayoutCx};
Expand Down Expand Up @@ -477,7 +478,11 @@ pub fn eval_entry<'tcx>(
let res: thread::Result<InterpResult<'_, !>> =
panic::catch_unwind(AssertUnwindSafe(|| ecx.run_threads()));
let res = res.unwrap_or_else(|panic_payload| {
ecx.handle_ice();
// rustc "handles" some errors by unwinding with FatalErrorMarker
// (after emitting suitable diagnostics), so do not treat those as ICEs.
if !panic_payload.is::<FatalErrorMarker>() {
ecx.handle_ice();
}
Comment on lines +483 to +485
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is happening here, why is this needed now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

layout_of cycles will now unwind with FatalErrorMarker (like other fatal errors). Miri is currently treating any unwinding as a panic, which this changes by skipping the ICE message for fatal errors.

It might make sense to also print the backtrace for fatal errors case, as I guess it's similar to #85633 though a bit noisy.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, that unwind is started via resume_unwind so the panic hook never gets called... feels kind of hacky given the function is called "resume" but oh well.

Suggested change
if !panic_payload.is::<FatalErrorMarker>() {
ecx.handle_ice();
}
// rustc "handles" some errors by unwinding with FatalErrorMarker
// (after emitting suitable diagnostics), so do not treat those as ICEs.
if !panic_payload.is::<FatalErrorMarker>() {
ecx.handle_ice();
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resume_unwind doesn't have the best name, it always starts unwinding. It probably should have been just unwind.

panic::resume_unwind(panic_payload)
});
// Obtain the result of the execution. This is always an `Err`, but that doesn't necessarily
Expand Down
3 changes: 1 addition & 2 deletions src/tools/miri/tests/fail/layout_cycle.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//@error-in-other-file: a cycle occurred during layout computation
//~^ ERROR: cycle detected when computing layout of
//~ ERROR: cycle detected when computing layout of

use std::mem;

Expand Down
11 changes: 2 additions & 9 deletions src/tools/miri/tests/fail/layout_cycle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ LL | const SIZE: usize = intrinsics::size_of::<Self>();
| ^^^^^^^^^^^^^^^^^
= 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[E0080]: a cycle occurred during layout computation
--> RUSTLIB/core/src/mem/mod.rs:LL:CC
|
LL | const SIZE: usize = intrinsics::size_of::<Self>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `<S<S<()>> as std::mem::SizedTypeProperties>::SIZE` failed here

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

Some errors have detailed explanations: E0080, E0391.
For more information about an error, try `rustc --explain E0080`.
For more information about this error, try `rustc --explain E0391`.
1 change: 0 additions & 1 deletion tests/ui/layout/layout-cycle.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//@ build-fail
//~^ ERROR: cycle detected when computing layout of
//~? ERROR: a cycle occurred during layout computation

// Issue #111176 -- ensure that we do not emit ICE on layout cycles

Expand Down
16 changes: 2 additions & 14 deletions tests/ui/layout/layout-cycle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ note: cycle used when const-evaluating + checking `core::mem::SizedTypePropertie
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
= 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[E0080]: a cycle occurred during layout computation
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
|
= note: evaluation of `<S<S<()>> as std::mem::SizedTypeProperties>::SIZE` failed here

note: the above error was encountered while instantiating `fn std::mem::size_of::<S<S<()>>>`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These notes are removed without #153194

--> $DIR/layout-cycle.rs:26:5
|
LL | mem::size_of::<S<T>>()
| ^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

Some errors have detailed explanations: E0080, E0391.
For more information about an error, try `rustc --explain E0080`.
For more information about this error, try `rustc --explain E0391`.
6 changes: 0 additions & 6 deletions tests/ui/layout/post-mono-layout-cycle.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ error[E0391]: cycle detected when computing layout of `Wrapper<()>`
= note: cycle used when computing layout of `core::option::Option<Wrapper<()>>`
= 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

note: the above error was encountered while instantiating `fn abi::<()>`
--> $DIR/post-mono-layout-cycle.rs:19:5
|
LL | abi::<T>(None);
| ^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0391`.
21 changes: 0 additions & 21 deletions tests/ui/sized/stack-overflow-trait-infer-98842.64bit.stderr

This file was deleted.

4 changes: 1 addition & 3 deletions tests/ui/sized/stack-overflow-trait-infer-98842.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// issue: rust-lang/rust#98842
//@ check-fail
//@ edition:2021
//@ stderr-per-bitwidth
//~^^^^^ ERROR cycle detected when computing layout of `Foo`
//~^^^^ ERROR cycle detected when computing layout of `Foo`

// If the inner `Foo` is named through an associated type,
// the "infinite size" error does not occur.
Expand All @@ -12,6 +11,5 @@ struct Foo(<&'static Foo as ::core::ops::Deref>::Target);
// and it will infinitely recurse somewhere trying to figure out the
// size of this pointer (is my guess):
const _: *const Foo = 0 as _;
//~^ ERROR a cycle occurred during layout computation

pub fn main() {}
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@ error[E0391]: cycle detected when computing layout of `Foo`
= note: ...which requires computing layout of `<&'static Foo as core::ops::deref::Deref>::Target`...
= note: ...which again requires computing layout of `Foo`, completing the cycle
note: cycle used when const-evaluating + checking `_`
--> $DIR/stack-overflow-trait-infer-98842.rs:14:1
--> $DIR/stack-overflow-trait-infer-98842.rs:13:1
|
LL | const _: *const Foo = 0 as _;
| ^^^^^^^^^^^^^^^^^^^
= 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[E0080]: a cycle occurred during layout computation
--> $DIR/stack-overflow-trait-infer-98842.rs:14:1
|
LL | const _: *const Foo = 0 as _;
| ^^^^^^^^^^^^^^^^^^^ evaluation of `_` failed here

error: aborting due to 2 previous errors
error: aborting due to 1 previous error

Some errors have detailed explanations: E0080, E0391.
For more information about an error, try `rustc --explain E0080`.
For more information about this error, try `rustc --explain E0391`.
Loading