Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the naive layout isn't refined by the actual layout #113941

Closed
j0lol opened this issue Jul 22, 2023 · 5 comments · Fixed by #113946
Closed

the naive layout isn't refined by the actual layout #113941

j0lol opened this issue Jul 22, 2023 · 5 comments · Fixed by #113946
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@j0lol
Copy link

j0lol commented Jul 22, 2023

Code

unsure, happened in crate inventory when compiling my project

Meta

rustc --version --verbose:

rustc 1.73.0-nightly (0308df23e 2023-07-21)
binary: rustc
commit-hash: 0308df23e621e783e31a27ca5beaa01b9df60d4a
commit-date: 2023-07-21
host: aarch64-unknown-linux-gnu
release: 1.73.0-nightly
LLVM version: 16.0.5

Error output

   Compiling inventory v0.3.9
error: internal compiler error: compiler/rustc_ty_utils/src/layout_sanity_check.rs:25:9: the naive layout isn't refined by the actual layout:
                                NaiveLayout {
                                    abi: Sized,
                                    niches: Maybe,
                                    size: Size(0 bytes),
                                    align: Align(4 bytes),
                                    exact: false,
                                }
                                TyAndLayout {
                                    ty: iter<T>,
                                    layout: Layout {
                                        size: Size(0 bytes),
                                        align: AbiAndPrefAlign {
                                            abi: Align(1 bytes),
                                            pref: Align(8 bytes),
                                        },
                                        abi: Aggregate {
                                            sized: true,
                                        },
                                        fields: Arbitrary {
                                            offsets: [],
                                            memory_index: [],
                                        },
                                        largest_niche: None,
                                        variants: Single {
                                            index: 1,
                                        },
                                        max_repr_align: None,
                                        unadjusted_abi_align: Align(1 bytes),
                                    },
                                }

   Compiling leptos_macro v0.4.5
thread 'rustc' panicked at 'Box<dyn Any>', /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/compiler/rustc_errors/src/lib.rs:1663:9
stack backtrace:
<SNIP>
error: could not compile `inventory` (lib)
Backtrace

   0:     0xffffaabff5c4 - std::backtrace_rs::backtrace::libunwind::trace::h64c27d8061185cee
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0xffffaabff5c4 - std::backtrace_rs::backtrace::trace_unsynchronized::h6b74b1bc14295ff4
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0xffffaabff5c4 - std::sys_common::backtrace::_print_fmt::h8f459cd181b04614
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/sys_common/backtrace.rs:65:5
   3:     0xffffaabff5c4 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h0840aa2c1f6c02b3
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/sys_common/backtrace.rs:44:22
   4:     0xffffaac5b194 - core::fmt::rt::Argument::fmt::hcbce529d895fb3a4
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/core/src/fmt/rt.rs:138:9
   5:     0xffffaac5b194 - core::fmt::write::h84b535bfe0c3925b
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/core/src/fmt/mod.rs:1094:21
   6:     0xffffaabf3f68 - std::io::Write::write_fmt::h31fe50bd51cf41dc
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/io/mod.rs:1714:15
   7:     0xffffaabff414 - std::sys_common::backtrace::_print::hea8ee6a4ed78ee7f
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/sys_common/backtrace.rs:47:5
   8:     0xffffaabff414 - std::sys_common::backtrace::print::h373a8ff7dd9a5b09
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/sys_common/backtrace.rs:34:9
   9:     0xffffaac020a4 - std::panicking::panic_hook_with_disk_dump::{{closure}}::hc1337a36b6032f4e
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/panicking.rs:278:22
  10:     0xffffaac01d7c - std::panicking::panic_hook_with_disk_dump::he3d4cf8fe1f1b2d3
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/panicking.rs:312:9
  11:     0xffffab99fe48 - rustc_driver_impl[82f35ce1073496e1]::install_ice_hook::{closure#0}
  12:     0xffffaac028fc - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h045e5ad2fca6d060
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/alloc/src/boxed.rs:2021:9
  13:     0xffffaac028fc - std::panicking::rust_panic_with_hook::h4181bd553b86022d
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/panicking.rs:733:13
  14:     0xffffb03998a4 - std[62788c2d563118c6]::panicking::begin_panic::<rustc_errors[985b626586fcb10c]::ExplicitBug>::{closure#0}
  15:     0xffffb0395f60 - std[62788c2d563118c6]::sys_common::backtrace::__rust_end_short_backtrace::<std[62788c2d563118c6]::panicking::begin_panic<rustc_errors[985b626586fcb10c]::ExplicitBug>::{closure#0}, !>
  16:     0xffffab8c0504 - std[62788c2d563118c6]::panicking::begin_panic::<rustc_errors[985b626586fcb10c]::ExplicitBug>
  17:     0xffffb041d5c0 - <rustc_errors[985b626586fcb10c]::HandlerInner>::bug::<alloc[d98521ecd4ce54c6]::string::String>
  18:     0xffffb041d424 - <rustc_errors[985b626586fcb10c]::Handler>::bug::<alloc[d98521ecd4ce54c6]::string::String>
  19:     0xffffb03142d4 - rustc_middle[d6524ddd23000e63]::util::bug::opt_span_bug_fmt::<rustc_span[5869028186ac036]::span_encoding::Span>::{closure#0}
  20:     0xffffb0312714 - rustc_middle[d6524ddd23000e63]::ty::context::tls::with_opt::<rustc_middle[d6524ddd23000e63]::util::bug::opt_span_bug_fmt<rustc_span[5869028186ac036]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  21:     0xffffb03126e0 - rustc_middle[d6524ddd23000e63]::ty::context::tls::with_context_opt::<rustc_middle[d6524ddd23000e63]::ty::context::tls::with_opt<rustc_middle[d6524ddd23000e63]::util::bug::opt_span_bug_fmt<rustc_span[5869028186ac036]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  22:     0xffffab8c5f50 - rustc_middle[d6524ddd23000e63]::util::bug::bug_fmt
  23:     0xffffae754848 - rustc_ty_utils[9bb1f0496e50022a]::layout_sanity_check::sanity_check_layout
  24:     0xffffae76ff50 - rustc_ty_utils[9bb1f0496e50022a]::layout::layout_of
  25:     0xffffaf56a504 - rustc_query_impl[5790540113a7ca7c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5790540113a7ca7c]::query_impl::layout_of::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d6524ddd23000e63]::query::erase::Erased<[u8; 16usize]>>
  26:     0xffffaf6d10a4 - <rustc_query_impl[5790540113a7ca7c]::query_impl::layout_of::dynamic_query::{closure#2} as core[b2a4bb11906303c2]::ops::function::FnOnce<(rustc_middle[d6524ddd23000e63]::ty::context::TyCtxt, rustc_middle[d6524ddd23000e63]::ty::ParamEnvAnd<rustc_middle[d6524ddd23000e63]::ty::Ty>)>>::call_once
  27:     0xffffaf73e69c - rustc_query_system[9a5635129a437fda]::query::plumbing::try_execute_query::<rustc_query_impl[5790540113a7ca7c]::DynamicConfig<rustc_query_system[9a5635129a437fda]::query::caches::DefaultCache<rustc_middle[d6524ddd23000e63]::ty::ParamEnvAnd<rustc_middle[d6524ddd23000e63]::ty::Ty>, rustc_middle[d6524ddd23000e63]::query::erase::Erased<[u8; 16usize]>>, false, true, false>, rustc_query_impl[5790540113a7ca7c]::plumbing::QueryCtxt, false>
  28:     0xffffaf5b1194 - rustc_query_impl[5790540113a7ca7c]::query_impl::layout_of::get_query_non_incr::__rust_end_short_backtrace
  29:     0xffffaeb9e8fc - rustc_middle[d6524ddd23000e63]::query::plumbing::query_get_at::<rustc_query_system[9a5635129a437fda]::query::caches::DefaultCache<rustc_middle[d6524ddd23000e63]::ty::ParamEnvAnd<rustc_middle[d6524ddd23000e63]::ty::Ty>, rustc_middle[d6524ddd23000e63]::query::erase::Erased<[u8; 16usize]>>>
  30:     0xffffaeba36d4 - <rustc_mir_transform[aafc68bfa3433c5c]::const_prop::CanConstProp>::check
  31:     0xffffaeba6dd8 - <rustc_mir_transform[aafc68bfa3433c5c]::const_prop_lint::ConstProp as rustc_mir_transform[aafc68bfa3433c5c]::pass_manager::MirLint>::run_lint
  32:     0xffffaeb2d794 - <rustc_session[55fdf58aae6cd726]::session::Session>::time::<(), rustc_mir_transform[aafc68bfa3433c5c]::pass_manager::run_passes_inner::{closure#3}>
  33:     0xffffaebf8188 - rustc_mir_transform[aafc68bfa3433c5c]::pass_manager::run_passes_inner
  34:     0xffffaec13ad4 - rustc_mir_transform[aafc68bfa3433c5c]::run_analysis_to_runtime_passes
  35:     0xffffaec13708 - rustc_mir_transform[aafc68bfa3433c5c]::mir_drops_elaborated_and_const_checked
  36:     0xffffaf569dac - rustc_query_impl[5790540113a7ca7c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5790540113a7ca7c]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d6524ddd23000e63]::query::erase::Erased<[u8; 8usize]>>
  37:     0xffffaf63bbb0 - <rustc_query_impl[5790540113a7ca7c]::query_impl::mir_drops_elaborated_and_const_checked::dynamic_query::{closure#2} as core[b2a4bb11906303c2]::ops::function::FnOnce<(rustc_middle[d6524ddd23000e63]::ty::context::TyCtxt, rustc_span[5869028186ac036]::def_id::LocalDefId)>>::call_once
  38:     0xffffaf78dea8 - rustc_query_system[9a5635129a437fda]::query::plumbing::try_execute_query::<rustc_query_impl[5790540113a7ca7c]::DynamicConfig<rustc_query_system[9a5635129a437fda]::query::caches::VecCache<rustc_span[5869028186ac036]::def_id::LocalDefId, rustc_middle[d6524ddd23000e63]::query::erase::Erased<[u8; 8usize]>>, false, false, false>, rustc_query_impl[5790540113a7ca7c]::plumbing::QueryCtxt, false>
  39:     0xffffaf599954 - rustc_query_impl[5790540113a7ca7c]::query_impl::mir_drops_elaborated_and_const_checked::get_query_non_incr::__rust_end_short_backtrace
  40:     0xffffabb27a58 - <rustc_session[55fdf58aae6cd726]::session::Session>::time::<(), rustc_interface[a76e8fb20eb955f]::passes::analysis::{closure#2}>
  41:     0xffffabb011f0 - rustc_interface[a76e8fb20eb955f]::passes::analysis
  42:     0xffffaf56a248 - rustc_query_impl[5790540113a7ca7c]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[5790540113a7ca7c]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[d6524ddd23000e63]::query::erase::Erased<[u8; 1usize]>>
  43:     0xffffaf5919b4 - <rustc_query_impl[5790540113a7ca7c]::query_impl::analysis::dynamic_query::{closure#2} as core[b2a4bb11906303c2]::ops::function::FnOnce<(rustc_middle[d6524ddd23000e63]::ty::context::TyCtxt, ())>>::call_once
  44:     0xffffaf739318 - rustc_query_system[9a5635129a437fda]::query::plumbing::try_execute_query::<rustc_query_impl[5790540113a7ca7c]::DynamicConfig<rustc_query_system[9a5635129a437fda]::query::caches::SingleCache<rustc_middle[d6524ddd23000e63]::query::erase::Erased<[u8; 1usize]>>, false, false, false>, rustc_query_impl[5790540113a7ca7c]::plumbing::QueryCtxt, false>
  45:     0xffffaf5951f4 - rustc_query_impl[5790540113a7ca7c]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  46:     0xffffab9b87a4 - <rustc_middle[d6524ddd23000e63]::ty::context::GlobalCtxt>::enter::<rustc_driver_impl[82f35ce1073496e1]::run_compiler::{closure#1}::{closure#2}::{closure#4}, core[b2a4bb11906303c2]::result::Result<(), rustc_span[5869028186ac036]::ErrorGuaranteed>>
  47:     0xffffab9dbf34 - rustc_span[5869028186ac036]::set_source_map::<core[b2a4bb11906303c2]::result::Result<(), rustc_span[5869028186ac036]::ErrorGuaranteed>, rustc_interface[a76e8fb20eb955f]::interface::run_compiler<core[b2a4bb11906303c2]::result::Result<(), rustc_span[5869028186ac036]::ErrorGuaranteed>, rustc_driver_impl[82f35ce1073496e1]::run_compiler::{closure#1}>::{closure#0}::{closure#0}>
  48:     0xffffab9aa724 - std[62788c2d563118c6]::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface[a76e8fb20eb955f]::util::run_in_thread_pool_with_globals<rustc_interface[a76e8fb20eb955f]::interface::run_compiler<core[b2a4bb11906303c2]::result::Result<(), rustc_span[5869028186ac036]::ErrorGuaranteed>, rustc_driver_impl[82f35ce1073496e1]::run_compiler::{closure#1}>::{closure#0}, core[b2a4bb11906303c2]::result::Result<(), rustc_span[5869028186ac036]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b2a4bb11906303c2]::result::Result<(), rustc_span[5869028186ac036]::ErrorGuaranteed>>
  49:     0xffffab9ab8f0 - <<std[62788c2d563118c6]::thread::Builder>::spawn_unchecked_<rustc_interface[a76e8fb20eb955f]::util::run_in_thread_pool_with_globals<rustc_interface[a76e8fb20eb955f]::interface::run_compiler<core[b2a4bb11906303c2]::result::Result<(), rustc_span[5869028186ac036]::ErrorGuaranteed>, rustc_driver_impl[82f35ce1073496e1]::run_compiler::{closure#1}>::{closure#0}, core[b2a4bb11906303c2]::result::Result<(), rustc_span[5869028186ac036]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[b2a4bb11906303c2]::result::Result<(), rustc_span[5869028186ac036]::ErrorGuaranteed>>::{closure#1} as core[b2a4bb11906303c2]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  50:     0xffffaac0c354 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::haea932353066af49
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/alloc/src/boxed.rs:2007:9
  51:     0xffffaac0c354 - <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once::h3ab43f4a76e7006f
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/alloc/src/boxed.rs:2007:9
  52:     0xffffaac0c354 - std::sys::unix::thread::Thread::new::thread_start::h8175a8cdc7fbbf76
                               at /rustc/0308df23e621e783e31a27ca5beaa01b9df60d4a/library/std/src/sys/unix/thread.rs:108:17
  53:     0xffffaa974624 - start_thread
  54:     0xffffaaaa749c - <unknown>
  55:                0x0 - <unknown>

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: please attach the file at `/home/tilde/.cargo/registry/src/index.crates.io-6f17d22bba15001f/inventory-0.3.9/rustc-ice-2023-07-22T01:09:03.554883194Z-3312353.txt` to your bug report

note: compiler flags: --crate-type lib -C embed-bitcode=no -C debuginfo=2

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [layout_of] computing layout of `iter<T>`
#1 [mir_drops_elaborated_and_const_checked] elaborating drops for `ITER::<impl at /home/tilde/.cargo/registry/src/index.crates.io-6f17d22bba15001f/inventory-0.3.9/src/lib.rs:284:5: 284:46>::into_iter`
#2 [analysis] running analysis passes on this crate
end of query stack

File attached as instructed: rustc-ice-2023-07-22T01:09:03.554883194Z-3312353.txt

@j0lol j0lol added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 22, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 22, 2023
@dtolnay dtolnay pinned this issue Jul 22, 2023
@dtolnay dtolnay added I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. P-critical Critical priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jul 22, 2023
@dtolnay
Copy link
Member

dtolnay commented Jul 22, 2023

I can repro at https://github.com/dtolnay/inventory/tree/b5c9757fb621f8e429b623d70acfb8ac01238b01 using cargo build. Bisects to #113166 according to cargo-bisect-rustc --start 2023-07-21 --end 2023-07-22 -- build.

@moulins @oli-obk PTAL

dtolnay added a commit to dtolnay/async-trait that referenced this issue Jul 22, 2023
dtolnay added a commit to dtolnay/basic-toml that referenced this issue Jul 22, 2023
dtolnay added a commit to dtolnay/build-alert that referenced this issue Jul 22, 2023
dtolnay added a commit to dtolnay/cargo-expand that referenced this issue Jul 22, 2023
dtolnay added a commit to dtolnay/cargo-llvm-lines that referenced this issue Jul 22, 2023
dtolnay added a commit to dtolnay/cargo-tally that referenced this issue Jul 22, 2023
dtolnay added a commit to dtolnay/cargo-unlock that referenced this issue Jul 22, 2023
dtolnay added a commit to dtolnay/dissimilar that referenced this issue Jul 22, 2023
dtolnay added a commit to dtolnay/dragonbox that referenced this issue Jul 22, 2023
dtolnay added a commit to dtolnay/dyn-clone that referenced this issue Jul 22, 2023
@dtolnay
Copy link
Member

dtolnay commented Jul 22, 2023

Assessing impact: 45 of my repos had failing CI jobs with this ICE. Of those, only 2 (inventory and typetag) were affected in rustc's default configuration, with 1 of those being the root regression (typetag depends on inventory). I've published a workaround in inventory 0.3.10. The other 43 failures were only exhibited when built using -Zrandomize-layout. In total I was using -Zrandomize-layout in 65 of my repos, so some of those additional 20 might have succeeded randomly in today's daily build, and might fail if the build were retried with a different random layout.

In summary this ICE affects a small percentage (1%? less?) of projects that do not build using -Zrandomize-layout ( regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. ). It affects a much larger percentage (70%? more?) of projects which do use -Zrandomize-layout ("regression from nightly to nightly").

@dtolnay dtolnay added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jul 22, 2023
@dtolnay dtolnay unpinned this issue Jul 22, 2023
@dtolnay
Copy link
Member

dtolnay commented Jul 22, 2023

Minimized:

enum Void {}

pub struct Struct([*const (); 0], Void);

pub enum Enum {
    Variant(Struct),
}

@thomcc
Copy link
Member

thomcc commented Jul 22, 2023

It also seems to break miri's stdlib tests: https://github.com/rust-lang/miri-test-libstd/actions/runs/5628275531

@RalfJung
Copy link
Member

It also seems to break miri's stdlib tests: https://github.com/rust-lang/miri-test-libstd/actions/runs/5628275531

miri-test-stdlib sets -Zrandomize-layout so that checks out with the observations above

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jul 22, 2023
…, r=dtolnay

Add regression test for issue rust-lang#113941 - naive layout isn't refined

This PR adds a regression test for issue rust-lang#113941 - `the naive layout isn't refined by the actual layout` based on the minimized repro rust-lang#113941 (comment).
bors added a commit to rust-lang-ci/rust that referenced this issue Jul 22, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#112508 (Tweak spans for self arg, fix borrow suggestion for signature mismatch)
 - rust-lang#113901 (Get rid of subst-relate incompleteness in new solver)
 - rust-lang#113948 (Fix rustc-args passing issue in bootstrap)
 - rust-lang#113950 (Remove Scope::Elision from bound-vars resolution.)
 - rust-lang#113957 (Add regression test for issue rust-lang#113941 - naive layout isn't refined)
 - rust-lang#113959 (Migrate GUI colors test to original CSS color format)

r? `@ghost`
`@rustbot` modify labels: rollup
@apiraino apiraino removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jul 24, 2023
@matthiaskrgr matthiaskrgr unpinned this issue Jul 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants