Skip to content

ICE: when non-static &str argument is encountered by TypeId #19791

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

Closed
Nercury opened this issue Dec 13, 2014 · 5 comments · Fixed by #19821
Closed

ICE: when non-static &str argument is encountered by TypeId #19791

Nercury opened this issue Dec 13, 2014 · 5 comments · Fixed by #19821
Labels
A-lifetimes Area: Lifetimes / regions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Nercury
Copy link
Contributor

Nercury commented Dec 13, 2014

use std::intrinsics::TypeId;

fn print_type_name<T:'static>(_val: T) {
    println!("{}", TypeId::of::<T>());
}

fn main() {
    print_type_name(|_name: &str| { // allows non 'static &str here
        5i
    });
}
// error: internal compiler error: non-static region found when hashing a type
@Nercury
Copy link
Contributor Author

Nercury commented Dec 13, 2014

Backtrace:

stack backtrace:
   1:        0x107b265c0 - rt::backtrace::imp::write::h276c1d3da30d25d7bVx
   2:        0x107b297d0 - failure::on_fail::h26104c4e5109e22dPhy
   3:        0x107d7ad95 - unwind::begin_unwind_inner::hfa8e57738653fe8fFBc
   4:        0x1072da0d7 - unwind::begin_unwind::h3249923926675629605
   5:        0x1072daa8f - diagnostic::Handler::bug::h1673c0a29453129cbaF
   6:        0x1050be778 - session::Session::bug::h09ebd830ac6d13fblMz
   7:        0x10532a8a2 - middle::ty::hash_crate_independent::closure.96589
   8:        0x10532af7f - middle::ty::hash_crate_independent::closure.96599
   9:        0x105307723 - middle::ty::walk_ty::closure.94468
  10:        0x1053fbe1e - middle::ty::maybe_walk_ty::closure.94478
  11:        0x1051a73d3 - middle::ty::maybe_walk_ty::h6e515205c1509074mAf
  12:        0x1051a7455 - middle::ty::maybe_walk_ty::h6e515205c1509074mAf
  13:        0x10532a820 - middle::ty::hash_crate_independent::hf4bd8bffe870a1f0kGj
  14:        0x104cdca94 - trans::intrinsic::trans_intrinsic_call::h2b3b59e4eb2f2b6dNcD
  15:        0x104caa82b - trans::callee::trans_call_inner::hbd39e21b08b3e49e13g
  16:        0x104cebabe - trans::expr::trans_rvalue_dps_unadjusted::h4191e842202cc935cgj
  17:        0x104ca1783 - trans::expr::trans_into::h87b2b20cddb6e2bcWMh
  18:        0x104ca2460 - trans::controlflow::trans_block::h92c650bfe835c6e0FYd
  19:        0x104ceac3d - trans::expr::trans_rvalue_dps_unadjusted::h4191e842202cc935cgj
  20:        0x104ca1783 - trans::expr::trans_into::h87b2b20cddb6e2bcWMh
  21:        0x104ca2460 - trans::controlflow::trans_block::h92c650bfe835c6e0FYd
  22:        0x104d4ff63 - trans::base::trans_closure::h8599ef4c8af09dcbVfu
  23:        0x104c94f50 - trans::base::trans_fn::hd9fe0820c71be153cru
  24:        0x104c96cc9 - trans::monomorphize::monomorphic_fn::h5f84861ef240adf0Yqd
  25:        0x104ccc81e - trans::callee::trans_fn_ref_with_substs::h6f3e02f49fb07bfadIg
  26:        0x104cc934e - trans::callee::trans_fn_ref::hc71677feb48bfed6vng
  27:        0x104cd8e76 - trans::callee::trans_call::closure.38397
  28:        0x104ca8e74 - trans::callee::trans_call_inner::hbd39e21b08b3e49e13g
  29:        0x104cebabe - trans::expr::trans_rvalue_dps_unadjusted::h4191e842202cc935cgj
  30:        0x104ce7d74 - trans::expr::trans_unadjusted::h8607f7db8bb3fae4UCi
  31:        0x104ca2a59 - trans::expr::trans::h553e065ec2b35466IQh
  32:        0x104cfe811 - trans::expr::trans_addr_of::h8fb8e63f184c2049Q3j
  33:        0x104ce8556 - trans::expr::trans_unadjusted::h8607f7db8bb3fae4UCi
  34:        0x104ca183c - trans::expr::trans_into::h87b2b20cddb6e2bcWMh
  35:        0x104d03efa - trans::expr::trans_adt::h4744b63c2ff7d25eVMj
  36:        0x104ceb7e3 - trans::expr::trans_rvalue_dps_unadjusted::h4191e842202cc935cgj
  37:        0x104ce7d74 - trans::expr::trans_unadjusted::h8607f7db8bb3fae4UCi
  38:        0x104ca2a59 - trans::expr::trans::h553e065ec2b35466IQh
  39:        0x104d6f096 - trans::_match::trans_match_inner::he8ec62a86a1f68a1BCx
  40:        0x104ceabd6 - trans::expr::trans_rvalue_dps_unadjusted::h4191e842202cc935cgj
  41:        0x104ca1783 - trans::expr::trans_into::h87b2b20cddb6e2bcWMh
  42:        0x104ca074c - trans::controlflow::trans_stmt_semi::h607474dd67b6c7f2MXd
  43:        0x104ca21cd - trans::controlflow::trans_block::h92c650bfe835c6e0FYd
  44:        0x104d4ff63 - trans::base::trans_closure::h8599ef4c8af09dcbVfu
  45:        0x104c94f50 - trans::base::trans_fn::hd9fe0820c71be153cru
  46:        0x104c964f5 - trans::monomorphize::monomorphic_fn::h5f84861ef240adf0Yqd
  47:        0x104ccc81e - trans::callee::trans_fn_ref_with_substs::h6f3e02f49fb07bfadIg
  48:        0x104cc934e - trans::callee::trans_fn_ref::hc71677feb48bfed6vng
  49:        0x104cd8e76 - trans::callee::trans_call::closure.38397
  50:        0x104ca8e74 - trans::callee::trans_call_inner::hbd39e21b08b3e49e13g
  51:        0x104cebabe - trans::expr::trans_rvalue_dps_unadjusted::h4191e842202cc935cgj
  52:        0x104ca1783 - trans::expr::trans_into::h87b2b20cddb6e2bcWMh
  53:        0x104ca074c - trans::controlflow::trans_stmt_semi::h607474dd67b6c7f2MXd
  54:        0x104ca21cd - trans::controlflow::trans_block::h92c650bfe835c6e0FYd
  55:        0x104d4ff63 - trans::base::trans_closure::h8599ef4c8af09dcbVfu
  56:        0x104c94f50 - trans::base::trans_fn::hd9fe0820c71be153cru
  57:        0x104c8f7d0 - trans::base::trans_item::h500da4689dfe0ec2eMu
  58:        0x104d51759 - trans::base::trans_mod::hde21d18912c60861JRu
  59:        0x104d5681b - trans::base::trans_crate::hcdd1861394aada8coIv
  60:        0x10455acf4 - driver::phase_4_translate_to_llvm::ha8b95de82e05b0beVCa
  61:        0x10454275a - driver::compile_input::hde6371ddee42c3f7pba
  62:        0x1045d828d - run_compiler::h06c79cf9e1e33dfbEYb
  63:        0x1045d6cee - run::closure.21409
  64:        0x1045e812e - task::TaskBuilder::try_future::closure.22863
  65:        0x107aff833 - task::TaskBuilder::spawn_internal::closure.30632
  66:        0x107d7899d - task::Task::spawn::closure.5567
  67:        0x107de016c - rust_try_inner
  68:        0x107de0156 - rust_try
  69:        0x107d78a77 - unwind::try::he77b5a8881543410Wqc
  70:        0x107d7884c - task::Task::run::he429ca3c5047a629fIb
  71:        0x107d7854f - task::Task::spawn::closure.5543
  72:        0x107d79e57 - thread::thread_start::h6870b75b36f51b8cwZb
  73:     0x7fff8f02d899 - _pthread_body
  74:     0x7fff8f02d72a - _pthread_struct_init

@huonw huonw added O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ A-lifetimes Area: Lifetimes / regions and removed O-Arm Target: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state labels Dec 13, 2014
@bkoropoff
Copy link
Contributor

Well, this is interesting. It's broken all the way back to 0.10. I think it's been a bug in the type id implementation since it first landed. Here's a smaller test case:

use std::intrinsics::TypeId;

fn main() {
    TypeId::of::<fn<'a>(&'a int)>();
}

@bkoropoff
Copy link
Contributor

@alexcrichton, is there a particular reason hash_crate_independent explicitly checks that all regions it encounters are 'static? Trans doesn't seem to go out of its way to erase late-bound regions in fn type signatures, which results in this ICE. I could add a call to normalize_ty in trans to fix this, but it would be cheaper to just ignore regions during hashing.

@Nercury Nercury changed the title ICE: when non-static &str argument is allowed for closure used as static generic type ICE: when non-static &str argument is encountered by TypeId Dec 13, 2014
@alexcrichton
Copy link
Member

Ended up catching me on IRC

@bkoropoff
Copy link
Contributor

It seems we actually want to take late-bound regions into account when hashing. For example, the following should hold:

TypeId::of::<fn(&'static int)>() != TypeId::of::<for<'a> fn(&'a int)>()

bkoropoff added a commit to bkoropoff/rust that referenced this issue Dec 16, 2014
Normalize late-bound regions in bare functions, stack closures,
and traits and include them in the generated hash.

Closes rust-lang#19791
bkoropoff added a commit to bkoropoff/rust that referenced this issue Dec 16, 2014
brson added a commit that referenced this issue Dec 16, 2014
Normalize late-bound regions in bare functions, stack closures, and traits and include them in the generated hash.

Closes #19791

r? @nikomatsakis (does my normalization make sense?)
cc @alexcrichton
alexcrichton added a commit to alexcrichton/rust that referenced this issue Dec 17, 2014
Normalize late-bound regions in bare functions, stack closures, and traits and include them in the generated hash.

Closes rust-lang#19791

r? @nikomatsakis (does my normalization make sense?)
cc @alexcrichton
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants