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

Compiler panics on cycle in (sub)traits declaration #58813

Closed
udi0peled opened this issue Feb 28, 2019 · 7 comments
Closed

Compiler panics on cycle in (sub)traits declaration #58813

udi0peled opened this issue Feb 28, 2019 · 7 comments
Labels
A-incr-comp Area: Incremental compilation A-trait-system Area: Trait system 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. WG-incr-comp Working group: Incremental compilation

Comments

@udi0peled
Copy link

I tried this code:

trait T2: T1 {
    fn say_bye(&self);
}
trait T1: T2 {
    fn say_hello(&self);
}
impl T1 for i32 {
    fn say_hello(&self) {
        println!("Hello {}!", self);
    }
}
impl T2 for i32 {
    fn say_bye(&self) {
        println!("Bye {}?", self);
    }
}

fn main() {
    let n = 16;
    n.say_hello();
    n.say_bye();
}

I expected to see this happen: compilation error about cycle in traits T1,T2

Instead, this happened: compiler panicked

Meta

rustc --version --verbose:
rustc 1.32.0 (9fda7c2 2019-01-16)
binary: rustc
commit-hash: 9fda7c2
commit-date: 2019-01-16
host: x86_64-unknown-linux-gnu
release: 1.32.0
LLVM version: 8.0

@estebank estebank added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-trait-system Area: Trait system labels Feb 28, 2019
@estebank
Copy link
Contributor

Can you post the output? I cannot reproduce this in the playground for any release.

@hellow554
Copy link
Contributor

With the exact same compiler and that code I cannot reproduce that ICE. If you happen to reproduce it, please do it like RUST_BACKTRACE=1 cargo build or similar and post the result of that please :)

@udi0peled
Copy link
Author

Weird, yesterday I could reproduce it multiple times, now I can't, and I get the set same result as in the playground.

@udi0peled
Copy link
Author

OK, I'm managed to recreate the bug by first running almost the same code, but without the problem.
Specifically, first run this code (removed the subtrait : T2 from T1: T2):

trait T2: T1 {
    fn say_bye(&self);
}
trait T1 {
    fn say_hello(&self);
}
impl T1 for i32 {
    fn say_hello(&self) {
        println!("Hello {}!", self);
    }
}
impl T2 for i32 {
    fn say_bye(&self) {
        println!("Bye {}?", self);
    }
}
fn main() {
    let n = 16;
    n.say_hello();
    n.say_bye();
}

Then running the original problematic code with : T2 subtrait of T1: T2, and the backtrace of the bug is this:

/home/udi/.cargo/bin/cargo run --color=always --package hello --bin hello
   Compiling hello v0.1.0 (/home/udi/prg/Rust/hello)
thread 'main' panicked at 'did not find a cycle', src/librustc/ty/query/job.rs:146:9
stack backtrace:
   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace
             at src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:71
   2: std::panicking::default_hook::{{closure}}
             at src/libstd/sys_common/backtrace.rs:59
             at src/libstd/panicking.rs:211
   3: std::panicking::default_hook
             at src/libstd/panicking.rs:227
   4: rustc::util::common::panic_hook
   5: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:495
   6: std::panicking::begin_panic
   7: rustc::ty::query::job::QueryJob::await
   8: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
   9: rustc_typeck::collect::super_predicates_of
  10: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::super_predicates_of<'tcx>>::compute
  11: rustc::ty::context::tls::with_context
  12: rustc::dep_graph::graph::DepGraph::with_task_impl
  13: <rustc::ty::query::plumbing::JobOwner<'a, 'tcx, Q>>::start
  14: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  15: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query
  16: rustc::ty::query::plumbing::force_from_dep_node
  17: rustc::dep_graph::graph::DepGraph::try_mark_green
  18: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::try_mark_green_and_read
  19: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  20: <rustc_typeck::collect::CollectItemTypesVisitor<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item
  21: rustc::hir::Crate::visit_all_item_likes
  22: rustc::util::common::time
  23: rustc_typeck::check_crate
  24: rustc::ty::context::tls::enter_context
  25: <std::thread::local::LocalKey<T>>::with
  26: rustc::ty::context::TyCtxt::create_and_enter
  27: rustc_driver::driver::compile_input
  28: rustc_driver::run_compiler_with_pool
  29: <scoped_tls::ScopedKey<T>>::set
  30: rustc_driver::run_compiler
  31: rustc_driver::monitor::{{closure}}
  32: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:102
  33: rustc_driver::run
  34: rustc_driver::main
  35: std::rt::lang_start::{{closure}}
  36: std::panicking::try::do_call
             at src/libstd/rt.rs:59
             at src/libstd/panicking.rs:310
  37: __rust_maybe_catch_panic
             at src/libpanic_unwind/lib.rs:102
  38: std::rt::lang_start_internal
             at src/libstd/panicking.rs:289
             at src/libstd/panic.rs:398
             at src/libstd/rt.rs:58
  39: main
  40: __libc_start_main
  41: <unknown>
query stack during panic:
#0 [super_predicates_of] computing the supertraits of `T1`
end of query stack

error: internal compiler error: unexpected panic

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.32.0 (9fda7c223 2019-01-16) running on x86_64-unknown-linux-gnu

note: compiler flags: -C debuginfo=2 -C incremental --crate-type bin

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

error: Could not compile `hello`.

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

Process finished with exit code 101

@hellow554
Copy link
Contributor

Indeed! Thank you very much! Incremental bugs are sometimes hard to reproduce.

Bug is also on 1.33.0 stable, but not on 1.34.0-beta1.

@hellow554
Copy link
Contributor

The question is: This is already fixed in nightly. I think this deserved a testcase nevertheless, right?

Here's one if needed

src/test/incremental/circular_dependency.rs
// revisions:rpass1 rpass2
// See issue #58813

#![allow(warnings)]
pub trait T1: T2 { }
#[cfg(rpass1)]
pub trait T2 { }
#[cfg(rpass2)]
pub trait T2: T1 { }

fn main() { }

@pnkfelix pnkfelix added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-incr-comp Area: Incremental compilation WG-incr-comp Working group: Incremental compilation labels Mar 4, 2019
@pnkfelix
Copy link
Member

pnkfelix commented Mar 4, 2019

Heh, normally when regressions are fixed I tagged them as E-needstest, but I guess we already have a test ready to go here.

pnkfelix added a commit to pnkfelix/rust that referenced this issue Mar 6, 2019
(Update: Fixed test; revision is meant to introduce compile-failure, w/o ICE.)
pietroalbini added a commit to pietroalbini/rust that referenced this issue Mar 8, 2019
bors added a commit that referenced this issue Mar 9, 2019
Rollup of 24 pull requests

Successful merges:

 - #58080 (Add FreeBSD armv6 and armv7 targets)
 - #58204 (On return type `impl Trait` for block with no expr point at last semi)
 - #58269 (Add librustc and libsyntax to rust-src distribution.)
 - #58369 (Make the Entry API of HashMap<K, V> Sync and Send)
 - #58861 (Expand where negative supertrait specific error is shown)
 - #58877 (Suggest removal of `&` when borrowing macro and appropriate)
 - #58883 (Suggest appropriate code for unused field when destructuring pattern)
 - #58891 (Remove stray ` in the docs for the FromIterator implementation for Option)
 - #58893 (race condition in thread local storage example)
 - #58906 (Monomorphize generator field types for debuginfo)
 - #58911 (Regression test for #58435.)
 - #58912 (Regression test for #58813)
 - #58916 (Fix release note problems noticed after merging.)
 - #58918 (Regression test added for an async ICE.)
 - #58921 (Add an explicit test for issue #50582)
 - #58926 (Make the lifetime parameters of tcx consistent.)
 - #58931 (Elide invalid method receiver error when it contains TyErr)
 - #58940 (Remove JSBackend from config.toml)
 - #58950 (Add self to mailmap)
 - #58961 (On incorrect cfg literal/identifier, point at the right span)
 - #58963 (libstd: implement Error::source for io::Error)
 - #58970 (delay_span_bug in wfcheck's ty.lift_to_tcx unwrap)
 - #58984 (Teach `-Z treat-err-as-bug` to take a number of errors to emit)
 - #59007 (Add a test for invalid const arguments)

Failed merges:

 - #58959 (Add release notes for PR #56243)

r? @ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-incr-comp Area: Incremental compilation A-trait-system Area: Trait system 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. WG-incr-comp Working group: Incremental compilation
Projects
None yet
Development

No branches or pull requests

4 participants