Skip to content

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

@Nercury

Description

@Nercury
Contributor
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

Activity

Nercury

Nercury commented on Dec 13, 2014

@Nercury
ContributorAuthor

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
added
O-ArmTarget: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state
I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
A-lifetimesArea: Lifetimes / regions
and removed
O-ArmTarget: 32-bit Arm processors (armv6, armv7, thumb...), including 64-bit Arm in AArch32 state
on Dec 13, 2014
bkoropoff

bkoropoff commented on Dec 13, 2014

@bkoropoff
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

bkoropoff commented on Dec 13, 2014

@bkoropoff
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.

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[/+] on Dec 13, 2014
alexcrichton

alexcrichton commented on Dec 13, 2014

@alexcrichton
Member

Ended up catching me on IRC

bkoropoff

bkoropoff commented on Dec 13, 2014

@bkoropoff
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)>()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lifetimesArea: Lifetimes / regionsI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alexcrichton@Nercury@huonw@bkoropoff

      Issue actions

        ICE: when non-static &str argument is encountered by TypeId · Issue #19791 · rust-lang/rust