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

Cannot create local mono-item #48751

Closed
alecmocatta opened this issue Mar 5, 2018 · 8 comments
Closed

Cannot create local mono-item #48751

alecmocatta opened this issue Mar 5, 2018 · 8 comments
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@alecmocatta
Copy link
Contributor

alecmocatta commented Mar 5, 2018

I'm getting the following ICE on at least various nightlies going back a month.

error: internal compiler error: librustc_mir/monomorphize/collector.rs:747: Cannot create local mono-item for DefId(18/0:171 ~ my_lib_crate[8418]::my_lib_submod[0]::{{impl}}[18]::new[0])

thread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:535:9
stack backtrace:
   0:     0x7f1f4999ee83 - std::sys::unix::backtrace::tracing::imp::unwind_backtrace::h06394d49c249a4bb
                               at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1:     0x7f1f49995d64 - std::sys_common::backtrace::_print::h9b103b13339f9058
                               at libstd/sys_common/backtrace.rs:71
   2:     0x7f1f4999b72d - std::panicking::default_hook::{{closure}}::h098a999e0c1b279e
                               at libstd/sys_common/backtrace.rs:59
                               at libstd/panicking.rs:207
   3:     0x7f1f4999b429 - std::panicking::default_hook::hd2f541195ebc1dea
                               at libstd/panicking.rs:223
   4:     0x7f1f463f725d - core::ops::function::Fn::call::h0946a0c3275debde
   5:     0x7f1f4999bbc9 - std::panicking::rust_panic_with_hook::h127f3d328cb9c946
                               at libstd/panicking.rs:403
   6:     0x7f1f4551069a - std::panicking::begin_panic::hbfebf35e964b9da1
   7:     0x7f1f45534ce5 - rustc_errors::Handler::bug::hf13b4cd4ede3ee59
   8:     0x7f1f466f01bf - rustc::session::opt_span_bug_fmt::{{closure}}::hfee030be9b8ff1e8
   9:     0x7f1f467a9ef5 - rustc::ty::context::tls::with_opt::{{closure}}::h88a2cfeee7591ffa
  10:     0x7f1f463ef78f - <std::thread::local::LocalKey<T>>::try_with::h8e6e81c50519f79b
  11:     0x7f1f463ef3c6 - <std::thread::local::LocalKey<T>>::with::h3efd74c0542fa548
  12:     0x7f1f467a9cf6 - rustc::ty::context::tls::with::h4e7056c46f6be47e
  13:     0x7f1f467a9ea7 - rustc::ty::context::tls::with_opt::hcf162eb7c7be45bb
  14:     0x7f1f466f00c4 - rustc::session::opt_span_bug_fmt::h275dfefeda53d72f
  15:     0x7f1f466f0036 - rustc::session::bug_fmt::he81ec97ba9fd393d
  16:     0x7f1f473ccd02 - rustc_mir::monomorphize::collector::should_monomorphize_locally::hadc53c23cf2ecd35
  17:     0x7f1f473ccad4 - rustc_mir::monomorphize::collector::visit_instance_use::h2eba081f4558be70
  18:     0x7f1f473cca9e - rustc_mir::monomorphize::collector::visit_fn_use::he4b23b23a4337853
  19:     0x7f1f473cc5ac - <rustc_mir::monomorphize::collector::MirNeighborCollector<'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_terminator_kind::hddb5a5bfa62a6bdc
  20:     0x7f1f47230909 - rustc::mir::visit::Visitor::visit_mir::h557b1066eb9ca420
  21:     0x7f1f473c94d2 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  22:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  23:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  24:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  25:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  26:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  27:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  28:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  29:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  30:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  31:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  32:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  33:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  34:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  35:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  36:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  37:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  38:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  39:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  40:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  41:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  42:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  43:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  44:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  45:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  46:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  47:     0x7f1f473ca2f1 - rustc_mir::monomorphize::collector::collect_items_rec::hde05f88e26b073e8
  48:     0x7f1f473c8d62 - rustc_mir::monomorphize::collector::collect_crate_mono_items::h7d3fa603ca193ea1
  49:     0x7f1f3eef6391 - rustc_trans::base::collect_and_partition_translation_items::hbc56d9acdbfb8fce
  50:     0x7f1f46591055 - rustc::dep_graph::graph::DepGraph::with_task_impl::haab752cf4b04a9d9
  51:     0x7f1f469468c1 - rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::force::h173e27a678062fc0
  52:     0x7f1f46947434 - rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::try_get::h8458681d3977b430
  53:     0x7f1f469743c5 - rustc::ty::maps::TyCtxtAt::collect_and_partition_translation_items::h7e54fb221877b03e
  54:     0x7f1f4696d45e - rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::collect_and_partition_translation_items::h0fe8a60b44cc74e1
  55:     0x7f1f3eef1d5b - rustc_trans::base::trans_crate::h95abd4e4789925dc
  56:     0x7f1f3ef4f497 - <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate::h4fb823522ed0f41d
  57:     0x7f1f49d5eaa2 - rustc_driver::driver::phase_4_translate_to_llvm::h040f62e78a90a498
  58:     0x7f1f49d57a2e - rustc_driver::driver::compile_input::{{closure}}::he9c5443356997304
  59:     0x7f1f49ce44b4 - rustc::ty::context::TyCtxt::create_and_enter::h010c9fa8ed1d20fc
  60:     0x7f1f49d55a5e - rustc_driver::driver::compile_input::hd0a77987b3f07ae0
  61:     0x7f1f49d7244a - rustc_driver::run_compiler::h7e92d64f306a4def
  62:     0x7f1f49c9d9f0 - std::sys_common::backtrace::__rust_begin_short_backtrace::hcea77d6abfa0c596
  63:     0x7f1f499b4a6e - __rust_maybe_catch_panic
                               at libpanic_unwind/lib.rs:102
  64:     0x7f1f49cd6db6 - <F as alloc::boxed::FnBox<A>>::call_box::h45c47cff726094f9
  65:     0x7f1f499abd1b - std::sys::unix::thread::Thread::new::thread_start::h2ff3c08e553ac72c
                               at /checkout/src/liballoc/boxed.rs:793
                               at libstd/sys_common/thread.rs:24
                               at libstd/sys/unix/thread.rs:90
  66:     0x7f1f4486f7fb - start_thread
  67:     0x7f1f49660b5e - clone
  68:                0x0 - <unknown>

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.26.0-nightly (259e4a678 2018-03-04) running on x86_64-unknown-linux-gnu

note: compiler flags: -C opt-level=3 -C target-cpu=native

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

I've tried to get a smaller repro but as yet haven't been successful. Below is some code to give an idea of what's going on in case it's useful, but as mentioned something's missing as it doesn't repro.

use std::{thread};
use std::sync::Arc;
use std::convert::AsRef;

#[derive(Debug)]
struct A(usize);
impl A {
    fn hello(&self) {
        println!("hello {}", self.0);
    }
    // fn run(abc: Arc<Self>) -> thread::JoinHandle<()> { // works fine
    fn run<X:AsRef<Self>+Send+'static>(abc: X) -> thread::JoinHandle<()> { // ICE
        abc.as_ref().hello();
        thread::spawn(move||{
            let abc = abc;
            let abc: &A = abc.as_ref();
            abc.hello();
        })
    }
}

And in another crate (if same crate then it works fine):

use std::sync::Arc;
fn main() {
    let abc = A(123);
    A::run(Arc::new(abc)).join().unwrap();
}

Also if I replace Arc with borrow::Borrow, it works fine.

@TimNN TimNN added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ C-bug Category: This is a bug. labels Mar 6, 2018
@estokes
Copy link

estokes commented Apr 12, 2018

I got this as well on a library using futures on rustc 1.27.0-nightly (ad610be 2018-04-11)

error: internal compiler error: librustc_mir/monomorphize/collector.rs:750: Cannot create local mono-item for DefId(44/0:489 ~ libgsh[4be4]::resolver_server[0]::send[0])

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:542:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::print
             at libstd/sys_common/backtrace.rs:71
             at libstd/sys_common/backtrace.rs:59
   2: std::panicking::default_hook::{{closure}}
             at libstd/panicking.rs:206
   3: std::panicking::default_hook
             at libstd/panicking.rs:222
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at libstd/panicking.rs:401
   6: std::panicking::begin_panic
   7: rustc_errors::Handler::bug
   8: rustc::session::opt_span_bug_fmt::{{closure}}
   9: rustc::ty::context::tls::with_opt::{{closure}}
  10: rustc::ty::context::tls::with_context_opt
  11: rustc::ty::context::tls::with_opt
  12: rustc::session::opt_span_bug_fmt
  13: rustc::session::bug_fmt
  14: rustc_mir::monomorphize::collector::should_monomorphize_locally
  15: rustc_mir::monomorphize::collector::visit_instance_use
  16: <rustc_mir::monomorphize::collector::MirNeighborCollector<'a, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_terminator_kind
  17: rustc_mir::monomorphize::collector::collect_items_rec
  18: rustc_mir::monomorphize::collector::collect_items_rec
  19: rustc_mir::monomorphize::collector::collect_items_rec
  20: rustc_mir::monomorphize::collector::collect_items_rec
  21: rustc_mir::monomorphize::collector::collect_items_rec
  22: rustc_mir::monomorphize::collector::collect_items_rec
  23: rustc_mir::monomorphize::collector::collect_items_rec
  24: rustc_mir::monomorphize::collector::collect_items_rec
  25: rustc_mir::monomorphize::collector::collect_items_rec
  26: rustc_mir::monomorphize::collector::collect_items_rec
  27: rustc_mir::monomorphize::collector::collect_items_rec
  28: rustc_mir::monomorphize::collector::collect_items_rec
  29: rustc_mir::monomorphize::collector::collect_crate_mono_items
  30: rustc::util::common::time
  31: rustc_trans::base::collect_and_partition_translation_items
  32: rustc::dep_graph::graph::DepGraph::with_task_impl
  33: rustc::ty::context::tls::with_related_context
  34: rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::force_with_lock
  35: rustc::ty::maps::<impl rustc::ty::maps::queries::collect_and_partition_translation_items<'tcx>>::try_get
  36: rustc::ty::maps::TyCtxtAt::collect_and_partition_translation_items
  37: rustc::ty::maps::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::collect_and_partition_translation_items
  38: rustc_trans::base::trans_crate
  39: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate
  40: rustc::util::common::time
  41: rustc_driver::driver::phase_4_translate_to_llvm
  42: rustc_driver::driver::compile_input::{{closure}}
  43: rustc::ty::context::tls::enter_context
  44: <std::thread::local::LocalKey<T>>::with
  45: rustc::ty::context::TyCtxt::create_and_enter
  46: rustc_driver::driver::compile_input
  47: rustc_driver::run_compiler_impl
  48: syntax::with_globals
  49: rustc_driver::run
  50: rustc_driver::main
  51: std::rt::lang_start::{{closure}}
  52: std::panicking::try::do_call
             at libstd/rt.rs:59
             at libstd/panicking.rs:305
  53: __rust_maybe_catch_panic
             at libpanic_unwind/lib.rs:101
  54: std::rt::lang_start_internal
             at libstd/panicking.rs:284
             at libstd/panic.rs:361
             at libstd/rt.rs:58
  55: main
  56: __libc_start_main
  57: <unknown>
query stack during panic:
#0 [collect_and_partition_translation_items] collect_and_partition_translation_items
end of query stack
error: aborting due to previous error

@estokes
Copy link

estokes commented Apr 12, 2018

The code generating this error seems to be,

#[derive(Serialize, Deserialize, Clone, Debug)]
pub enum FromResolver {
  Resolved(Vec<SocketAddr>),
  Response(Vec<Path>),
  Published,
  Unpublished,
  Error(String)
}

fn send(
  w: WriteHalf<TcpStream>,
  m: FromResolver
) -> impl Future<Item=WriteHalf<TcpStream>, Error=()> {
  match serde_json::to_vec(&m) {
    Err(_) => future::err(()),
    Ok(m) => future::ok(m)
  }.and_then(|m| {
    write_all(w, m).map_err(|_| ())
      .and_then(|(w, _)| {
        write_all(w, "\n").map_err(|_| ())
          .and_then(|(w, _)| Ok(w))
      })
  })
}

@estokes
Copy link

estokes commented Apr 12, 2018

So if I box all my futures instead of impl Future at the public api of the crate then that works around this bug. e.g. even though send is a couple of levels deep in the api, if I box the public function in the crate that calls send then the error doesn't happen. I guess that's sort of obvious since changing to a trait object means we are no longer doing monomorpization.

@Mark-Simulacrum
Copy link
Member

Am I correct in that there's no reproducible example of this issue with any sample of code, small or large? If so I think we'd probably have to close as it'll be hard to track down without that.

@estokes
Copy link

estokes commented Jun 2, 2018 via email

@estokes
Copy link

estokes commented Jun 2, 2018 via email

@estokes
Copy link

estokes commented Jun 5, 2018 via email

@Mark-Simulacrum
Copy link
Member

Thanks; closing in favor of #50865.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants