Skip to content

Internal compiler error: meth::trans_trait_callee given non-bare-rust-fn #26049

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
bagedevimo opened this issue Jun 6, 2015 · 6 comments
Closed
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bagedevimo
Copy link

Compiler ICE

I tried this code:

pub struct Load;

struct LoadHlD16 {
  param: u16,
}

trait Instruction {
  fn execute(&self, cpu: &mut CPU);
}

trait InstructionMagic : Instruction {
  fn new(rom: &mut Box<MemoryUnit>) -> Box<Instruction> { panic!("invalid opcode, {}", rom.read_word()); }
}

impl Instruction for LoadHlD16 {
  fn execute(&self, cpu: &mut CPU) {
    cpu.reg_h = ((self.param >> 8) & 0xff) as u8;
    cpu.reg_l = ((self.param >> 0) & 0xff) as u8;
  }
}

impl InstructionMagic for LoadHlD16 {
  fn new(rom: &mut Box<MemoryUnit>) -> Box<Instruction> {
    Box::new(LoadHlD16 {
      param: rom.read_dword(),
    })
  }
}

trait MemoryUnit {
  extern fn read_word(&mut self) -> u8;
  extern fn read_dword(&mut self) -> u16;
}

struct ROM {
  memory: Vec<u8>,
  read_head: usize,
}

impl ROM {
  pub fn new() -> ROM {
    ROM {
      memory: Vec::new(),
      read_head: 0,
    }
  }
}

impl MemoryUnit for ROM {
  extern fn read_word(&mut self) -> u8 {
    self.read_head += 1;
    return self.memory[self.read_head - 1];
  }

 extern fn read_dword(&mut self) -> u16 {
    let a16 = self.read_word() as u16;
    let b16 = self.read_word() as u16;

    (b16 << 8) | a16
  }
}

pub struct CPU {
  reg_h : u8,
  reg_l : u8,
}

fn main() { }

I expected to see this happen: A syntax error some something, as this seems like dodgy code.

Instead, this happened: Internal Compiler Error

Meta

rustc --version --verbose:

rustc 1.2.0-nightly (613e57b44 2015-06-01) (built 2015-06-01) binary: rustc commit-hash: 613e57b448c88591b6076a8cea9799f1f3876687 commit-date: 2015-06-01 build-date: 2015-06-01 host: x86_64-apple-darwin release: 1.2.0-nightly

Backtrace:

error: internal compiler error: meth::trans_trait_callee given non-bare-rust-fn 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 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/nightly-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:249

stack backtrace:
   1:        0x10a37b7b5 - sys::backtrace::write::hb40a7a5e7a72988bfas
   2:        0x10a3843f0 - panicking::on_panic::h86479ea026bd45advvw
   3:        0x10a33e918 - rt::unwind::begin_unwind_inner::h293827e692145ff2Ndw
   4:        0x109afb5ee - rt::unwind::begin_unwind::h8034774599807933892
   5:        0x109afc842 - diagnostic::Handler::bug::hffef8a39d579c80fSwC
   6:        0x10745acb7 - session::Session::bug::h21e72a48d80b8271mRr
   7:        0x106cb792e - trans::meth::trans_trait_callee_from_llval::h18843a188ce6a71cuJJ
   8:        0x106bee74f - trans::meth::trans_method_callee::h05baa791ac83a5c6JjJ
   9:        0x106beae93 - trans::callee::trans_call_inner::h6958093892275901921
  10:        0x106c5306e - trans::expr::trans_rvalue_dps_unadjusted::hcdcefe2a3f59365bLHB
  11:        0x106c51424 - trans::expr::trans_unadjusted::h086fef628f42cd18dcB
  12:        0x106b843f2 - trans::expr::trans::h6448a08da6a9358chEA
  13:        0x106c5d3e8 - trans::expr::trans_binary::h1a460ba0bd236f66XIC
  14:        0x106c515f2 - trans::expr::trans_unadjusted::h086fef628f42cd18dcB
  15:        0x106b843f2 - trans::expr::trans::h6448a08da6a9358chEA
  16:        0x106c5d840 - trans::expr::trans_unary::haac7951f58a2c9295oC
  17:        0x106c51612 - trans::expr::trans_unadjusted::h086fef628f42cd18dcB
  18:        0x106b843f2 - trans::expr::trans::h6448a08da6a9358chEA
  19:        0x106c53096 - trans::expr::trans_rvalue_dps_unadjusted::hcdcefe2a3f59365bLHB
  20:        0x106c2648c - trans::expr::trans_into::h6009ec9ae47bc5feYxA
  21:        0x106c25f7c - trans::controlflow::trans_stmt_semi::h689fdb8ae5150005upv
  22:        0x106ba4788 - trans::controlflow::trans_block::h3e04463295d967c0qqv
  23:        0x106ba3346 - trans::base::trans_closure::hacac1641af16a94dyUh
  24:        0x106ba512e - trans::base::trans_fn::hc41f53572339d5aeg5h
  25:        0x106ba8c2c - trans::base::trans_item::h8d3637d6c62dd6b5Kti
  26:        0x106bb6faf - trans::base::trans_crate::h95df642bda748ef0Wij
  27:        0x106a236fd - driver::phase_4_translate_to_llvm::h3a56782fe1d07222zOa
  28:        0x1069ff664 - driver::compile_input::heb62e3ff94a6164dQba
  29:        0x106ab9e54 - run_compiler::h16134909dfe8b0c9n6b
  30:        0x106ab75aa - boxed::F.FnBox<A>::call_box::h14102854404630110502
  31:        0x106ab6cc7 - rt::unwind::try::try_fn::h12738087818574960391
  32:        0x10a40cbf8 - rust_try_inner
  33:        0x10a40cbe5 - rust_try
  34:        0x10a36e315 - rt::unwind::try::inner_try::h8724f7b732bcbc52G9v
  35:        0x106ab6f22 - boxed::F.FnBox<A>::call_box::h14615098147423876694
  36:        0x10a382eed - sys::thread::Thread::new::thread_start::h4c9197fb4b3ddc8afyv
  37:     0x7fff9374c267 - _pthread_body
  38:     0x7fff9374c1e4 - _pthread_start```

Thanks!

cc @rust-lang/compiler

@bagedevimo
Copy link
Author

changing param: rom.read_dword(), to param: 16 will fix this and i'm pretty sure this one is on me.

@Aatch Aatch added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 6, 2015
@bagedevimo
Copy link
Author

@Aatch noted on IRC that this is caused by the externs on read_word and read_dword

@Aatch
Copy link
Contributor

Aatch commented Jun 6, 2015

Minimal test case:

#![crate_type="lib"]

trait Foo {
    extern fn read_word(&mut self) -> u8;
}

fn do_foo(f: &mut Box<Foo>) -> u8 {
    f.read_word()
}

@Aatch
Copy link
Contributor

Aatch commented Jun 6, 2015

Interestingly, it seems that this only affects virtual calls, not regular method calls. So doing f.read_word where f : F, F : Foo works, while f : &mut Foo doesn't.

Aatch added a commit to Aatch/rust that referenced this issue Jun 6, 2015
Trying to call methods with a non-Rust ABI on a trait object results in
an ICE. While we could try to translate them, it makes more sense to
just reject non-Rust ABIs in type-check.

This is technically a [breaking-change] due to that fact that we didn't
ICE when statically dispatching these method calls.

Fixes rust-lang#26049
@Aatch
Copy link
Contributor

Aatch commented Jun 6, 2015

Bah, my fix causes another test-case to fail. For some reason we allowed extern methods, even though that doesn't really make much sense.

Question for the language subteam (@rust-lang/language): Should we not allow these extern methods, even though they're a breaking change, make them trigger object-safety violations or support them in trait objects?

@steveklabnik
Copy link
Member

This no longer ICEs on last night's nightly.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants