Skip to content

ICE: Unsized struct type with no unsized type params? #16977

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
japaric opened this issue Sep 3, 2014 · 4 comments · Fixed by #17112
Closed

ICE: Unsized struct type with no unsized type params? #16977

japaric opened this issue Sep 3, 2014 · 4 comments · Fixed by #17112
Labels
A-DSTs Area: Dynamically-sized types (DSTs) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@japaric
Copy link
Member

japaric commented Sep 3, 2014

STR

use std::mem;

pub struct MatrixPtr<T> {
    stride: uint,
    data: [T],
}

fn main() {
    println!("{}", mem::size_of::<Box<MatrixPtr<u8>>>());
}

Backtrace

error: internal compiler error: unexpected failure
note: the compiler hit an unexpected failure path. this is a bug.
note: we would appreciate a bug report: http://doc.rust-lang.org/complement-bugreport.html
note: run with `RUST_BACKTRACE=1` for a backtrace
task 'rustc' failed at 'Unsized struct type with no unsized type params? MatrixPtr<u8>', /var/tmp/paludis/build/dev-lang-rust-scm/work/rust-scm/src/librustc/middle/ty.rs:2996

stack backtrace:
   1:     0x7f8733ea1f70 - rt::backtrace::imp::write::h299eec8aab69a711QLq
   2:     0x7f8733ea5110 - <unknown>
   3:     0x7f87383e6720 - unwind::begin_unwind_inner::h54a7e7ee8ce0bb5562d
   4:     0x7f87383e6210 - unwind::begin_unwind_fmt::heb960fdaa23bb220q0d
   5:     0x7f8738e66cd0 - middle::ty::unsized_part_of_type::h89ac47b79a68d4e2zFG
   6:     0x7f8738e66a70 - <unknown>
   7:     0x7f8738de4d50 - middle::trans::type_of::type_of::h7d6d777844b0d72d7p9
   8:     0x7f8738de4d50 - middle::trans::type_of::type_of::h7d6d777844b0d72d7p9
   9:     0x7f8738e141a0 - middle::trans::intrinsic::trans_intrinsic_call::hef8776afbdff5fd19co
  10:     0x7f8738de6940 - middle::trans::callee::trans_call_inner::hdb5af0a4259acdadDN1
  11:     0x7f8738e12d10 - middle::trans::callee::trans_call::hd7a0c21ac21ab585IH1
  12:     0x7f8738e20590 - <unknown>
  13:     0x7f8738ddd7e0 - middle::trans::expr::trans_into::h455a70c3d80c644bbC2
  14:     0x7f8738dddbe0 - middle::trans::controlflow::trans_block::hd19ec4bf5fe4707dcsY
  15:     0x7f8738e20590 - <unknown>
  16:     0x7f8738ddd7e0 - middle::trans::expr::trans_into::h455a70c3d80c644bbC2
  17:     0x7f8738dddbe0 - middle::trans::controlflow::trans_block::hd19ec4bf5fe4707dcsY
  18:     0x7f8738e8bb90 - middle::trans::base::trans_closure::h38cd943ee5cbb21cZGe
  19:     0x7f8738dcee60 - middle::trans::base::trans_fn::h40d057b9529de439MSe
  20:     0x7f8738dcf4b0 - middle::trans::monomorphize::monomorphic_fn::h549338ed5be0cdd49OX
  21:     0x7f8738e08820 - middle::trans::callee::trans_fn_ref_with_vtables::hc6d83971dcff08eeOm1
  22:     0x7f8738e060b0 - middle::trans::callee::trans_fn_ref::h1568c66e253fe357W80
  23:     0x7f8738e12f70 - <unknown>
  24:     0x7f8738de6940 - middle::trans::callee::trans_call_inner::hdb5af0a4259acdadDN1
  25:     0x7f8738e12d10 - middle::trans::callee::trans_call::hd7a0c21ac21ab585IH1
  26:     0x7f8738e20590 - <unknown>
  27:     0x7f8738e1f660 - <unknown>
  28:     0x7f8738dded80 - middle::trans::expr::trans::hc04a6451622f2c0f7F2
  29:     0x7f8738e2cd60 - <unknown>
  30:     0x7f8738e1f660 - <unknown>
  31:     0x7f8738ddd7e0 - middle::trans::expr::trans_into::h455a70c3d80c644bbC2
  32:     0x7f8738e34090 - middle::trans::expr::trans_adt::hab2f5ae0bb98191bxy4
  33:     0x7f8738e20590 - <unknown>
  34:     0x7f8738e1f660 - <unknown>
  35:     0x7f8738dded80 - middle::trans::expr::trans::hc04a6451622f2c0f7F2
  36:     0x7f8738eadbe0 - <unknown>
  37:     0x7f8738e20590 - <unknown>
  38:     0x7f8738ddd7e0 - middle::trans::expr::trans_into::h455a70c3d80c644bbC2
  39:     0x7f8738ddcca0 - middle::trans::controlflow::trans_stmt_semi::h47c762caa9301142irY
  40:     0x7f8738ddc380 - middle::trans::controlflow::trans_stmt::h8b414dbefeffca511mY
  41:     0x7f8738dddbe0 - middle::trans::controlflow::trans_block::hd19ec4bf5fe4707dcsY
  42:     0x7f8738e8bb90 - middle::trans::base::trans_closure::h38cd943ee5cbb21cZGe
  43:     0x7f8738dcee60 - middle::trans::base::trans_fn::h40d057b9529de439MSe
  44:     0x7f8738dca830 - middle::trans::base::trans_item::h3cf9d14d5c4845bcMaf
  45:     0x7f8738e96310 - middle::trans::base::trans_crate::h22b399d616507876d5f
  46:     0x7f87392a9440 - driver::driver::phase_4_translate_to_llvm::hcda833ff5a8394f3J9B
  47:     0x7f87392a1070 - driver::driver::compile_input::h360a96a71b54c472RLB
  48:     0x7f8739334dc0 - <unknown>
  49:     0x7f8739334cd0 - <unknown>
  50:     0x7f87393478d0 - <unknown>
  51:     0x7f87393476d0 - <unknown>
  52:     0x7f87387375f0 - <unknown>
  53:     0x7f8738433f30 - <unknown>
  54:     0x7f8738433f20 - rust_try
  55:     0x7f87383e3e70 - unwind::try::h6700e660c05658b3gRd
  56:     0x7f87383e3cd0 - task::Task::run::h480a4539e35e57e892c
  57:     0x7f8738737350 - <unknown>
  58:     0x7f87383e57e0 - <unknown>
  59:     0x7f8733247000 - start_thread
  60:     0x7f87380b4ec9 - clone
  61:                0x0 - <unknown>

Version

rustc 0.12.0-pre (3ce5a026b 2014-09-03 09:21:02 +0000)

cc @nick29581

@nrc nrc added the A-dst label Sep 3, 2014
@nrc
Copy link
Member

nrc commented Sep 3, 2014

This should be a compiler error, not an ICE. The error is (or should be) that data is unsized, but is not a bare T.

@Kimundi
Copy link
Member

Kimundi commented Sep 3, 2014

Why would this be an error? Isn't enabling this kind of code part of the goal of DST?

@nrc
Copy link
Member

nrc commented Sep 3, 2014

@Kimundi Not quite. We want to allow struct's last field to be potentially unsized, but it must be possible to have a sized version too. This is because only sized types can be instantiated. Since there is no possible sized version of MatrixPtr, it cannot be instantiated and should be an error.

@Kimundi
Copy link
Member

Kimundi commented Sep 4, 2014

Hm, I see. This is kinda unfortunate though, because you can't hide away the actual slice type from your wrapper. Eg, you could do

struct MatrixPtr_<Sized? T> {
    stride: uint,
    data: T,
}
pub type MatrixPtr = MatrixPtr_<[T]>;

But that widens your wrapper to possibly be instantiated with more than [T, ..N] and [T].

Maybe allow a struct definition like

struct MatrixPtr<T> {
    stride: uint,
    data: [T],
}

but to use it you need to transmute something like MatrixPtr_<[u8]> ?


As an aside, the example in this issue would probably not work anyway, as the stride should presumably be stored per pointer, and not once in the target matrices backing memory. But this is till relevant for newtype wrappers around [T], eg a hypothetical struct Str([u8])

nrc added a commit to nrc/rust that referenced this issue Sep 7, 2014
@huonw huonw added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Sep 10, 2014
nrc added a commit to nrc/rust that referenced this issue Sep 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-DSTs Area: Dynamically-sized types (DSTs) I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
4 participants