rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
98.86k stars 12.77k forks source link

ICE when using generic FnMut #15354

Closed bluss closed 10 years ago

bluss commented 10 years ago

Encountered ICE when trying to implement something like std::iter::Map using a F: FnMut bound for the mapping function.

ICE in middle/trans/type_of.rs

 error: internal compiler error: fictitious type ty_param(middle::ty::ParamTy{space: TypeSpace, idx: 0u, def_id: syntax::ast::DefId{krate: 0u32, node: 44u32}}) in sizing_type_of()
 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 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/diagnostic.rs:163

Testcase:

#![feature(overloaded_calls)]

use std::ops::FnMut;

pub struct Cumsum {
    v: int
}

impl FnMut<(int, ), int> for Cumsum
{
    fn call_mut(&mut self, (arg, ): (int, )) -> int {
        self.v += arg;
        self.v
    }
}

struct User<F> {
    f: F
}

impl<T: Add<T, T>, F: FnMut<(T, ), T>> User<F>
{
    fn next(&mut self, x: T) -> T {
        (self.f)(x)
    }
}

fn main()
{
    let mut user = User{f: Cumsum{v: 0}};
    let first = user.next(1);
}

Backtrace

task 'rustc' failed at 'Box<Any>', /home/rustbuild/src/rust-buildbot/slave/nightly-linux/build/src/libsyntax/diagnostic.rs:163

stack backtrace:
   1:     0x7f741ffd8ed0 - rt::backtrace::imp::write::h3e02102493c7a1b79Hp::v0.11.0.pre
   2:     0x7f741ffdfa00 - failure::on_fail::h73803e3fd7728138o3p::v0.11.0.pre
   3:     0x7f742213def0 - unwind::begin_unwind_inner::h66e3981eb8555b96cZd::v0.11.0.pre
   4:     0x7f74215864e0 - unwind::begin_unwind::h14114372353668361027::v0.11.0.pre
   5:     0x7f7421586e80 - diagnostic::Handler::bug::h163e51ddd1a017c2Dgc::v0.11.0.pre
   6:     0x7f7422a30520 - driver::session::Session::bug::h09f59f7b6f35750fdsr::v0.11.0.pre
   7:     0x7f7422a6d1e0 - middle::trans::type_of::sizing_type_of::h596bfec2e0619330HKl::v0.11.0.pre
   8:     0x7f7422bc6ce0 - middle::trans::adt::mk_struct::h5f80bd0c8a357283VNF::v0.11.0.pre
   9:     0x7f7422a787d0 - middle::trans::adt::represent_type::h089a2263bacd8707JrF::v0.11.0.pre
  10:     0x7f7422aa61c0 - middle::trans::expr::trans_rvalue_dps_unadjusted::h10d867840ebf8cbdivg::v0.11.0.pre
  11:     0x7f7422a61310 - middle::trans::expr::trans_into::hdc05c03d27b262d4JDf::v0.11.0.pre
  12:     0x7f7422a61940 - middle::trans::controlflow::trans_block::hf4faa65f79a4fae52ic::v0.11.0.pre
  13:     0x7f7422b27850 - middle::trans::base::trans_closure::hbab3416264edbe7aauq::v0.11.0.pre
  14:     0x7f7422a31790 - middle::trans::base::trans_fn::hd7d1d11484c269ccbCq::v0.11.0.pre
  15:     0x7f7422a32350 - middle::trans::monomorphize::monomorphic_fn::hf1e617671772921fkGb::v0.11.0.pre
  16:     0x7f7422a8cce0 - middle::trans::callee::trans_fn_ref_with_vtables::hcd28561a215ad27aYDe::v0.11.0.pre
  17:     0x7f7422a88110 - middle::trans::callee::trans_fn_ref::h9fdd39cf917745719pe::v0.11.0.pre
  18:     0x7f7422a9ca80 - middle::trans::meth::trans_method_callee::hbb7b4616681f8316ZCw::v0.11.0.pre
  19:     0x7f7422a9c9f0 - middle::trans::callee::trans_method_call::closure.81141
  20:     0x7f7422a95e10 - middle::trans::callee::trans_call_inner::h29fc42cbb279d858S1e::v0.11.0.pre
  21:     0x7f7422a9c380 - middle::trans::callee::trans_method_call::h0a1b75d4517517088We::v0.11.0.pre
  22:     0x7f7422aa61c0 - middle::trans::expr::trans_rvalue_dps_unadjusted::h10d867840ebf8cbdivg::v0.11.0.pre
  23:     0x7f7422a61310 - middle::trans::expr::trans_into::hdc05c03d27b262d4JDf::v0.11.0.pre
  24:     0x7f7422b6b000 - middle::trans::_match::store_local::closure.85655
  25:     0x7f7422b6acf0 - middle::trans::_match::mk_binding_alloca::h16257314354832004452::v0.11.0.pre
  26:     0x7f7422b21a70 - middle::trans::_match::store_local::h71f3ff230e537ab6JEu::v0.11.0.pre
  27:     0x7f7422a607e0 - middle::trans::base::init_local::he8478d5bef2cef9cOZp::v0.11.0.pre
  28:     0x7f7422a5fd40 - middle::trans::controlflow::trans_stmt::h77aa44239cd8a9d8Mdc::v0.11.0.pre
  29:     0x7f7422a61940 - middle::trans::controlflow::trans_block::hf4faa65f79a4fae52ic::v0.11.0.pre
  30:     0x7f7422b27850 - middle::trans::base::trans_closure::hbab3416264edbe7aauq::v0.11.0.pre
  31:     0x7f7422a31790 - middle::trans::base::trans_fn::hd7d1d11484c269ccbCq::v0.11.0.pre
  32:     0x7f7422a2a230 - middle::trans::base::trans_item::h40a4f8eccf6f8e7eCSq::v0.11.0.pre
  33:     0x7f7422b381b0 - middle::trans::base::trans_crate::h470bfcf3cac093e1JMr::v0.11.0.pre
  34:     0x7f742333d570 - driver::driver::phase_4_translate_to_llvm::h2fa30f4b120cdb579Aq::v0.11.0.pre
  35:     0x7f74233342b0 - driver::driver::compile_input::h1d313b682f9ead2bDeq::v0.11.0.pre
  36:     0x7f74234010c0 - driver::run_compiler::hcc8540f7b478ad28b0s::v0.11.0.pre
  37:     0x7f7423400fd0 - driver::main_args::closure.117522
  38:     0x7f74234160f0 - task::TaskBuilder<S>::try_future::closure.118663
  39:     0x7f7423415d10 - task::TaskBuilder<S>::spawn_internal::closure.118640
  40:     0x7f7422493590 - task::spawn_opts::closure.7462
  41:     0x7f7422196290 - rust_try
  42:     0x7f742213a500 - unwind::try::h800fde6f36f3558bBNd::v0.11.0.pre
  43:     0x7f742213a1e0 - task::Task::run::hf743f122a6385418XYc::v0.11.0.pre
  44:     0x7f7422493350 - task::spawn_opts::closure.7408
  45:     0x7f742213cda0 - thread::thread_start::hd9510588dd47efddvld::v0.11.0.pre
  46:     0x7f741fa4f000 - start_thread
  47:     0x7f7421e06039 - __clone
  48:                0x0 - <unknown>

cc @pcwalton

ghost commented 10 years ago

Doesn't ICE any more.

bluss commented 10 years ago

Thanks for the update. With extern "rust-call" the testcase even works as intended.