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: librustc/mir/tcx.rs:68: extracting field of non-tuple non-adt: Ty { ty: _ } #55552

Closed
vitiral opened this issue Oct 31, 2018 · 8 comments
Closed
Assignees
Labels
A-NLL Area: Non-lexical lifetimes (NLL) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ NLL-complete Working towards the "valid code works" goal P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta.

Comments

@vitiral
Copy link
Contributor

vitiral commented Oct 31, 2018

An underscore (aka wildcard aka _) nested within a type declaration is causing problems for some new code that tries to project out the inner types after normalization is finished. Here is an example (play):

struct X;
struct Y;
struct Z;

pub fn join<A, B, RA, RB>(_oper_a: A, _oper_b: B) -> (RA, RB)
    where A: FnOnce() -> RA + Send,
          B: FnOnce() -> RB + Send,
          RA: Send,
          RB: Send
{
    loop { }
}

fn main() {
    let ((_x, _y), _z): (_, Z) = join(|| (X, Y),
                                      || Z);
}

Original bug report follows


Running cargo test here

error: internal compiler error: librustc/mir/tcx.rs:68: extracting field of non-tuple non-adt: Ty { ty: _ }                             
                                                                                                                                 
thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:600: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
   2: std::panicking::default_hook::{{closure}}
             at libstd/sys_common/backtrace.rs:59        
             at libstd/panicking.rs:211                                                                                              
   3: std::panicking::default_hook                      
             at libstd/panicking.rs:227                
   4: rustc::util::common::panic_hook              
   5: std::panicking::rust_panic_with_hook                                                               
             at libstd/panicking.rs:480                                                       
   6: std::panicking::begin_panic                                                   
   7: rustc_errors::Handler::bug                                       
   8: rustc::util::bug::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::util::bug::opt_span_bug_fmt                            
  13: rustc::util::bug::bug_fmt                                                                          
  14: rustc::mir::tcx::PlaceTy::field_ty                                                      
  15: rustc::mir::tcx::PlaceTy::projection_ty_core                                               
  16: rustc_mir::borrow_check::nll::type_check::TypeChecker::relate_type_and_user_type
  17: <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'gcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_local_decl
  18: <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'gcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_mir
  19: rustc_mir::borrow_check::nll::type_check::type_check_internal
  20: rustc::ty::context::tls::with_related_context             
  21: rustc::infer::InferCtxtBuilder::enter                                                              
  22: <rustc_mir::borrow_check::nll::type_check::TypeckMir as rustc_mir::transform::MirPass>::run_pass
  23: rustc_mir::transform::run_passes::{{closure}}                                
  24: rustc_mir::transform::run_passes           
  25: rustc_mir::transform::mir_const          
  26: rustc::ty::query::__query_compute::mir_const       
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_const<'tcx>>::compute
  28: rustc::ty::context::tls::with_context             
  29: rustc::dep_graph::graph::DepGraph::with_task_impl
  30: rustc::ty::context::tls::with_related_context
  31: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  32: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  33: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_const
  34: rustc_mir::transform::mir_validated                              
  35: rustc::ty::query::__query_compute::mir_validated                                                           
  36: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_validated<'tcx>>::compute
  37: rustc::ty::context::tls::with_context                                          
  38: rustc::dep_graph::graph::DepGraph::with_task_impl
  39: rustc::ty::context::tls::with_related_context                 
  40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  41: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query
  42: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query
  43: rustc_borrowck::borrowck::borrowck                                              
  44: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::borrowck<'tcx>>::compute    
  45: rustc::ty::context::tls::with_context                                                                                      
  46: rustc::dep_graph::graph::DepGraph::with_task_impl            
  47: rustc::ty::context::tls::with_related_context                                                                                                                                                       [22/3644]
  48: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job
  49: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query        
  50: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::par_body_owners
  51: rustc_borrowck::borrowck::check_crate      
  52: rustc::util::common::time                                 
  53: rustc::ty::context::tls::enter_context             
  54: <std::thread::local::LocalKey<T>>::with                                                                                        
  55: rustc::ty::context::TyCtxt::create_and_enter                                    
  56: rustc_driver::driver::compile_input              
  57: rustc_driver::run_compiler_with_pool         
  58: rustc_driver::driver::spawn_thread_pool                                                            
  59: rustc_driver::run_compiler                                                              
  60: <scoped_tls::ScopedKey<T>>::set                                               
  61: syntax::with_globals               
  62: __rust_maybe_catch_panic                                                                                   
             at libpanic_unwind/lib.rs:102                                                                                               
  63: rustc_driver::run                                                              
  64: rustc_driver::main                               
  65: std::rt::lang_start::{{closure}}                              
  66: std::panicking::try::do_call                                                                       
             at libstd/rt.rs:59                                                               
             at libstd/panicking.rs:310                                                          
  67: __rust_maybe_catch_panic                                                        
             at libpanic_unwind/lib.rs:102                                                                                              
  68: std::rt::lang_start_internal                                                                                               
             at libstd/panicking.rs:289                            
             at libstd/panic.rs:392                             
             at libstd/rt.rs:58                                                                          
  69: main                                                                                            
  70: __libc_start_main                                                            
  71: <unknown>                                  
query stack during panic:                      
#0 [mir_const] processing `artifact::determine_artifacts`
#1 [mir_validated] processing `artifact::determine_artifacts`                                                                        
#2 [borrowck] processing `artifact::determine_artifacts`
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.31.0-nightly (1cf82fd9c 2018-10-30) running on x86_64-unknown-linux-gnu
                                                       
note: compiler flags: -C debuginfo=2 -C incremental --crate-type lib
                                                                                                         
note: some of the compiler flags provided by cargo are hidden                                 
                                                                                                 
error: Could not compile `artifact_data`.                                         
```
@vitiral vitiral changed the title ICE on nightly ICE: librustc/mir/tcx.rs:68: extracting field of non-tuple non-adt: Ty { ty: _ } Oct 31, 2018
@matthewjasper matthewjasper added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Oct 31, 2018
@pnkfelix pnkfelix self-assigned this Nov 2, 2018
@pnkfelix pnkfelix added the A-NLL Area: Non-lexical lifetimes (NLL) label Nov 2, 2018
@pnkfelix
Copy link
Member

pnkfelix commented Nov 2, 2018

This is almost certainly a very recent injection (and I think it was my PR, and its probably on beta branch too). Investigating now.

@pnkfelix
Copy link
Member

pnkfelix commented Nov 2, 2018

Oddly I can't get to the ICE because I cannot compile petgraph with this version of the compiler...

Update: oh well I might have also needed to run cargo update locally... might have been nice if cargo had automatically suggested that option when the compilation of the dependent crate failed.

@pnkfelix
Copy link
Member

pnkfelix commented Nov 2, 2018

no surprise, this was injected between nightly-2018-10-27-x86_64-unknown-linux-gnu - rustc 1.31.0-nightly (3e6f30e 2018-10-26) (which works) and nightly-2018-10-28-x86_64-unknown-linux-gnu - rustc 1.31.0-nightly (cae6efc 2018-10-27) (which does not work).

I'm the one who wrote the code that is ICE'ing, I'll try to have a fix up soon.

@pnkfelix
Copy link
Member

pnkfelix commented Nov 2, 2018

Working on making an isolated test case now; I think the ICE is originating from compiling the body of artifact::determine_artifacts (I really wish I had put a span_bug! in there instead of a bug!...)

@pnkfelix
Copy link
Member

pnkfelix commented Nov 2, 2018

Okay here's a really small test case that replicates the problem on play. It currently relies on extern crate rayon but it shouldn't be hard to cut-and-paste a signature for fn join to make a truly standalone test.

extern crate rayon; // 1.0.2

struct A;
struct B;
struct C;

fn main() {
    let ((_a, _b), _c): (_, C) = rayon::join(
        || { (A, B) },
        || { C });
}

Interestingly this is happening on code that isn't even opting into NLL; I didn't expect that...

@pnkfelix
Copy link
Member

pnkfelix commented Nov 2, 2018

Okay and here's a standalone test

struct X;
struct Y;
struct Z;

pub fn join<A, B, RA, RB>(_oper_a: A, _oper_b: B) -> (RA, RB)
    where A: FnOnce() -> RA + Send,
          B: FnOnce() -> RB + Send,
          RA: Send,
          RB: Send
{
    loop { }
}


fn main() {
    let ((_x, _y), _z): (_, Z) = join(|| (X, Y),
                                      || Z);
}

@pnkfelix pnkfelix added regression-from-stable-to-beta Performance or correctness regression from stable to beta. P-high High priority labels Nov 2, 2018
@pnkfelix
Copy link
Member

pnkfelix commented Nov 2, 2018

Its an interesting bug; even just doing the following is enough to bypass the ICE:

let ((_x, _y), _z): ((_, _), Z) = ...

@pnkfelix pnkfelix added the NLL-complete Working towards the "valid code works" goal label Nov 6, 2018
@pnkfelix
Copy link
Member

pnkfelix commented Nov 6, 2018

Note that since this is an ICE, we don't get to use our usual excuse of "NLL migration mode automatically handles NLL-complete issues." That's why this s P-high.

@pnkfelix pnkfelix added this to the Rust 2018 Release milestone Nov 6, 2018
bors added a commit that referenced this issue Nov 10, 2018
…rojections-out-of-a-ty-var, r=nikomatsakis

Do not attempt to ascribe projections out of a ty var

If we encounter `_` ascribed to structural pattern like `(a, b)`, just skip relate_types.

Fix #55552
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-NLL Area: Non-lexical lifetimes (NLL) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ NLL-complete Working towards the "valid code works" goal P-high High priority regression-from-stable-to-beta Performance or correctness regression from stable to beta.
Projects
None yet
Development

No branches or pull requests

3 participants