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 when accessing an associated constant of a generic impl #55219

Closed
jebrosen opened this issue Oct 20, 2018 · 11 comments · Fixed by #55323
Closed

ICE when accessing an associated constant of a generic impl #55219

jebrosen opened this issue Oct 20, 2018 · 11 comments · Fixed by #55323
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 regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.

Comments

@jebrosen
Copy link
Contributor

jebrosen commented Oct 20, 2018

(minimized test case provided by @tmandry )

This is triggered by accessing an associated constant of a generic impl. Here's a minimized testcase that ICEs on nightly (playground link):

pub struct Foo<T>(T);

impl<T> Foo<T> {
    const HASH_LEN: usize = 20;

    fn stuff() {
        let _ = Self::HASH_LEN;
    }
}

If a lifetime parameter is used instead of a type parameter, no ICE occurs.

Original bug report follows


Compiling mysql_common fails on rustc 1.31.0-nightly (78ff609d7 2018-10-19), but works on the previous nightly rustc 1.31.0-nightly (e7f5d4805 2018-10-18).

   Compiling mysql_common v0.10.0 (/home/mee/code/rust_mysql_common)                                                                                                                           
thread 'main' panicked at 'assertion failed: !impl_self_ty.has_infer_types()', librustc_mir/borrow_check/nll/type_check/mod.rs:1033:21                                                         
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: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_mir::borrow_check::nll::type_check::TypeChecker::relate_type_and_user_type                                                                                                         
   8: <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'gcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_constant                                                         
   9: <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'gcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_rvalue                                                           
  10: <rustc_mir::borrow_check::nll::type_check::TypeVerifier<'a, 'b, 'gcx, 'tcx> as rustc::mir::visit::Visitor<'tcx>>::visit_mir                                                              
  11: rustc_mir::borrow_check::nll::type_check::type_check_internal                                                                                                                            
  12: rustc::ty::context::tls::with_related_context                                                                                                                                            
  13: rustc::infer::InferCtxtBuilder::enter                                                                                                                                                    
  14: <rustc_mir::borrow_check::nll::type_check::TypeckMir as rustc_mir::transform::MirPass>::run_pass                                                                                         
  15: rustc_mir::transform::mir_const::{{closure}}                                                                                                                                             
  16: rustc_mir::transform::mir_const                                                                                                                                                          
  17: rustc::ty::query::__query_compute::mir_const                                                                                                                                             
  18: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_const<'tcx>>::compute                                                          
  19: rustc::ty::context::tls::with_context                                                                                                                                                    
  20: rustc::dep_graph::graph::DepGraph::with_task_impl                                                                                                                                        
  21: rustc::ty::context::tls::with_related_context                                                                                                                                            
  22: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job                                                                                      
  23: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query                                                                                                 
  24: rustc::ty::query::<impl rustc::ty::context::TyCtxt<'a, 'tcx, 'lcx>>::mir_const                                                                                                           
  25: rustc_mir::transform::mir_validated                                                                                                                                                      
  26: rustc::ty::query::__query_compute::mir_validated                                                                                                                                         
  27: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::mir_validated<'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::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::ensure_query                                                                                              
  34: rustc_borrowck::borrowck::borrowck                                                                                                                                                       
  35: rustc::ty::query::<impl rustc::ty::query::config::QueryAccessors<'tcx> for rustc::ty::query::queries::borrowck<'tcx>>::compute                                                           
  36: rustc::ty::context::tls::with_context                                                                                                                                                    
  37: rustc::dep_graph::graph::DepGraph::with_task_impl                                                                                                                                        
  38: rustc::ty::context::tls::with_related_context                                                                                                                                            
  39: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::force_query_with_job                                                                                      
  40: rustc::ty::query::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::get_query                                                                                                 
  41: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::par_body_owners                                                                                                            
  42: rustc_borrowck::borrowck::check_crate                                                                                                                                                    
  43: rustc::util::common::time                                                                                                                                                                
  44: rustc::ty::context::tls::enter_context                                                                                                                                                   
  45: <std::thread::local::LocalKey<T>>::with                                                                                                                                                  
  46: rustc::ty::context::TyCtxt::create_and_enter                                                                                                                                             
  47: rustc_driver::driver::compile_input                                                                                                                                                      
  48: rustc_driver::run_compiler_with_pool                                                                                                                                                     
  49: rustc_driver::driver::spawn_thread_pool                                                                                                                                                  
  50: rustc_driver::run_compiler                                                                                                                                                               
  51: <scoped_tls::ScopedKey<T>>::set                                                                                                                                                          
  52: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once                                                                                                          
  53: __rust_maybe_catch_panic                                                                                                                                                                 
             at libpanic_unwind/lib.rs:102                                                                                                                                                     
  54: rustc_driver::run                                                                                                                                                                        
  55: rustc_driver::main                                                                                                                                                                       
  56: std::rt::lang_start::{{closure}}                                                                                                                                                         
  57: std::panicking::try::do_call                                                                                                                                                             
             at libstd/rt.rs:59                                                                                                                                                                
             at libstd/panicking.rs:310                                                                                                                                                        
  58: __rust_maybe_catch_panic                                                                                                                                                                 
             at libpanic_unwind/lib.rs:102                                                                                                                                                     
  59: std::rt::lang_start_internal                                                                                                                                                             
             at libstd/panicking.rs:289                                                                                                                                                        
             at libstd/panic.rs:392                                                                                                                                                            
             at libstd/rt.rs:58                                                                                                                                                                
  60: main                                                                                                                                                                                     
  61: __libc_start_main                                                                                                                                                                        
  62: <unknown>                                                                                                                                                                                
query stack during panic:                                                                                                                                                                      
#0 [mir_const] processing `<crypto::rsa::Pkcs1OaepPadding<T>>::mgf1`                                                                                                                           
#1 [mir_validated] processing `<crypto::rsa::Pkcs1OaepPadding<T>>::mgf1`                                                                                                                       
#2 [borrowck] processing `<crypto::rsa::Pkcs1OaepPadding<T>>::mgf1`                                                                                                                            
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.31.0-nightly (78ff609d7 2018-10-19) 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 `mysql_common`.                                                                                                                                                       

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

thread 'main' panicked at 'assertion failed: !impl_self_ty.has_infer_types()', librustc_mir/borrow_check/nll/type_check/mod.rs:1033:21

Some additional detail with RUST_LOG=debug before and after the stack trace:

 INFO 2018-10-20T04:27:03Z: rustc_mir::build: fn_id DefId(0/0:65 ~ mysql_common[73d2]::crypto[0]::rsa[0]::{{impl}}[2]::mgf1[0]) has attrs Borrowed([Attribute { id: AttrId(52), style: Outer, path: path(doc), tokens: TokenStream { kind: Stream([TokenStream { kind: Tree(Token(src/crypto/rsa.rs:70:5: 70:56, Eq)) }, TokenStream { kind: Tree(Token(src/crypto/rsa.rs:70:5: 70:56, Literal(Str_(/// Mask Generation Function as defined in rfc2437.), None))) }]) }, is_sugared_doc: true, span: src/crypto/rsa.rs:70:5: 70:56 }, Attribute { id: AttrId(53), style: Outer, path: path(doc), tokens: TokenStream { kind: Stream([TokenStream { kind: Tree(Token(src/crypto/rsa.rs:71:5: 71:8, Eq)) }, TokenStream { kind: Tree(Token(src/crypto/rsa.rs:71:5: 71:8, Literal(Str_(///), None))) }]) }, is_sugared_doc: true, span: src/crypto/rsa.rs:71:5: 71:8 }, Attribute { id: AttrId(54), style: Outer, path: path(doc), tokens: TokenStream { kind: Stream([TokenStream { kind: Tree(Token(src/crypto/rsa.rs:72:5: 72:46, Eq)) }, TokenStream { kind: Tree(Token(src/crypto/rsa.rs:72:5: 72:46, Literal(Str_(/// It will use SHA-1 as a hash function.), None))) }]) }, is_sugared_doc: true, span: src/crypto/rsa.rs:72:5: 72:46 }])
 INFO 2018-10-20T04:27:03Z: rustc_mir::build: fn_id DefId(0/1:18 ~ mysql_common[73d2]::crypto[0]::rsa[0]::{{impl}}[2]::mgf1[0]::{{closure}}[0]) has attrs Borrowed([])                         
thread 'main' panicked at 'assertion failed: !impl_self_ty.has_infer_types()', librustc_mir/borrow_check/nll/type_check/mod.rs:1033:21
[stack backtrace]

The problematic code appears to be https://github.com/blackbeam/rust_mysql_common/blob/master/src/crypto/rsa.rs#L88

PR #55152 looks like a likely cause as it touched the failing assert! and nearby code, cc @nikomatsakis

EDIT: typo in PR number.

@memoryruins memoryruins added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-NLL Area: Non Lexical Lifetimes (NLL) labels Oct 20, 2018
@jebrosen
Copy link
Contributor Author

I tried bisecting this but quite a few commits in that PR throw out errors starting with:

error: internal compiler error: broken MIR in DefId(

Bisect log:

# bad: [78ff609d7375ee2a2c6d0222776ac612eb1b75be] Auto merge of #55152 - nikomatsakis:nll-issue-54571-type-annot-in-constants, r=pnkfelix
# good: [e7f5d48059aa14cc2808473564deadd72d1e818d] Auto merge of #54976 - davidtwco:issue-52663-special-case-closures, r=nikomatsakis
git bisect start '78ff609d7' 'e7f5d4805'
# good: [0724efd9a1aac9cf4620795786fb8e896fbb17b3] Rollup merge of #55013 - matthewjasper:propagate-generator-bounds, r=nikomatsakis
git bisect good 0724efd9a1aac9cf4620795786fb8e896fbb17b3
# skip: [e94959b9369d611aed86a4c179406a96e983278a] propagate user-type annotation for constants in expressions
git bisect skip e94959b9369d611aed86a4c179406a96e983278a
# skip: [a0a3b4c0585129405c09a9be46a1a3f8d3411b3b] replace `UserTypeAnnotation::AdtDef` with `TypeOf`
git bisect skip a0a3b4c0585129405c09a9be46a1a3f8d3411b3b
# bad: [9a7bb0ef249258aacf144d04f5d437ba70533128] normalize the self-type that we extract from impl
git bisect bad 9a7bb0ef249258aacf144d04f5d437ba70533128
# bad: [2d98e9e0aa6a990ec12f476c495be6720ad81f51] create type ascription for any cast
git bisect bad 2d98e9e0aa6a990ec12f476c495be6720ad81f51
# good: [dbab381da1a46a18e46a04a61156aec40c59a4f6] Auto merge of #55040 - scalexm:param-env, r=nikomatsakis
git bisect good dbab381da1a46a18e46a04a61156aec40c59a4f6
# skip: [e7ab33e7a61ff046f1736f1b027c16d9494e20b8] type_check/mod.rs: rustfmt
git bisect skip e7ab33e7a61ff046f1736f1b027c16d9494e20b8
# good: [ebdfda64f893f30675320e15349b2948b2194ea9] convert `FnDef` to `TypeOf`, which is more general
git bisect good ebdfda64f893f30675320e15349b2948b2194ea9
# bad: [121f3c8d19c3549ab0b51a14034ffb8b097faf42] normalize after substitution
git bisect bad 121f3c8d19c3549ab0b51a14034ffb8b097faf42
# skip: [f99300fcbdfec2908aeb93c823fc37f92a4d2d30] pull `relate_type_and_user_type` code into `type_check` module
git bisect skip f99300fcbdfec2908aeb93c823fc37f92a4d2d30
# only skipped commits left to test
# possible first bad commit: [121f3c8d19c3549ab0b51a14034ffb8b097faf42] normalize after substitution
# possible first bad commit: [f99300fcbdfec2908aeb93c823fc37f92a4d2d30] pull `relate_type_and_user_type` code into `type_check` module
# possible first bad commit: [e7ab33e7a61ff046f1736f1b027c16d9494e20b8] type_check/mod.rs: rustfmt
# possible first bad commit: [a0a3b4c0585129405c09a9be46a1a3f8d3411b3b] replace `UserTypeAnnotation::AdtDef` with `TypeOf`
# possible first bad commit: [e94959b9369d611aed86a4c179406a96e983278a] propagate user-type annotation for constants in expressions

@tmandry
Copy link
Member

tmandry commented Oct 23, 2018

Just confirmed that this was triggered by #55152. The merge commit fails; its first parent does not.

@jebrosen Thanks for your detailed reports, btw!

@tmandry
Copy link
Member

tmandry commented Oct 23, 2018

This is triggered by accessing an associated constant of a generic impl. Here's a minimized testcase that ICEs on nightly (playground link):

pub struct Foo<T>(T);

impl<T> Foo<T> {
    const HASH_LEN: usize = 20;

    fn stuff() {
        let _ = Self::HASH_LEN;
    }
}

If a lifetime parameter is used instead of a type parameter, no ICE occurs.

This is all I know, someone else will have to figure out what it means. :)

@jebrosen
Copy link
Contributor Author

@tmandry Aha! That does happen in mysql_common as well, a few lines above the location I pointed out before:

https://github.com/blackbeam/rust_mysql_common/blob/e4e80124c3c711cfc9e0f22de2784113914ef4c6/src/crypto/rsa.rs#L86

@tmandry
Copy link
Member

tmandry commented Oct 23, 2018

@jebrosen Indeed, I used that code as my starting point for the minimized testcase. Thanks for pointing to it :)

#55273 had another case; that code also makes use of Self::CONST.

@jebrosen
Copy link
Contributor Author

I reverted only commit e94959b locally, and both mysql_common and the minimized test case above compile again.

@pnkfelix
Copy link
Member

it looks to me like #55261 and #55219 are duplicates of each other.

@pnkfelix
Copy link
Member

pnkfelix commented Oct 23, 2018

(Well except that #55261 only fails on 2015 edition. So I'll close that in favor of #55219, which has a more general test case that exhibits failure on both 2015 and 2018 editions.)

@pnkfelix pnkfelix changed the title ICE when building mysql_common with rustc 1.31.0-nightly (78ff609d7 2018-10-19) ICE when accessing an associated constant of a generic impl Oct 23, 2018
@pnkfelix
Copy link
Member

an NLL PR injected this so it seems fair that someone from WG-compiler-nll should have to fix it.

Tagging with NLL-complete. Note that migration does not mitigate this because it is an ICE.

@pnkfelix pnkfelix added the NLL-complete Working towards the "valid code works" goal label Oct 23, 2018
@pnkfelix pnkfelix self-assigned this Oct 23, 2018
@pnkfelix pnkfelix added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Oct 23, 2018
@pnkfelix
Copy link
Member

Tagging as a Release blocker. But does not need to block RC2; instead, will probably need a beta backport.

@nikomatsakis
Copy link
Contributor

Have a pending fix.

nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Oct 24, 2018
Add regression tests for rust-lang#55219 and rust-lang#55241

Also another test where a duplicate-like error appears to have been
suppressed; I'm not 100% sure why this output changes, though I could
imagine that some duplicate suppression is enabled by this PR.
bors added a commit that referenced this issue Oct 25, 2018
introduce type-op for user-type ascription in NLL

Handle user-type ascription in a type operator, which gives us a lot more flexibility around the order in which we resolve things.

r? @pnkfelix

Fixes #55219
Fixes #55241
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 regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants