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: "Unexpected tail in unsized_info_ty" when using impl Trait #37096

Closed
ghost opened this Issue Oct 11, 2016 · 6 comments

Comments

Projects
None yet
6 participants
@ghost
Copy link

ghost commented Oct 11, 2016

I was using impl Trait and the futures library when I got an ICE. I managed to reduce it to the following example:

edit: Updated example

#![feature(conservative_impl_trait)]

extern crate futures;

use futures::Future;

pub fn give_future() -> impl Future<Item=u32,Error=()> {
    futures::finished(1)
}

pub fn bug() {
    let fut1 = futures::finished(1);

    let fut2 = futures::finished(())
        .and_then(|_| {
            give_future()
        });

    fut1.join(fut2);
}
error: internal compiler error: ../src/librustc_trans/type_of.rs:154: Unexpected tail in unsized_info_ty: futures::join::MaybeDone<futures::AndThen<futures::Finished<(), ()>, futures::Finished<u32, ()>, [closure@src/lib.rs:15:19: 17:10]>> for ty=futures::join::MaybeDone<futures::AndThen<futures::Finished<(), ()>, futures::Finished<u32, ()>, [closure@src/lib.rs:15:19: 17:10]>>

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: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', ../src/librustc_errors/lib.rs:656
stack backtrace:
   1:     0x7f32fee74aef - std::sys::backtrace::tracing::imp::write::h22f199c1dbb72ba2
   2:     0x7f32fee8401d - std::panicking::default_hook::{{closure}}::h9a389c462b6a22dd
   3:     0x7f32fee81496 - std::panicking::default_hook::h852b4223c1c00c59
   4:     0x7f32fee81b78 - std::panicking::rust_panic_with_hook::hcd9d05f53fa0dafc
   5:     0x7f32fb2b8607 - std::panicking::begin_panic::h2f463d37998ebeba
   6:     0x7f32fb2c8768 - rustc_errors::Handler::bug::haca77c19c882b432
   7:     0x7f32fc31da9a - rustc::session::opt_span_bug_fmt::{{closure}}::hfeb850fbe828b399
   8:     0x7f32fc25cba5 - rustc::session::opt_span_bug_fmt::h46e45438a860a75e
   9:     0x7f32fc25c9e2 - rustc::session::bug_fmt::hde22f071bf5a80ea
  10:     0x7f32fdab3529 - rustc_trans::type_of::unsized_info_ty::h3691d330280e0b84
  11:     0x7f32fdab3cad - rustc_trans::type_of::in_memory_type_of::h125eed35c11bfd7e
  12:     0x7f32fdac15c6 - rustc_trans::abi::FnType::unadjusted::{{closure}}::h08a86fd257e9f006
  13:     0x7f32fda1d958 - rustc_trans::abi::FnType::unadjusted::h86a7b5168034e32a
  14:     0x7f32fda70629 - rustc_trans::declare::declare_fn::hd68e68443a787ee8
  15:     0x7f32fdaac871 - rustc_trans::trans_item::TransItem::predefine::hc4cd0f9fb130714e
  16:     0x7f32fda2eee0 - rustc_trans::base::trans_crate::h9b06de31ed8799d1
  17:     0x7f32ff209d4d - rustc_driver::driver::phase_4_translate_to_llvm::hc3883ea2c4750179
  18:     0x7f32ff244cf7 - rustc_driver::driver::compile_input::{{closure}}::h9162a2fa292aeb3f
  19:     0x7f32ff23bef3 - rustc_driver::driver::phase_3_run_analysis_passes::{{closure}}::h1928c4704cfe9c61
  20:     0x7f32ff2076ed - rustc_driver::driver::phase_3_run_analysis_passes::he578df6b8805151c
  21:     0x7f32ff1f3f69 - rustc_driver::driver::compile_input::h5b63ccd49eeeb98b
  22:     0x7f32ff21d2ba - rustc_driver::run_compiler::h98c7274e7cb1d11d
  23:     0x7f32ff156f0b - std::panicking::try::do_call::h99ed0da044e497c3
  24:     0x7f32fee8bf16 - __rust_maybe_catch_panic
  25:     0x7f32ff175461 - <F as alloc::boxed::FnBox<A>>::call_box::hbdd5a14cd8e33b97
  26:     0x7f32fee7fef0 - std::sys::thread::Thread::new::thread_start::h50b05608a499d2b2
  27:     0x7f32f71536f9 - start_thread
  28:     0x7f32feb43b5c - clone
  29:                0x0 - <unknown>

It happened on a ~week-old nightly version, and then on the latest version.

$ rustc --version --verbose
rustc 1.14.0-nightly (a3bc191b5 2016-10-10)
binary: rustc
commit-hash: a3bc191b5f41df5143cc65084b13999896411817
commit-date: 2016-10-10
host: x86_64-unknown-linux-gnu
release: 1.14.0-nightly

@apasel422 apasel422 added the I-ICE label Oct 11, 2016

@TimNN

This comment has been minimized.

Copy link
Contributor

TimNN commented Oct 12, 2016

I assume this is (once again) a duplicate of #16812.

@ghost

This comment has been minimized.

Copy link
Author

ghost commented Oct 12, 2016

Sorry for the duplicate, I did a quick search on (open) issues with pieces of the error message and it didn't bring anything ...

However, all issues linked with #16812 look related to unsized types. Are impl Trait or unboxed closures considered unsized types?

I edited the example to remove the .boxed() and BoxFuture, and it still ICE.

@TimNN

This comment has been minimized.

Copy link
Contributor

TimNN commented Oct 12, 2016

However, all issues linked with #16812 look related to unsized types. Are impl Trait or unboxed closures considered unsized types?

I'm not sure where the the unsized type comes from, however the MaybeDone enum does have a variant which just contains a T: Future which may be unsized.

And don't worry too much about the duplicate, it's great that you did search for open issues and it also gives a bit of a feel for how often certain issues occur.

@novacrazy

This comment has been minimized.

Copy link

novacrazy commented Jan 13, 2017

I just ran into this exact ICE again with futures-rs, with impl Trait and the future-rs .join combinators used on the impl Trait types. If I change the impl Trait into Box<Trait> it works fine.

If it can help, I did get another ICE when I try to box the impl Trait and the Join combinator. I thought that might help somehow to do that, but nope. Here is where I encountered the ICE while testing an event emitter thing I'm working on.

It might be related to #35988, but it might be worth noting since it can be triggered on MaybeDone

fn test_pooled_emit() {
    let mut emitter = PooledEventEmitter::new();

    emitter.add_listener("test", box || {
        thread::sleep_ms(1000);
        println!("Thread: {}", thread_id::get());
        Ok(())
    }).unwrap();

    emitter.add_listener_value::<i32, _>("test", box |arg| {
        println!("Thread: {}, {:?}", thread_id::get(), arg);
        Ok(())
    }).unwrap();

    emitter.add_listener_value::<&str, _>("test", box |arg| {
        println!("Thread: {}, {:?}", thread_id::get(), arg);
        Ok(())
    }).unwrap();

    let a = box emitter.emit("test");
    let b = box emitter.emit_value("test", 10);
    let c = box emitter.emit_value("test", "test");

    let all = box a.join3(b, c);

    assert_eq!(all.wait().unwrap(), (3, 3, 3));
}

I can't replicate it with something simpler so far, but here is the error generated from the above code:

error: internal compiler error: C:\bot\slave\nightly-dist-rustc-win-msvc-64\build\src\librustc_trans\context.rs:859: failed to get layout for `futures::task::Spawn<Box<futures::Join3<Box<futures::Flatten<futures_cpupool::CpuFuture<futures::stream::Fold<futures:
:stream::Flatten<futures::stream::Map<futures::stream::IterStream<Box<std::iter::Iterator<Item=std::result::Result<std::sync::Arc<events::event_emitter::parallel::SyncEventListener>, common::error::Trace<events::event_emitter::EventError>>> + std::marker::Send>
>, [closure@DefId { krate: CrateNum(67), node: DefIndex(130) => combustion_events/30a12d9603e592ce7f4410f2882f7033::event_emitter[0]::parallel[0]::{{impl}}[5]::emit[0]::do_spawn[0]::{{closure}}[1] } 0:std::sync::Arc<events::event_emitter::parallel::Inner>]>>, [
closure@DefId { krate: CrateNum(67), node: DefIndex(141) => combustion_events/30a12d9603e592ce7f4410f2882f7033::event_emitter[0]::parallel[0]::{{impl}}[5]::emit[0]::{{closure}}[0]::{{closure}}[0]::{{closure}}[0] }], std::result::Result<usize, common::error::Tra
ce<events::event_emitter::EventError>>, usize>, common::error::Trace<events::event_emitter::EventError>>>>, Box<futures::Flatten<futures_cpupool::CpuFuture<futures::stream::Fold<futures::stream::Flatten<futures::stream::Map<futures::stream::IterStream<Box<std::
iter::Iterator<Item=std::result::Result<(Box<i32>, std::sync::Arc<events::event_emitter::parallel::SyncEventListener>), common::error::Trace<events::event_emitter::EventError>>> + std::marker::Send>>, [closure@DefId { krate: CrateNum(67), node: DefIndex(163) =>
 combustion_events/30a12d9603e592ce7f4410f2882f7033::event_emitter[0]::parallel[0]::{{impl}}[5]::emit_value[0]::do_spawn[0]::{{closure}}[1] } 0:std::sync::Arc<events::event_emitter::parallel::Inner>]>>, [closure@DefId { krate: CrateNum(67), node: DefIndex(177)
=> combustion_events/30a12d9603e592ce7f4410f2882f7033::event_emitter[0]::parallel[0]::{{impl}}[5]::emit_value[0]::{{closure}}[0]::{{closure}}[0]::{{closure}}[0] }], std::result::Result<usize, common::error::Trace<events::event_emitter::EventError>>, usize>, com
mon::error::Trace<events::event_emitter::EventError>>>>, Box<futures::Flatten<futures_cpupool::CpuFuture<futures::stream::Fold<futures::stream::Flatten<futures::stream::Map<futures::stream::IterStream<Box<std::iter::Iterator<Item=std::result::Result<(Box<&str>,
 std::sync::Arc<events::event_emitter::parallel::SyncEventListener>), common::error::Trace<events::event_emitter::EventError>>> + std::marker::Send>>, [closure@DefId { krate: CrateNum(67), node: DefIndex(163) => combustion_events/30a12d9603e592ce7f4410f2882f703
3::event_emitter[0]::parallel[0]::{{impl}}[5]::emit_value[0]::do_spawn[0]::{{closure}}[1] } 0:std::sync::Arc<events::event_emitter::parallel::Inner>]>>, [closure@DefId { krate: CrateNum(67), node: DefIndex(177) => combustion_events/30a12d9603e592ce7f4410f2882f7
033::event_emitter[0]::parallel[0]::{{impl}}[5]::emit_value[0]::{{closure}}[0]::{{closure}}[0]::{{closure}}[0] }], std::result::Result<usize, common::error::Trace<events::event_emitter::EventError>>, usize>, common::error::Trace<events::event_emitter::EventErro
r>>>>>>>`: the type `futures::future::join::MaybeDone<Box<futures::Flatten<futures_cpupool::CpuFuture<futures::stream::Fold<futures::stream::Flatten<futures::stream::Map<futures::stream::IterStream<Box<std::iter::Iterator<Item=std::result::Result<(Box<&str>, st
d::sync::Arc<events::event_emitter::parallel::SyncEventListener>), common::error::Trace<events::event_emitter::EventError>>> + std::marker::Send>>, [closure@DefId { krate: CrateNum(67), node: DefIndex(163) => combustion_events/30a12d9603e592ce7f4410f2882f7033::
event_emitter[0]::parallel[0]::{{impl}}[5]::emit_value[0]::do_spawn[0]::{{closure}}[1] } 0:std::sync::Arc<events::event_emitter::parallel::Inner>]>>, [closure@DefId { krate: CrateNum(67), node: DefIndex(177) => combustion_events/30a12d9603e592ce7f4410f2882f7033
::event_emitter[0]::parallel[0]::{{impl}}[5]::emit_value[0]::{{closure}}[0]::{{closure}}[0]::{{closure}}[0] }], std::result::Result<usize, common::error::Trace<events::event_emitter::EventError>>, usize>, common::error::Trace<events::event_emitter::EventError>>
>>>` has an unknown layout

Here is the backtrace:

thread 'rustc' panicked at 'Box<Any>', C:\bot\slave\nightly-dist-rustc-win-msvc-64\build\src\librustc_errors\lib.rs:423
stack backtrace:
   0:     0x7ffd4f0dff30 - std::panicking::Location::line::h8c528bbdf4eef8a3
   1:     0x7ffd4f0df3b2 - std::panicking::Location::line::h8c528bbdf4eef8a3
   2:     0x7ffd4f0e2dfd - std::panicking::rust_panic_with_hook::h7abc6e334345e341
   3:     0x7ffd5c1429ea - <unknown>
   4:     0x7ffd5c15db8e - rustc_errors::Handler::bug::hbd513abe0d1e3f18
   5:     0x7ffd4e3cd065 - rustc::session::bug_fmt::hcff0bf8ae86d3c88
   6:     0x7ffd4e3cca72 - rustc::session::bug_fmt::hcff0bf8ae86d3c88
   7:     0x7ffd4e3cc18c - rustc::session::bug_fmt::hcff0bf8ae86d3c88
   8:     0x7ffd4eebc6f8 - rustc_trans::context::CrateContext::layout_of::he1b6401d700095e0
   9:     0x7ffd4ee794b2 - rustc_trans::abi::FnType::apply_attrs_callsite::h73e6feb1527ce239
  10:     0x7ffd4ef25f4c - rustc_trans::type_::Type::from_primitive::h9e7efe5b450d9e05
  11:     0x7ffd4ef25e46 - rustc_trans::type_::Type::from_primitive::h9e7efe5b450d9e05
  12:     0x7ffd4ee74ff3 - rustc_trans::abi::FnType::unadjusted::h9efa81225506b54d
  13:     0x7ffd4ee745ab - rustc_trans::abi::FnType::unadjusted::h9efa81225506b54d
  14:     0x7ffd4eeda76f - rustc_trans::debuginfo::CrateDebugContext::new::h155d50bc9ace152f
  15:     0x7ffd4ef1ebdd - rustc_trans::trans_item::TransItem::predefine::h059b29bceadef9e0
  16:     0x7ffd4ee845a0 - rustc_trans::base::trans_crate::h7630c9da869079ce
  17:     0x7ffd61efa922 - rustc_driver::driver::phase_4_translate_to_llvm::h7a1e00c44f844853
  18:     0x7ffd61ecbe45 - rustc_driver::driver::compile_input::h44e43be0fc34a1a1
  19:     0x7ffd61ef04ff - rustc_driver::driver::count_nodes::h761a1dba824a4f1e
  20:     0x7ffd61e2c51b - <unknown>
  21:     0x7ffd61ec7f4c - rustc_driver::driver::compile_input::h44e43be0fc34a1a1
  22:     0x7ffd61f19917 - rustc_driver::run_compiler::h5e34a930c0929e5c
  23:     0x7ffd61def0de - <unknown>
  24:     0x7ffd4f0e5e31 - _rust_maybe_catch_panic
  25:     0x7ffd61e1dec6 - <unknown>
  26:     0x7ffd4f0dd42e - std::sys::imp::thread::Thread::new::h7a1b2b1b6bab390a
  27:     0x7ffd92828363 - BaseThreadInitThunk
@novacrazy

This comment has been minimized.

Copy link

novacrazy commented Jan 13, 2017

I refactored my code to remove a locally defined function with its own impl Trait return, and the ICE is gone now. That kind of leads me to believe closures and/or locally defined functions with automatic return types or impl Trait return types might have something to do with this.

@cramertj

This comment has been minimized.

Copy link
Member

cramertj commented Jan 5, 2018

This has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment