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 in collect_and_partition_mono_items #69785

Closed
jonhoo opened this issue Mar 6, 2020 · 15 comments · Fixed by #96667
Closed

ICE in collect_and_partition_mono_items #69785

jonhoo opened this issue Mar 6, 2020 · 15 comments · Fixed by #96667
Labels
A-async-await Area: Async & Await A-codegen Area: Code generation AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jonhoo
Copy link
Contributor

jonhoo commented Mar 6, 2020

Code

// crate a
#![feature(type_alias_impl_trait)]

use std::future::Future;

pub trait Service<Request> {
    type Future: Future<Output = ()>;
    fn call(&mut self, req: Request) -> Self::Future;
}

// NOTE: the pub(crate) here is critical
pub(crate) fn new() -> () {}

pub struct A;
impl Service<()> for A {
    type Future = impl Future<Output = ()>;
    fn call(&mut self, _: ()) -> Self::Future {
        async { new() }
    }
}
// crate b
use a::Service;
use std::future::Future;
use std::pin::Pin;
use std::task::Context;


fn broken(mut a: a::A, cx: &mut Context<'_>) {
    let mut fut = a.call(());
    let _ = unsafe { Pin::new_unchecked(&mut fut) }.poll(cx);
}

pub async fn main(cx: &mut Context<'_>) {
    broken(a::A, cx);
}

Meta

$ rustc --version --verbose
rustc 1.43.0-nightly (96bb8b31c 2020-03-05)
binary: rustc
commit-hash: 96bb8b31c81dc2394317f2f083c3acf8087efea1
commit-date: 2020-03-05
host: x86_64-unknown-linux-gnu
release: 1.43.0-nightly
LLVM version: 9.0

Error output

error: internal compiler error: src/librustc_mir/monomorphize/collector.rs:745: cannot create local mono-item for DefId(15:8 ~ a[ffa2]::new[0])

thread 'rustc' panicked at 'Box<Any>', src/librustc_errors/lib.rs:875:9
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1053
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1428
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:204
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:224
  10: rustc_driver::report_ice
  11: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:474
  12: std::panicking::begin_panic
  13: rustc_errors::HandlerInner::bug
  14: rustc_errors::Handler::bug
  15: rustc::util::bug::opt_span_bug_fmt::{{closure}}
  16: rustc::ty::context::tls::with_opt::{{closure}}
  17: rustc::ty::context::tls::with_opt
  18: rustc::util::bug::opt_span_bug_fmt
  19: rustc::util::bug::bug_fmt
  20: rustc_mir::monomorphize::collector::should_monomorphize_locally
  21: <rustc_mir::monomorphize::collector::MirNeighborCollector as rustc::mir::visit::Visitor>::visit_terminator_kind
  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_session::utils::<impl rustc_session::session::Session>::time
  26: rustc_mir::monomorphize::collector::collect_crate_mono_items
  27: rustc_mir::monomorphize::partitioning::collect_and_partition_mono_items
  28: rustc::dep_graph::graph::DepGraph::with_task_impl
  29: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::force_query
  30: rustc::ty::query::plumbing::force_from_dep_node
  31: rustc::dep_graph::graph::DepGraph::try_mark_previous_green
  32: rustc::dep_graph::graph::DepGraph::try_mark_green
  33: rustc::dep_graph::graph::DepGraph::try_mark_green_and_read
  34: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt>::get_query
  35: rustc_metadata::rmeta::encoder::EncodeContext::encode_crate_root
  36: rustc::dep_graph::graph::DepGraph::with_ignore
  37: rustc_metadata::rmeta::encoder::encode_metadata
  38: rustc_metadata::rmeta::decoder::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::creader::CStore>::encode_metadata
  39: rustc::ty::context::TyCtxt::encode_metadata
  40: rustc_interface::passes::start_codegen
  41: rustc::ty::context::tls::enter_global
  42: rustc_interface::queries::Queries::ongoing_codegen
  43: rustc_interface::interface::run_compiler_in_existing_thread_pool
  44: rustc_ast::attr::with_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

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.43.0-nightly (96bb8b31c 2020-03-05) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental -C target-cpu=native --crate-type lib

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

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
#1 [exported_symbols] exported_symbols
end of query stack
error: aborting due to previous error

error: could not compile `b`.

This is probably a smaller reproduction of #57430.

@jonhoo jonhoo 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 Mar 6, 2020
@jonas-schievink jonas-schievink added A-async-await Area: Async & Await E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-nominated A-codegen Area: Code generation labels Mar 6, 2020
@jonhoo
Copy link
Contributor Author

jonhoo commented Mar 9, 2020

If anyone has a quick and dirty idea for how to force an impl Trait type to resolve, I think I could finish minifying the above pretty easily.

@csmoe

This comment has been minimized.

@jonhoo
Copy link
Contributor Author

jonhoo commented Mar 10, 2020

@jonas-schievink Updated reproducing code to remove need for futures_executor.

@csmoe csmoe removed the E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example label Mar 10, 2020
@jonhoo
Copy link
Contributor Author

jonhoo commented Mar 10, 2020

I'm fairly certain this is related to the visibility of types that appear in an impl Trait type. Specifically, in the code above, if pub(crate) fn new() in a is changed to pub, it compiles fine.

jonhoo added a commit to mit-pdos/noria that referenced this issue Mar 10, 2020
@spastorino
Copy link
Member

@rustbot ping icebreakers-cleanup-crew

@rustbot rustbot added the ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections label Mar 11, 2020
@rustbot
Copy link
Collaborator

rustbot commented Mar 11, 2020

Hey Cleanup Crew ICE-breakers! This bug has been identified as a good
"Cleanup ICE-breaking candidate". In case it's useful, here are some
instructions for tackling these sorts of bugs. Maybe take a look?
Thanks! <3

cc @AminArria @chrissimpkins @contrun @DutchGhost @elshize @ethanboxx @h-michael @HallerPatrick @hdhoang @hellow554 @imtsuki @jakevossen5 @KarlK90 @LeSeulArtichaut @matheus-consoli @mental32 @nmccarty @Noah-Kennedy @pard68 @PeytonT @pierreN @Redblueflame @RobbieClarken @RobertoSnap @robjtede @SarthakSingh31 @senden9 @shekohex @sinato @spastorino @turboladen @woshilapin @yerke

@pnkfelix pnkfelix added the F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` label Mar 11, 2020
@spastorino spastorino added the P-high High priority label Mar 11, 2020
@spastorino
Copy link
Member

triage: P-high until we assess severity (the bug written depends on a feature flag) we want to know if that's really needed for the issue to reproduce.

@jonhoo
Copy link
Contributor Author

jonhoo commented Mar 11, 2020

fwiw, my guess is that the feature flag is not necessary, and that the relevant type = impl Trait can be replaced by an async fn.

@Centril Centril added the requires-nightly This issue requires a nightly compiler in some way. label Mar 12, 2020
@nikomatsakis
Copy link
Contributor

So, for cleanup crew ICE-breakers who might take a look at this:

(a) we should try to get a backtrace with line numbers
(b) we should see if this is a regression and track down the cause (maybe jump back a few months and see if the corresponding nightly from that time works?)
(c) it'd be interesting to see if we can remove the type = impl Trait from the impl and thus reproduce on something that builds on stable. As @jonhoo noted, an inherent async fn on A could trigger it, or perhaps something like:

// crate a
use std::future::Future;

// NOTE: the pub(crate) here is critical
pub(crate) fn new() -> () {}

pub struct A;
impl A {
    fn call(&mut self, _: ()) -> impl Future<Output = ()> {
        async { new() }
    }
}

@Centril Centril added P-medium Medium priority and removed P-high High priority labels Mar 12, 2020
@Centril
Copy link
Contributor

Centril commented Mar 12, 2020

Downgrading priority for now until we can reproduce without the gate.

@pnkfelix
Copy link
Member

related discussion from T-compiler meeting

@jonhoo
Copy link
Contributor Author

jonhoo commented Mar 16, 2020

@nikomatsakis Interestingly enough, an inherent method like that does not reproduce the issue, so it appears the existential type in associated type position is also needed.

@tmandry tmandry added the AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. label Mar 17, 2020
@nazar-pc
Copy link

I just hit the same issue on nightly:

error: internal compiler error: compiler/rustc_monomorphize/src/collector.rs:966:9: no MIR available for DefId(20:1344 ~ cranelift_codegen[eeed]::machinst::buffer::{impl#3}::get_srclocs_sorted)

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1169:9
stack backtrace:
   0: std::panicking::begin_panic::<rustc_errors::ExplicitBug>
   1: std::panic::panic_any::<rustc_errors::ExplicitBug>
   2: <rustc_errors::HandlerInner>::bug
   3: <rustc_errors::Handler>::bug
   4: rustc_middle::ty::context::tls::with_opt::<rustc_middle::util::bug::opt_span_bug_fmt<rustc_span::span_encoding::Span>::{closure#0}, ()>
   5: rustc_middle::util::bug::opt_span_bug_fmt::<rustc_span::span_encoding::Span>
   6: rustc_middle::util::bug::bug_fmt
   7: rustc_monomorphize::collector::collect_neighbours
   8: rustc_monomorphize::collector::collect_items_rec
   9: rustc_monomorphize::collector::collect_items_rec
  10: rustc_monomorphize::collector::collect_items_rec
  11: rustc_monomorphize::collector::collect_items_rec
  12: rustc_monomorphize::collector::collect_items_rec
  13: <rustc_session::session::Session>::time::<(), rustc_monomorphize::collector::collect_crate_mono_items::{closure#1}>
  14: rustc_monomorphize::collector::collect_crate_mono_items
  15: rustc_monomorphize::partitioning::collect_and_partition_mono_items
  16: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<(), (&std::collections::hash::set::HashSet<rustc_span::def_id::DefId, core::hash::BuildHasherDefault<rustc_hash::FxHasher>>, &[rustc_middle::mir::mono::CodegenUnit])>>
  17: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::collect_and_partition_mono_items, rustc_query_impl::plumbing::QueryCtxt>
  18: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::collect_and_partition_mono_items
  19: rustc_codegen_ssa::back::symbol_export::exported_symbols_provider_local
  20: rustc_query_system::query::plumbing::try_execute_query::<rustc_query_impl::plumbing::QueryCtxt, rustc_query_system::query::caches::DefaultCache<rustc_span::def_id::CrateNum, &[(rustc_middle::middle::exported_symbols::ExportedSymbol, rustc_middle::middle::exported_symbols::SymbolExportLevel)]>>
  21: rustc_query_system::query::plumbing::get_query::<rustc_query_impl::queries::exported_symbols, rustc_query_impl::plumbing::QueryCtxt>
  22: <rustc_metadata::rmeta::encoder::EncodeContext>::encode_crate_root
  23: rustc_metadata::rmeta::encoder::encode_metadata_impl
  24: rustc_data_structures::sync::join::<rustc_metadata::rmeta::encoder::encode_metadata::{closure#0}, rustc_metadata::rmeta::encoder::encode_metadata::{closure#1}, rustc_metadata::rmeta::encoder::EncodedMetadata, ()>
  25: rustc_metadata::rmeta::encoder::encode_metadata
  26: <rustc_interface::queries::Queries>::ongoing_codegen
  27: <rustc_interface::interface::Compiler>::enter::<rustc_driver::run_compiler::{closure#1}::{closure#2}, core::result::Result<core::option::Option<rustc_interface::queries::Linker>, rustc_errors::ErrorReported>>
   Compiling kvdb-memorydb v0.10.0
  28: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#1}>
  29: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>
  30: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorReported>, rustc_driver::run_compiler::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose 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.60.0-nightly (22e491ac7 2022-01-13) running on x86_64-unknown-linux-gnu

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

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

query stack during panic:
#0 [collect_and_partition_mono_items] collect_and_partition_mono_items
#1 [exported_symbols] exported_symbols
end of query stack
error: could not compile `wasmtime-cranelift`

Reproduction is huge though: https://github.com/subspace/substrate/tree/rust-69785

Just cargo test it. This happened after I upgraded wasmtime dependency from 0.31.0 to 0.33.0.

I don't see type_alias_impl_trait feature used in wasmtime-cranelift.

@bjorn3
Copy link
Member

bjorn3 commented Jan 16, 2022

That is #92755 which was fixed two days ago. Try updating rustc.

@nazar-pc
Copy link

Indeed, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-codegen Area: Code generation AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ ICEBreaker-Cleanup-Crew Helping to "clean up" bugs with minimal examples and bisections P-medium Medium priority requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Development

Successfully merging a pull request may close this issue.