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: upvar_tys called before capture types are inferred in rustc_type_ir/src/ty_kind/closure.rs #125881

Closed
cushionbadak opened this issue Jun 2, 2024 · 9 comments
Labels
A-closures Area: Closures (`|…| { … }`) C-bug Category: This is a bug. F-const_trait_impl `#![feature(const_trait_impl)]` F-effects `#![feature(effects)]` F-transmutability `#![feature(transmutability)]` F-unboxed_closures `#![feature(unboxed_closures)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@cushionbadak
Copy link

Code

(hand reduced & simplified)

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

const fn test() -> impl std::mem::BikeshedIntrinsicFrom() {
    || {}
}
original code

#![feature(transmutability)]

pub fn is_maybe_transmutable<Dst>()
where
    Dst: std::mem::BikeshedIntrinsicFrom<(), ()>,
{
}

fn should_pad_explicitly_aligned_field() {
    #[repr(packed, align(0x100))]
    #[repr(u8)]
    enum V0u8 {
        V,
    }

    is_maybe_transmutable::<V0u8>();
}

fn main() {}


#![feature(const_trait_impl)]

const fn test() -> impl ~const std::mem::BikeshedIntrinsicFrom() {
    const move || {
        let sl: &[u8] = b"foo";

        match sl {
            [first, remainder @ ..] => {
                assert_eq!(first, &b'f');
            }
            [] => panic!(),
        }
    }
}

Meta

rustc --version --verbose:

rustc 1.80.0-nightly (f67a1acc0 2024-06-01)
binary: rustc
commit-hash: f67a1acc04c7ecbf05751b17592dd8d245b75256
commit-date: 2024-06-01
host: aarch64-apple-darwin
release: 1.80.0-nightly
LLVM version: 18.1.6

Error output

Command: rustc -Zcrate-attr="feature(effects)"

error[E0220]: associated type `Output` not found for `BikeshedIntrinsicFrom`
 --> r_sty_1331FC.rs:5:35
  |
5 | const fn test() -> impl std::mem::BikeshedIntrinsicFrom() {
  |                                   ^^^^^^^^^^^^^^^^^^^^^^^ associated type `Output` not found
Backtrace

thread 'rustc' panicked at /rustc/f67a1acc04c7ecbf05751b17592dd8d245b75256/compiler/rustc_type_ir/src/ty_kind/closure.rs:168:29:
upvar_tys called before capture types are inferred
stack backtrace:
   0: _rust_begin_unwind
   1: core::panicking::panic_fmt
   2: rustc_ty_utils::layout::layout_of_uncached
   3: rustc_ty_utils::layout::layout_of
      [... omitted 2 frames ...]
   4: <rustc_transmute::maybe_transmutable::MaybeTransmutableQuery<rustc_middle::ty::Ty, rustc_middle::ty::context::TyCtxt>>::answer::{closure#0}
   5: <rustc_transmute::maybe_transmutable::MaybeTransmutableQuery<rustc_middle::ty::Ty, rustc_middle::ty::context::TyCtxt>>::answer
   6: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt>::get_safe_transmute_error_and_reason
   7: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::TypeErrCtxtExt>::report_selection_error
   8: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::InferCtxtPrivExt>::report_fulfillment_error
   9: <rustc_infer::infer::error_reporting::TypeErrCtxt as rustc_trait_selection::traits::error_reporting::type_err_ctxt_ext::TypeErrCtxtExt>::report_fulfillment_errors
  10: <rustc_hir_typeck::fn_ctxt::FnCtxt>::resolve_vars_with_obligations
  11: <rustc_hir_typeck::fn_ctxt::FnCtxt>::try_structurally_resolve_type
  12: <rustc_hir_typeck::fn_ctxt::FnCtxt>::coerce
  13: <rustc_hir_typeck::coercion::CoerceMany<&rustc_hir::hir::Expr>>::coerce_inner::<<rustc_hir_typeck::fn_ctxt::FnCtxt>::check_expr_return::{closure#1}>
  14: <rustc_hir_typeck::fn_ctxt::FnCtxt>::check_return_expr
  15: rustc_hir_typeck::check::check_fn
  16: rustc_hir_typeck::typeck
      [... omitted 2 frames ...]
  17: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::VecCache<rustc_span::def_id::LocalDefId, rustc_middle::query::erase::Erased<[u8; 8]>>>
  18: rustc_hir_analysis::collect::type_of::opaque::find_opaque_ty_constraints_for_rpit
      [... omitted 2 frames ...]
  19: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
  20: rustc_hir_analysis::collect::type_of::type_of
      [... omitted 2 frames ...]
  21: rustc_middle::query::plumbing::query_get_at::<rustc_query_system::query::caches::DefIdCache<rustc_middle::query::erase::Erased<[u8; 8]>>>
  22: rustc_hir_analysis::check::check::check_item_type
  23: rustc_hir_analysis::check::wfcheck::check_well_formed
      [... omitted 2 frames ...]
  24: rustc_middle::query::plumbing::query_ensure_error_guaranteed::<rustc_query_system::query::caches::VecCache<rustc_hir::hir_id::OwnerId, rustc_middle::query::erase::Erased<[u8; 1]>>, ()>
  25: <rustc_middle::hir::ModuleItems>::par_items::<rustc_hir_analysis::check::wfcheck::check_mod_type_wf::{closure#0}>
  26: rustc_hir_analysis::check::wfcheck::check_mod_type_wf
      [... omitted 2 frames ...]
  27: <rustc_session::session::Session>::time::<(), rustc_hir_analysis::check_crate::{closure#1}>
  28: rustc_hir_analysis::check_crate
  29: rustc_interface::passes::analysis
      [... omitted 2 frames ...]
  30: <rustc_interface::queries::QueryResult<&rustc_middle::ty::context::GlobalCtxt>>::enter::<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}::{closure#1}::{closure#3}>
  31: <rustc_interface::interface::Compiler>::enter::<rustc_driver_impl::run_compiler::{closure#0}::{closure#1}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_span::ErrorGuaranteed>>
  32: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::run_in_thread_with_globals<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_span::ErrorGuaranteed>, rustc_driver_impl::run_compiler::{closure#0}>::{closure#1}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, core::result::Result<(), rustc_span::ErrorGuaranteed>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: the compiler unexpectedly panicked. this is a bug.

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: please attach the file at `/Users/jisukbyun/workspace/240601_100chaos_tree_combine_typ/icefiles/rustc-ice-2024-06-02T07_07_30-17637.txt` to your bug report

note: compiler flags: -Z crate-attr=feature(effects)

query stack during panic:
panicked at /rustc/f67a1acc04c7ecbf05751b17592dd8d245b75256/compiler/rustc_type_ir/src/ty_kind.rs:856:17:
thread panicked while processing panic. aborting.
[1]    17637 abort      rustc r_sty_1331FC.rs -Zcrate-attr="feature(effects)"

Note

  • ICE location: rustc_type_ir/src/ty_kind/closure.rs L168
    pub fn upvar_tys(self) -> I::Tys {
    match self.tupled_upvars_ty().kind() {
    ty::Error(_) => Default::default(),
    ty::Tuple(tys) => tys,
    ty::Infer(_) => panic!("upvar_tys called before capture types are inferred"),
    ty => panic!("Unexpected representation of upvar types tuple {:?}", ty),
    }
    }
  • As shown in the backtrace, it panicked while printing the query stack.
@cushionbadak cushionbadak 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 Jun 2, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 2, 2024
@lqd lqd added requires-nightly This issue requires a nightly compiler in some way. F-unboxed_closures `#![feature(unboxed_closures)]` F-effects `#![feature(effects)]` F-transmutability `#![feature(transmutability)]` and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Jun 2, 2024
@lqd
Copy link
Member

lqd commented Jun 2, 2024

Since you seem to be fuzzing and opening a lot of issues (thanks!), please also add F-labels for every feature used in your repro so that triagers have less work to do to make the issue discoverable.

Thanks in advance

@lqd lqd added the A-closures Area: Closures (`|…| { … }`) label Jun 2, 2024
@cushionbadak
Copy link
Author

Thanks for your advice, but I'm unsure how to modify label on my issue. I can't see a gear icon next to the label lists when creating or viewing an issue.
Perhaps label editing is available only to members of the Rust project, I guess.

@lqd
Copy link
Member

lqd commented Jun 2, 2024

Ah there’s a bot for that for everybody. I don’t have a link to the docs at the ready but you can use the bot for almost all labels, like @rustbot label -A-closures +A-closures

@rustbot rustbot removed the A-closures Area: Closures (`|…| { … }`) label Jun 2, 2024
@lqd
Copy link
Member

lqd commented Jun 2, 2024

The A- ones are a bit more internal to find from just a repro, but the F- features one are straightforward

@rustbot label +A-closures

@rustbot

This comment was marked as outdated.

@rustbot rustbot added the A-closures Area: Closures (`|…| { … }`) label Jun 2, 2024
@cushionbadak
Copy link
Author

Oh, I can use rustbot! I always wondered whether rustbot is available to everyone or not. Thanks!

@matthiaskrgr matthiaskrgr added the S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. label Jun 9, 2024
@cushionbadak
Copy link
Author

cushionbadak commented Jun 12, 2024

Regression in rust-lang-ci@d48eec5
The PR introducing the regression in this rollup is #123367: Safe Transmute: Compute transmutability from `rustc_target:…

searched nightlies: from nightly-2023-01-01 to nightly-2024-05-30
regressed nightly: nightly-2024-04-09
searched commit range: 9d5cdf7...ab5bda1
regressed commit: ab5bda1

bisected with cargo-bisect-rustc v0.6.8

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start=2023-01-01 --end=2024-05-30 --regress=ice --script=rustc --preserve -- 125881.rs -Zcrate-attr=feature(effects)

@jswrenn
Copy link
Member

jswrenn commented Oct 17, 2024

This was fixed in #131112.

@fmease fmease added the F-const_trait_impl `#![feature(const_trait_impl)]` label Nov 15, 2024
@fmease
Copy link
Member

fmease commented Nov 15, 2024

Closing as such.

@fmease fmease closed this as completed Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) C-bug Category: This is a bug. F-const_trait_impl `#![feature(const_trait_impl)]` F-effects `#![feature(effects)]` F-transmutability `#![feature(transmutability)]` F-unboxed_closures `#![feature(unboxed_closures)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. S-bug-has-test Status: This bug is tracked inside the repo by a `known-bug` test. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants