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 on associated type violating its bounds in a blanket impl #54108

Closed
askeksa opened this issue Sep 10, 2018 · 7 comments · Fixed by #77741
Closed

ICE on associated type violating its bounds in a blanket impl #54108

askeksa opened this issue Sep 10, 2018 · 7 comments · Fixed by #77741
Labels
A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@askeksa
Copy link

askeksa commented Sep 10, 2018

When I give this code to rustc:

use std::ops::Add;

pub trait Encoder {
	type Size: Add<Output = Self::Size>;

	fn foo(&self) -> Self::Size;
}

pub trait SubEncoder : Encoder {
	type ActualSize;

	fn bar(&self) -> Self::Size;
}

impl<T> Encoder for T where T: SubEncoder {
	type Size = <Self as SubEncoder>::ActualSize;

	fn foo(&self) -> Self::Size {
		self.bar() + self.bar()
	}
}

pub struct UnitEncoder;

impl SubEncoder for UnitEncoder {
	type ActualSize = ();

	fn bar(&self) {}
}


fn main() {
	fun(&UnitEncoder {});
}

pub fn fun<R: Encoder>(encoder: &R) {
	encoder.foo();
}

I get this output:

error: internal compiler error: librustc\traits\codegen\mod.rs:68: Encountered error `Unimplemented` selecting `Binder(<() as std::ops::Add>)` during codegen

thread 'main' panicked at 'Box<Any>', librustc_errors\lib.rs:554:9
stack backtrace:
   0: <std::sync::mpsc::select::Select as core::fmt::Debug>::fmt
   1: std::stdsimd::arch::detect::os::check_for
   2: std::panicking::take_hook
   3: std::panicking::take_hook
   4: <rustc::ty::query::on_disk_cache::CacheEncoder<'enc, 'a, 'tcx, serialize::opaque::Encoder<'enc>> as serialize::serialize::SpecializedEncoder<rustc::ich::fingerprint::Fingerprint>>::specialized_encode
   5: std::panicking::rust_panic_with_hook
   6: <rustc_errors::emitter::ColorConfig as core::fmt::Debug>::fmt
   7: rustc_errors::Handler::bug
   8: <rustc::hir::map::MapEntry<'hir> as core::clone::Clone>::clone
   9: rustc::ty::context::tls::track_diagnostic
  10: rustc::ty::context::tls::track_diagnostic
  11: rustc::ty::context::tls::track_diagnostic
  12: rustc::session::bug_fmt
  13: rustc::session::bug_fmt
  14: rustc::ty::context::tls::track_diagnostic
  15: rustc::traits::codegen::codegen_fulfill_obligation
  16: rustc::ty::query::on_disk_cache::__ty_decoder_impl::<impl serialize::serialize::Decoder for rustc::ty::query::on_disk_cache::CacheDecoder<'a, 'tcx, 'x>>::read_str
  17: rustc::ty::context::tls::track_diagnostic
  18: rustc::dep_graph::graph::DepGraph::assert_ignored
  19: rustc::ty::context::tls::track_diagnostic
  20: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  21: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  22: rustc::ty::instance::Instance::resolve
  23: <rustc_mir::monomorphize::collector::MirNeighborCollector<'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_terminator_kind
  24: rustc_mir::monomorphize::collector::collect_crate_mono_items
  25: rustc_mir::monomorphize::collector::collect_crate_mono_items
  26: rustc_mir::monomorphize::collector::collect_crate_mono_items
  27: rustc_mir::monomorphize::collector::collect_crate_mono_items
  28: rustc_mir::monomorphize::collector::collect_crate_mono_items
  29: <rustc_codegen_llvm::time_graph::TimelineId as core::fmt::Debug>::fmt
  30: <rustc_codegen_llvm::base::ValueIter as core::iter::iterator::Iterator>::next
  31: rustc::ty::context::tls::track_diagnostic
  32: rustc::dep_graph::graph::DepGraph::assert_ignored
  33: rustc::ty::context::tls::track_diagnostic
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  35: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_print_query_stack
  36: <rustc_codegen_llvm::base::ValueIter as core::iter::iterator::Iterator>::next
  37: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_utils::codegen_backend::CodegenBackend>::codegen_crate
  38: rustc_driver::driver::build_output_filenames
  39: rustc_driver::driver::phase_4_codegen
  40: rustc_driver::profile::dump
  41: <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_impl_item
  42: <rustc_driver::pretty::IdentifiedAnnotation<'hir> as rustc_driver::pretty::PrinterSupport>::sess
  43: <unknown>
  44: rustc_driver::driver::compile_input
  45: rustc_driver::run_compiler
  46: rustc_driver::target_features::add_configuration
  47: <rustc_driver::pretty::IdentifiedAnnotation<'hir> as rustc_driver::pretty::PrinterSupport>::sess
  48: _rust_maybe_catch_panic
  49: <rustc_driver::derive_registrar::Finder as rustc::hir::itemlikevisit::ItemLikeVisitor<'v>>::visit_item
  50: rustc_driver::main
  51: <unknown>
  52: std::panicking::update_panic_count
  53: _rust_maybe_catch_panic
  54: std::rt::lang_start_internal
  55: <unknown>
  56: <unknown>
  57: BaseThreadInitThunk
  58: RtlUserThreadStart
query stack during panic:
#0 [codegen_fulfill_obligation] checking if `std::ops::Add` fulfills its obligations
#1 [collect_and_partition_mono_items] collect_and_partition_mono_items
end of query stack
error: aborting due to previous error


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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.28.0 (9634041f0 2018-07-30) running on x86_64-pc-windows-msvc

(The same crash occurs with rustc 1.30.0-nightly (2d4e34ca8 2018-09-09).)

It seems the line

	type Size = <Self as SubEncoder>::ActualSize;

should have resulted in an error stating that the trait bounds for Size are not fulfilled, but no such error was generated, and the subsequent use of + on an expression of type Size with Size as a type not implementing Add caused the compiler to panic.

@memoryruins memoryruins added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 11, 2018
@jonas-schievink jonas-schievink added A-associated-items Area: Associated items (types, constants & functions) C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-nominated labels Aug 6, 2019
@jonas-schievink
Copy link
Contributor

Triage: Still reproduces on current stable and nightly. Also seems like this could be some potential unsoundness.

@nagisa nagisa added P-high High priority and removed I-nominated labels Aug 8, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Sep 19, 2019

@jonas-schievink the potential unsoundness that you posited above: is that based on the part of the description stating that they think type Size = <Self as SubEncoder>::ActualSize; should have caused errors due to trait bounds on Size being unfulfilled?

Or is it something else that caused you to note that?

Because I'll just post a reminder that under the current rustc, we don't check trait bounds eagerly; cc #51626

@pnkfelix
Copy link
Member

(in other words, #51626 type stuff should not be a source of unsoundness.)

@pnkfelix
Copy link
Member

((I'm tempted to downgrade this (#54108) to P-medium, but I'll wait until I see a response from @jonas-schievink before I make any decision there.))

@jonas-schievink
Copy link
Contributor

@jonas-schievink then potential unsoundness that you posited above: is that based on the part of the description stating that they think type Size = <Self as SubEncoder>::ActualSize; should have caused errors due to trait bounds on Size being unfulfilled?

Yeah, instead of getting an Unimplemented error during codegen. I agree with making this P-medium unless someone manages to cause actual unsoundness with this.

@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Oct 15, 2019
@pnkfelix
Copy link
Member

triage: Downgrading to P-medium until someone can demonstrate actual unsoundness.

@pnkfelix pnkfelix added P-medium Medium priority and removed P-high High priority labels Nov 14, 2019
@pnkfelix pnkfelix changed the title Compiler crash on associated type violating its bounds in a blanket impl ICE on associated type violating its bounds in a blanket impl Nov 14, 2019
@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 7, 2020
@JohnTitor
Copy link
Member

Triage: This is no longer ICE with the latest nightly, marking as E-needs-test.

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. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority 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.

7 participants