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

Normalizing <T as Trait>::AssocType in a union causes an ICE #81199

Closed
guswynn opened this issue Jan 19, 2021 · 7 comments
Closed

Normalizing <T as Trait>::AssocType in a union causes an ICE #81199

guswynn opened this issue Jan 19, 2021 · 7 comments
Assignees
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.

Comments

@guswynn
Copy link
Contributor

guswynn commented Jan 19, 2021

https://github.com/rust-lang/rust/pull/81172/files
was reading this and trying to test how unions work with generics, and got an ICE

removing the union causes the ICE to NOT trigger

Code

#[repr(C)]
union PtrRepr<T: ?Sized> {
    const_ptr: *const T,
    mut_ptr: *mut T,
    components: PtrComponents<T>,
}

#[repr(C)]
struct PtrComponents<T: Pointee + ?Sized> {
    data_address: *const (),
    metadata: <T as Pointee>::Metadata,
}



pub trait Pointee {
   type Metadata;
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=b3888d392c9bf1a2ee1bf1cfb961b84b

Meta

rustc --version --verbose:

1.49 (playground

Error output

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:958:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

note: 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: rustc 1.49.0 (e1884a8e3 2020-12-29) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<T as Pointee>::Metadata`
#1 [needs_drop_raw] computing whether `PtrComponents<T>` needs drop
end of query stack
error: aborting due to previous error

error: could not compile `playground`

To learn more, run the command again with --verbose.

Backtrace

thread 'rustc' panicked at 'Box<Any>', compiler/rustc_errors/src/lib.rs:958:9
stack backtrace:
   0: std::panicking::begin_panic
   1: rustc_errors::HandlerInner::bug
   2: rustc_errors::Handler::bug
   3: rustc_middle::util::bug::opt_span_bug_fmt::{{closure}}
   4: rustc_middle::ty::context::tls::with_opt::{{closure}}
   5: rustc_middle::ty::context::tls::with_opt
   6: rustc_middle::util::bug::opt_span_bug_fmt
   7: rustc_middle::util::bug::bug_fmt
   8: rustc_infer::infer::InferCtxtBuilder::enter
   9: rustc_traits::normalize_erasing_regions::normalize_generic_arg_after_erasing_regions
  10: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  11: rustc_data_structures::stack::ensure_sufficient_stack
  12: rustc_query_system::query::plumbing::get_query_impl
  13: <rustc_middle::ty::normalize_erasing_regions::NormalizeAfterErasingRegionsFolder as rustc_middle::ty::fold::TypeFolder>::fold_ty
  14: rustc_ty::needs_drop::needs_drop_raw
  15: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::needs_drop_raw>::compute
  16: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  17: rustc_data_structures::stack::ensure_sufficient_stack
  18: rustc_query_system::query::plumbing::get_query_impl
  19: <rustc_passes::stability::Checker as rustc_hir::intravisit::Visitor>::visit_item
  20: rustc_middle::hir::map::Map::visit_item_likes_in_module
  21: rustc_passes::stability::check_mod_unstable_api_usage
  22: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::check_mod_unstable_api_usage>::compute
  23: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  24: rustc_data_structures::stack::ensure_sufficient_stack
  25: rustc_query_system::query::plumbing::get_query_impl
  26: rustc_query_system::query::plumbing::ensure_query_impl
  27: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
  28: rustc_session::utils::<impl rustc_session::session::Session>::time
  29: rustc_interface::passes::analysis
  30: rustc_middle::ty::query::<impl rustc_query_system::query::config::QueryAccessors<rustc_middle::ty::context::TyCtxt> for rustc_middle::ty::query::queries::analysis>::compute
  31: rustc_query_system::dep_graph::graph::DepGraph<K>::with_task_impl
  32: rustc_data_structures::stack::ensure_sufficient_stack
  33: rustc_query_system::query::plumbing::get_query_impl
  34: rustc_interface::passes::QueryContext::enter
  35: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  36: rustc_span::with_source_map
  37: rustc_interface::interface::create_compiler_and_run
  38: rustc_span::with_session_globals
@guswynn guswynn 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 Jan 19, 2021
@guswynn
Copy link
Contributor Author

guswynn commented Jan 19, 2021

Minimization:

union PtrRepr<T: ?Sized> {
    const_ptr: *const T,
    mut_ptr: *mut T,
    components: <T as Pointee>::Metadata
}

pub trait Pointee {
    type Metadata;
}

ICE's

and

union PtrRepr<T: Pointee + ?Sized> {
    const_ptr: *const T,
    mut_ptr: *mut T,
    components: <T as Pointee>::Metadata
}

pub trait Pointee {
    type Metadata;
}

Errors with a unions may not contain fields that need dropping

@guswynn
Copy link
Contributor Author

guswynn commented Jan 19, 2021

@jyn514 jyn514 added the A-associated-items Area: Associated items (types, constants & functions) label Jan 20, 2021
@YangKeao
Copy link

YangKeao commented Jan 20, 2021

I have run cargo bisect between 2020-07-01 and 2020-12-29 and found that this regression was brought by e3051d8

Here are more information:

error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:43:32: could not fully normalize `<T as Pointee>::Metadata` 

query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<T as Pointee>::Metadata`
#1 [check_mod_unstable_api_usage] checking for unstable API usage in top-level module
#2 [analysis] running analysis passes on this crate
end of query stack
error: aborting due to previous error

When the generic parameter has enough constraints, e.g.

pub trait Pointee {
   type Metadata;
}

// minimization
union PtrRepr<T: Pointee> {
    components: <T as Pointee>::Metadata,
}

This error disappears.

@guswynn
Copy link
Contributor Author

guswynn commented Jan 20, 2021

@guswynn
Copy link
Contributor Author

guswynn commented Jan 20, 2021

Yeah with the code "fixed" with the constraint it disappears, ideally rustc would tell the user that (like it does in the struct case i think I linked above), and not ICE

@YangKeao
Copy link

YangKeao commented Jan 21, 2021

@YangKeao was it this PR? https://github.com/rust-lang/rust/pull/77547/files

Yes. It calls normalize_erasing_regions before the type-check, which will cause ICE. A quick fix could be delaying the union unstable api check until the end of type-check, but I don't know where is the most suitable place for the check 😿

@camelid
Copy link
Member

camelid commented Jul 24, 2021

Minimization from #87327 (comment):

union U {
    a: <Self as Iterator>::Item,
}

estebank added a commit to estebank/rust that referenced this issue Aug 25, 2021
When normalizing `union`s with fields coming from associated types that
don't satisfy trait bounds, avoid ICEing by using `delay_span_bug()`
instead of `bug!()`.

Fix rust-lang#81199.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 3, 2021
…egions, r=jackh726

Use try_normalize_erasing_regions in needs_drop

Fixes rust-lang#81199

r? `@jackh726`
@bors bors closed this as completed in f056f0d Dec 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. glacier ICE tracked in rust-lang/glacier. 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.
Projects
None yet
6 participants