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

intrinsicck is broken in the presence of associated types #28625

Closed
fizyk20 opened this issue Sep 24, 2015 · 10 comments
Closed

intrinsicck is broken in the presence of associated types #28625

fizyk20 opened this issue Sep 24, 2015 · 10 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@fizyk20
Copy link

fizyk20 commented Sep 24, 2015

The compiler told me to report it, so here goes ;)

I tried to compile this code using cargo build: https://gist.github.com/fizyk20/4cf1665a18ff800584f1

This is the only file in the crate. Cargo.toml looks like this:

name = "peano-array"
version = "0.1.0"
authors = ["Bartłomiej Kamiński <fizyk20@gmail.com>"]

So, nothing really unusual.

What I got is posted below:

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
thread 'rustc' panicked at 'assertion failed: `(left == right)` (left: `64`, right: `128`)', src/librustc_trans/trans/intrinsic.rs:193

stack backtrace:
   1:     0x7f57f242266e - sys::backtrace::write::ha67a6a2049d22fadIvs
   2:     0x7f57f242ad55 - panicking::on_panic::hfa4bf0215983f759lzx
   3:     0x7f57f23eb94e - rt::unwind::begin_unwind_inner::ha1b5da93bdf7e8ffC0w
   4:     0x7f57f23ec6b6 - rt::unwind::begin_unwind_fmt::hac9e09b20e42a51cIZw
   5:     0x7f57f12574c5 - trans::intrinsic::trans_intrinsic_call::h7041dfce108605fd2dH
   6:     0x7f57f126509e - trans::callee::trans_call_inner::h1312425629985073641
   7:     0x7f57f12c35af - trans::expr::trans_rvalue_dps_unadjusted::h0c5c402374fadccbRyC
   8:     0x7f57f129bbc8 - trans::expr::trans_into::hd80da72fd88f78b0voB
   9:     0x7f57f122a213 - trans::controlflow::trans_block::h712a0dbbff7e0feau1v
  10:     0x7f57f12c2b4f - trans::expr::trans_rvalue_dps_unadjusted::h0c5c402374fadccbRyC
  11:     0x7f57f12c1733 - trans::expr::trans_unadjusted::h842ed4ea995ab4beb2B
  12:     0x7f57f1209589 - trans::expr::trans::h0a46d0057de341dfLuB
  13:     0x7f57f129b7d5 - trans::expr::trans_into::hd80da72fd88f78b0voB
  14:     0x7f57f1309cf0 - trans::_match::mk_binding_alloca::h8933109284487913883
  15:     0x7f57f12148d4 - trans::base::init_local::h05162f2d49649b99pOh
  16:     0x7f57f1229ec6 - trans::controlflow::trans_block::h712a0dbbff7e0feau1v
  17:     0x7f57f1228fd6 - trans::base::trans_closure::h5ba05285462a4747sDi
  18:     0x7f57f122a808 - trans::base::trans_fn::h05022c5934c7e8c7fNi
  19:     0x7f57f12645e8 - trans::monomorphize::monomorphic_fn::hb8352eb2d7d26c23DHL
  20:     0x7f57f125420e - trans::callee::trans_fn_ref_with_substs::hfc6b0bc3f78e159eGBo
  21:     0x7f57f1268d6d - trans::meth::trans_method_callee::hb526dbe08959880cHJK
  22:     0x7f57f12e2a09 - trans::callee::trans_call_inner::h5390986988460394530
  23:     0x7f57f12cb0e6 - trans::expr::trans_index::hac54b3447ae4d077bgC
  24:     0x7f57f12c18ab - trans::expr::trans_unadjusted::h842ed4ea995ab4beb2B
  25:     0x7f57f1209589 - trans::expr::trans::h0a46d0057de341dfLuB
  26:     0x7f57f129b526 - trans::expr::trans_to_lvalue::hac83b8b50acc99b6k1B
  27:     0x7f57f12c5674 - trans::expr::trans_rvalue_stmt_unadjusted::h1b8ea36ec1927e36fsC
  28:     0x7f57f129bcf5 - trans::expr::trans_into::hd80da72fd88f78b0voB
  29:     0x7f57f129b4a2 - trans::controlflow::trans_stmt_semi::haea6d90b71002e6cy0v
  30:     0x7f57f1229e9a - trans::controlflow::trans_block::h712a0dbbff7e0feau1v
  31:     0x7f57f12c2b4f - trans::expr::trans_rvalue_dps_unadjusted::h0c5c402374fadccbRyC
  32:     0x7f57f129bbc8 - trans::expr::trans_into::hd80da72fd88f78b0voB
  33:     0x7f57f1301d8b - trans::_match::trans_match_inner::h74c561c52dd5299ftcK
  34:     0x7f57f12c2b19 - trans::expr::trans_rvalue_dps_unadjusted::h0c5c402374fadccbRyC
  35:     0x7f57f129bbc8 - trans::expr::trans_into::hd80da72fd88f78b0voB
  36:     0x7f57f122a213 - trans::controlflow::trans_block::h712a0dbbff7e0feau1v
  37:     0x7f57f12c69f5 - trans::expr::trans_rvalue_stmt_unadjusted::h1b8ea36ec1927e36fsC
  38:     0x7f57f129bcf5 - trans::expr::trans_into::hd80da72fd88f78b0voB
  39:     0x7f57f1301d8b - trans::_match::trans_match_inner::h74c561c52dd5299ftcK
  40:     0x7f57f12c2b19 - trans::expr::trans_rvalue_dps_unadjusted::h0c5c402374fadccbRyC
  41:     0x7f57f129bbc8 - trans::expr::trans_into::hd80da72fd88f78b0voB
  42:     0x7f57f1309cf0 - trans::_match::mk_binding_alloca::h8933109284487913883
  43:     0x7f57f12148d4 - trans::base::init_local::h05162f2d49649b99pOh
  44:     0x7f57f1229ec6 - trans::controlflow::trans_block::h712a0dbbff7e0feau1v
  45:     0x7f57f12c2b4f - trans::expr::trans_rvalue_dps_unadjusted::h0c5c402374fadccbRyC
  46:     0x7f57f129bbc8 - trans::expr::trans_into::hd80da72fd88f78b0voB
  47:     0x7f57f129b4a2 - trans::controlflow::trans_stmt_semi::haea6d90b71002e6cy0v
  48:     0x7f57f1229e9a - trans::controlflow::trans_block::h712a0dbbff7e0feau1v
  49:     0x7f57f1228fd6 - trans::base::trans_closure::h5ba05285462a4747sDi
  50:     0x7f57f122a808 - trans::base::trans_fn::h05022c5934c7e8c7fNi
  51:     0x7f57f12645e8 - trans::monomorphize::monomorphic_fn::hb8352eb2d7d26c23DHL
  52:     0x7f57f125420e - trans::callee::trans_fn_ref_with_substs::hfc6b0bc3f78e159eGBo
  53:     0x7f57f1252ca2 - trans::callee::trans_fn_ref::h557d599d56e051cd2qo
  54:     0x7f57f124ea18 - trans::callee::trans::hfc3e2da0f1482e8bNgo
  55:     0x7f57f1264e28 - trans::callee::trans_call_inner::h1312425629985073641
  56:     0x7f57f12c35af - trans::expr::trans_rvalue_dps_unadjusted::h0c5c402374fadccbRyC
  57:     0x7f57f129bbc8 - trans::expr::trans_into::hd80da72fd88f78b0voB
  58:     0x7f57f1309cf0 - trans::_match::mk_binding_alloca::h8933109284487913883
  59:     0x7f57f12148d4 - trans::base::init_local::h05162f2d49649b99pOh
  60:     0x7f57f1229ec6 - trans::controlflow::trans_block::h712a0dbbff7e0feau1v
  61:     0x7f57f1228fd6 - trans::base::trans_closure::h5ba05285462a4747sDi
  62:     0x7f57f122a808 - trans::base::trans_fn::h05022c5934c7e8c7fNi
  63:     0x7f57f122d928 - trans::base::trans_item::hd3ac3af06c93993fPdj
  64:     0x7f57f123a40c - trans::base::trans_crate::h14e6ea6d455593f8i0j
  65:     0x7f57f29912f4 - driver::phase_4_translate_to_llvm::h8ce7c7bfb0fd9b185Oa
  66:     0x7f57f298b885 - driver::phase_3_run_analysis_passes::closure.16542
  67:     0x7f57f2985ab1 - middle::ty::ctxt<'tcx>::create_and_enter::h9578579149294230291
  68:     0x7f57f2980991 - driver::phase_3_run_analysis_passes::h8415522514568150077
  69:     0x7f57f2964a90 - driver::compile_input::h52c7dafd49963360Tba
  70:     0x7f57f2a4aa63 - run_compiler::h473c62e00f865fa9A7b
  71:     0x7f57f2a484de - boxed::F.FnBox<A>::call_box::h10713159552398332324
  72:     0x7f57f2a47e09 - rt::unwind::try::try_fn::h16887904248528792425
  73:     0x7f57f242a84d - __rust_try
  74:     0x7f57f24158f7 - rt::unwind::try::inner_try::hafffff77ddacfa5fvWw
  75:     0x7f57f2a48028 - boxed::F.FnBox<A>::call_box::h5417278073590676257
  76:     0x7f57f2429991 - sys::thread::Thread::new::thread_start::h29dca2a2cf2294b535v
  77:     0x7f57eccc94a3 - start_thread
  78:     0x7f57f208713c - clone
  79:                0x0 - <unknown>

Meta

rustc --version --verbose:

rustc 1.3.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.3.0

(I'm on Arch Linux)

Backtrace is above, so I won't be pasting it here again ;)

@apasel422
Copy link
Contributor

Reduced:

trait Bar {
    type Bar;
}

struct ArrayPeano<T: Bar> {
    data: T::Bar,
}

fn foo<T>(a: &ArrayPeano<T>) -> &[T] where T: Bar {
    unsafe { std::mem::transmute(a) }
}

impl Bar for () {
    type Bar = ();
}

fn main() {
    let x: ArrayPeano<()> = ArrayPeano { data: () };
    foo(&x);
}

@apasel422
Copy link
Contributor

It appears that &ArrayPeano<()> is being treated as a fat pointer in rustc_trans::trans::intrinsic::check_intrinsics.

@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 24, 2015
@apasel422
Copy link
Contributor

More specifically, rustc_trans::trans::type_of::sizing_type_of is reporting:

DEBUG:rustc_trans::trans::type_of: sizing_type_of &ArrayPeano<isize>
DEBUG:rustc_trans::trans::type_of: --> mapped t=&ArrayPeano<isize> to llsizingty={ i8*, i8* }

@apasel422
Copy link
Contributor

Weirdly, implementing the trait for isize (independent of what the associated type Bar is set to) results in the expected error.

@apasel422
Copy link
Contributor

This debug output is also concerning:

DEBUG:rustc::middle::ty::util: Ty::impls_bound(ArrayPeano<isize>, Sized) = false

It seems that because isize doesn't implement Bar, <isize as Bar>::Bar is not known to be Sized. This is impossible, because Bar::Bar is not declared ?Sized. This manifests as this ICE because transmute restrictions are tested with isize.

@arielb1
Copy link
Contributor

arielb1 commented Sep 26, 2015

How did the isize get there? Trying to compute ArrayPeano<isize>: Sized causes a trait error, which makes impls_bound return false. Why are we asking for it?

@arielb1
Copy link
Contributor

arielb1 commented Sep 26, 2015

intrinsicck tries to use the types isize and [isize] for checking sizedness. This is, like, totally nonfunctional when associated types are involved.

I can't really see how intrinsicck can survive with associated types.

@arielb1
Copy link
Contributor

arielb1 commented Sep 26, 2015

intrinsicck should really be replaced with an unreachable + generating an rust-lang/rfcs#1229 warning.

@arielb1 arielb1 changed the title Unexpected compiler panic intrinsicck is broken in the presence of associated types Oct 7, 2015
@dylanede
Copy link
Contributor

Just bumped into this problem when trying to transmute a reference into a * const (). Is there a known workaround?

Edit: For anyone else wondering, the workaround for transmute is to just use transmute_copy instead, and potentially forget the original if necessary.

@eddyb
Copy link
Member

eddyb commented Jun 12, 2016

This has been fixed, @apasel422's reduction produces a transmute size mismatch error.

@eddyb eddyb added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Jun 12, 2016
bors added a commit that referenced this issue Aug 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

6 participants