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

ICE: we shouldn't be trying to determine if this is unsized for a reason or another #134060

Closed
matthiaskrgr opened this issue Dec 9, 2024 · 5 comments · Fixed by #134064
Closed
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-unboxed_closures `#![feature(unboxed_closures)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ L-improper_ctypes_definitions Lint: improper_ctypes_definitions S-has-bisection Status: a bisection has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@matthiaskrgr
Copy link
Member

auto-reduced (treereduce-rust):

#![crate_type = "lib"]

pub trait Foo {
    extern "C" fn foo_(&self, _: ()) -> i64 {
        0
    }
}

original:

#![feature(unboxed_closures)]
#![crate_type = "lib"]

pub trait Foo {
    extern "C" fn foo_(&self, _: ()) -> i64 {
        0
    }
}

Version information

rustc 1.85.0-nightly (1b3fb3167 2024-12-09)
binary: rustc
commit-hash: 1b3fb316751227d30b1523ed0e3f00d83956d4d0
commit-date: 2024-12-09
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.5

Possibly related line of code:

TypeSizedness::Definite => {
bug!("failed to find the reason why tuple `{:?}` is unsized", ty)
}
}
}
ty => {
bug!(
"we shouldn't be trying to determine if this is unsized for a reason or another: `{:?}`",
ty
)
}
}
}

Command:
/home/matthias/.rustup/toolchains/master/bin/rustc

Program output

error: internal compiler error: compiler/rustc_lint/src/types.rs:826:17: we shouldn't be trying to determine if this is unsized for a reason or another: `Self/#0`

thread 'rustc' panicked at compiler/rustc_lint/src/types.rs:826:17:
Box<dyn Any>
stack backtrace:
   0:     0x70f3b053bdaa - <std::sys::backtrace::BacktraceLock::print::DisplayBacktrace as core::fmt::Display>::fmt::h51600df8d4950f4d
   1:     0x70f3b0c13e26 - core::fmt::write::hb7c8a94b6e7648fe
   2:     0x70f3b1b994d1 - std::io::Write::write_fmt::h79afa2539dcac083
   3:     0x70f3b053bc02 - std::sys::backtrace::BacktraceLock::print::h72a8db84ee092cc0
   4:     0x70f3b053e11a - std::panicking::default_hook::{{closure}}::h2de76e304efd002d
   5:     0x70f3b053df63 - std::panicking::default_hook::h488bbcae59025a24
   6:     0x70f3af6adac8 - std[c899b8b05f76e59a]::panicking::update_hook::<alloc[3a1511764d158d5a]::boxed::Box<rustc_driver_impl[ca6f906ded399958]::install_ice_hook::{closure#0}>>::{closure#0}
   7:     0x70f3b053e8d8 - std::panicking::rust_panic_with_hook::h1c8dce42f9719b38
   8:     0x70f3af6e2e61 - std[c899b8b05f76e59a]::panicking::begin_panic::<rustc_errors[bb946ab4b6ab9041]::ExplicitBug>::{closure#0}
   9:     0x70f3af6d8006 - std[c899b8b05f76e59a]::sys::backtrace::__rust_end_short_backtrace::<std[c899b8b05f76e59a]::panicking::begin_panic<rustc_errors[bb946ab4b6ab9041]::ExplicitBug>::{closure#0}, !>
  10:     0x70f3af6d7fed - std[c899b8b05f76e59a]::panicking::begin_panic::<rustc_errors[bb946ab4b6ab9041]::ExplicitBug>
  11:     0x70f3af6ece01 - <rustc_errors[bb946ab4b6ab9041]::diagnostic::BugAbort as rustc_errors[bb946ab4b6ab9041]::diagnostic::EmissionGuarantee>::emit_producing_guarantee
  12:     0x70f3afcdbf93 - rustc_middle[c72e907903e7d8bf]::util::bug::opt_span_bug_fmt::<rustc_span[990772e3237250c]::span_encoding::Span>::{closure#0}
  13:     0x70f3afcc1e8a - rustc_middle[c72e907903e7d8bf]::ty::context::tls::with_opt::<rustc_middle[c72e907903e7d8bf]::util::bug::opt_span_bug_fmt<rustc_span[990772e3237250c]::span_encoding::Span>::{closure#0}, !>::{closure#0}
  14:     0x70f3afcc1d1b - rustc_middle[c72e907903e7d8bf]::ty::context::tls::with_context_opt::<rustc_middle[c72e907903e7d8bf]::ty::context::tls::with_opt<rustc_middle[c72e907903e7d8bf]::util::bug::opt_span_bug_fmt<rustc_span[990772e3237250c]::span_encoding::Span>::{closure#0}, !>::{closure#0}, !>
  15:     0x70f3ade4b040 - rustc_middle[c72e907903e7d8bf]::util::bug::bug_fmt
  16:     0x70f3b238cfc0 - rustc_lint[f612aa0c4812ac92]::types::get_type_sizedness.cold
  17:     0x70f3b0de54ee - <rustc_lint[f612aa0c4812ac92]::types::ImproperCTypesVisitor>::check_type_for_ffi
  18:     0x70f3b0de4807 - <rustc_lint[f612aa0c4812ac92]::types::ImproperCTypesVisitor>::check_type_for_ffi_and_report_errors
  19:     0x70f3b0de46d8 - <rustc_lint[f612aa0c4812ac92]::types::ImproperCTypesVisitor>::check_foreign_fn
  20:     0x70f3b20dcd20 - <rustc_lint[f612aa0c4812ac92]::BuiltinCombinedModuleLateLintPass as rustc_lint[f612aa0c4812ac92]::passes::LateLintPass>::check_fn.warm
  21:     0x70f3b0e36937 - <rustc_lint[f612aa0c4812ac92]::late::LateContextAndPass<rustc_lint[f612aa0c4812ac92]::BuiltinCombinedModuleLateLintPass> as rustc_hir[7c7f4c4fbde18468]::intravisit::Visitor>::visit_nested_item
  22:     0x70f3b0e354b7 - rustc_lint[f612aa0c4812ac92]::lint_mod
  23:     0x70f3b0e35249 - rustc_query_impl[f81b18394cfbf639]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f81b18394cfbf639]::query_impl::lint_mod::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c72e907903e7d8bf]::query::erase::Erased<[u8; 0usize]>>
  24:     0x70f3b1b9c441 - rustc_query_system[8aaaf029b136699]::query::plumbing::try_execute_query::<rustc_query_impl[f81b18394cfbf639]::DynamicConfig<rustc_query_system[8aaaf029b136699]::query::caches::DefaultCache<rustc_span[990772e3237250c]::def_id::LocalModDefId, rustc_middle[c72e907903e7d8bf]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[f81b18394cfbf639]::plumbing::QueryCtxt, false>
  25:     0x70f3b1b9a618 - rustc_query_impl[f81b18394cfbf639]::query_impl::lint_mod::get_query_non_incr::__rust_end_short_backtrace
  26:     0x70f3b1b9a202 - rustc_lint[f612aa0c4812ac92]::late::check_crate::{closure#1}
  27:     0x70f3b1b99d78 - rustc_lint[f612aa0c4812ac92]::late::check_crate
  28:     0x70f3b1b9d59d - rustc_interface[16ea6e92cdb33e83]::passes::analysis
  29:     0x70f3b1b9d32f - rustc_query_impl[f81b18394cfbf639]::plumbing::__rust_begin_short_backtrace::<rustc_query_impl[f81b18394cfbf639]::query_impl::analysis::dynamic_query::{closure#2}::{closure#0}, rustc_middle[c72e907903e7d8bf]::query::erase::Erased<[u8; 0usize]>>
  30:     0x70f3b1b33dd5 - rustc_query_system[8aaaf029b136699]::query::plumbing::try_execute_query::<rustc_query_impl[f81b18394cfbf639]::DynamicConfig<rustc_query_system[8aaaf029b136699]::query::caches::SingleCache<rustc_middle[c72e907903e7d8bf]::query::erase::Erased<[u8; 0usize]>>, false, false, false>, rustc_query_impl[f81b18394cfbf639]::plumbing::QueryCtxt, false>
  31:     0x70f3b1b33b0e - rustc_query_impl[f81b18394cfbf639]::query_impl::analysis::get_query_non_incr::__rust_end_short_backtrace
  32:     0x70f3b1c7ad6e - rustc_interface[16ea6e92cdb33e83]::interface::run_compiler::<(), rustc_driver_impl[ca6f906ded399958]::run_compiler::{closure#0}>::{closure#1}
  33:     0x70f3b1abdb87 - std[c899b8b05f76e59a]::sys::backtrace::__rust_begin_short_backtrace::<rustc_interface[16ea6e92cdb33e83]::util::run_in_thread_with_globals<rustc_interface[16ea6e92cdb33e83]::util::run_in_thread_pool_with_globals<rustc_interface[16ea6e92cdb33e83]::interface::run_compiler<(), rustc_driver_impl[ca6f906ded399958]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>
  34:     0x70f3b1abe022 - <<std[c899b8b05f76e59a]::thread::Builder>::spawn_unchecked_<rustc_interface[16ea6e92cdb33e83]::util::run_in_thread_with_globals<rustc_interface[16ea6e92cdb33e83]::util::run_in_thread_pool_with_globals<rustc_interface[16ea6e92cdb33e83]::interface::run_compiler<(), rustc_driver_impl[ca6f906ded399958]::run_compiler::{closure#0}>::{closure#1}, ()>::{closure#0}, ()>::{closure#0}::{closure#0}, ()>::{closure#1} as core[232da84776abb8b3]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0}
  35:     0x70f3b1abf5ef - std::sys::pal::unix::thread::Thread::new::thread_start::h6b90422f5a6efa1e
  36:     0x70f3abe6a39d - <unknown>
  37:     0x70f3abeef49c - <unknown>
  38:                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 make sure that you have updated to the latest nightly

note: rustc 1.85.0-nightly (1b3fb3167 2024-12-09) running on x86_64-unknown-linux-gnu

query stack during panic:
#0 [lint_mod] linting top-level module
#1 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to 1 previous error


@rustbot label +F-unboxed_closures

@matthiaskrgr matthiaskrgr 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 Dec 9, 2024
@rustbot rustbot added needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. F-unboxed_closures `#![feature(unboxed_closures)]` labels Dec 9, 2024
@matthiaskrgr
Copy link
Member Author

bisects to #131669 cc @niacdoial

@Millione Millione mentioned this issue Dec 9, 2024
4 tasks
@jieyouxu jieyouxu marked this as a duplicate of #134059 Dec 9, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 9, 2024

Also (unminimized): #134059

@jieyouxu jieyouxu added L-improper_ctypes_definitions Lint: improper_ctypes_definitions S-has-bisection Status: a bisection has been found for this issue A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 9, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Dec 9, 2024

I'm going to post a revert of #131669 because I briefly looked at the logic; it's not very straightforward to fix, it impacts real-world crates like #134059, and this looks easy to hit. The changes can be relanded once these cases are addressed.

@niacdoial
Copy link
Contributor

I'll have to agree with the "easy to hit", I'm surprised the auto-reduced example is that simple while my changes passed the tests.
sorry for all the trouble...

jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 9, 2024
Revert <rust-lang#131669> due to ICE
reports:

- <rust-lang#134059> (real-world)
- <rust-lang#134060> (fuzzing)

The changes can be re-landed with those cases addressed.

This reverts commit 703bb98, reversing
changes made to f415c07.
jieyouxu added a commit to jieyouxu/rust that referenced this issue Dec 9, 2024
Mostly just to check that the lint impl doesn't ICE from an easy case.
@jieyouxu
Copy link
Member

jieyouxu commented Dec 9, 2024

I'll have to agree with the "easy to hit", I'm surprised the auto-reduced example is that simple while my changes passed the tests. sorry for all the trouble...

No worries, it happens! It looks tricky because there are a bunch of ty kinds that might be reachable to that bug!. I'm going with a revert here, so that there's no pressure on you (or anyone else) to immediately fix the ICE. No need to be sorry, you did include quite a few test changes in the PR, but there are just many corner cases.

bors added a commit to rust-lang-ci/rust that referenced this issue Dec 9, 2024
Revert rust-lang#131669 due to ICEs

Revert [lint: change help for pointers to dyn types in FFI rust-lang#131669](rust-lang#131669) due to ICE reports:

- <rust-lang#134059> (real-world)
- <rust-lang#134060> (fuzzing)

Closes rust-lang#134060.

The revert criteria I used to assess whether to post this revert was:

1. It's not trivial to fix-forward. (1) The implementation itself is tricky due to `tcx.is_sized` query not being very trivial. (2) It will need more extensive test coverage for different ty kinds.
2. It is impacting real-world crates, i.e. rust-lang#134059.
3. `improper_ctypes_definitions` is a warn-by-default lint.

This revert is without prejudice to relanding the changes. The changes can be re-landed with those cases addressed and stronger test coverage.

A rough regression test corresponding to the fuzzed example reported in rust-lang#134060 is added to check that the revert worked, it is not sufficient for the lint test coverage when the lint improvements are to be relanded. Please feel free to improve the test in the reland.

r? `@workingjubilee` (or compiler)
cc `@niacdoial` (PR author)
bors added a commit to rust-lang-ci/rust that referenced this issue Dec 9, 2024
Revert rust-lang#131669 due to ICEs

Revert [lint: change help for pointers to dyn types in FFI rust-lang#131669](rust-lang#131669) due to ICE reports:

- <rust-lang#134059> (real-world)
- <rust-lang#134060> (fuzzing)

Closes rust-lang#134060.

The revert criteria I used to assess whether to post this revert was:

1. It's not trivial to fix-forward. (1) The implementation itself is tricky due to `tcx.is_sized` query not being very trivial. (2) It will need more extensive test coverage for different ty kinds.
2. It is impacting real-world crates, i.e. rust-lang#134059.
3. `improper_ctypes_definitions` is a warn-by-default lint.

This revert is without prejudice to relanding the changes. The changes can be re-landed with those cases addressed and stronger test coverage.

A rough regression test corresponding to the fuzzed example reported in rust-lang#134060 is added to check that the revert worked, it is not sufficient for the lint test coverage when the lint improvements are to be relanded. Please feel free to improve the test in the reland.

r? `@workingjubilee` (or compiler)
cc `@niacdoial` (PR author)
@bors bors closed this as completed in a224f38 Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. C-bug Category: This is a bug. F-unboxed_closures `#![feature(unboxed_closures)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ L-improper_ctypes_definitions Lint: improper_ctypes_definitions S-has-bisection Status: a bisection has been found for this issue 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.

4 participants