Skip to content

internal compiler error #18057

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
potan opened this issue Oct 15, 2014 · 6 comments
Closed

internal compiler error #18057

potan opened this issue Oct 15, 2014 · 6 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@potan
Copy link

potan commented Oct 15, 2014

error: internal compiler error: type_of with ty_param
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/pm/lang/rust/rust/src/libsyntax/diagnostic.rs:169

stack backtrace:
   1:     0x7fdc7b12c500 - rt::backtrace::imp::write::h1477ac29053ece3cgDq
   2:     0x7fdc7b12f630 - failure::on_fail::h090bf222fe08db7cDYq
   3:     0x7fdc7b8f6430 - unwind::begin_unwind_inner::h51916ee1d5d0deddGxd
   4:     0x7fdc77529790 - unwind::begin_unwind::h15240260624484748152
   5:     0x7fdc77529e70 - diagnostic::Handler::bug::had6fd9d040101c34hRF
   6:     0x7fdc7bcda490 - driver::session::Session::bug::h85ae544149280a1fTey
   7:     0x7fdc7c0b80e0 - middle::trans::type_of::type_of::h3c358519e57ad9e6Zxa
   8:     0x7fdc7c0b80e0 - middle::trans::type_of::type_of::h3c358519e57ad9e6Zxa
   9:     0x7fdc7c0b80e0 - middle::trans::type_of::type_of::h3c358519e57ad9e6Zxa
  10:     0x7fdc7c1d9270 - middle::trans::adt::struct_llfields::h6d3c4aa8a91bfda3sIu
  11:     0x7fdc7c13ec20 - middle::trans::adt::finish_type_of::h54eeac837f85766amwu
  12:     0x7fdc7c0b80e0 - middle::trans::type_of::type_of::h3c358519e57ad9e6Zxa
  13:     0x7fdc7c0b80e0 - middle::trans::type_of::type_of::h3c358519e57ad9e6Zxa
  14:     0x7fdc7c0fa410 - middle::trans::expr::trans_uniq_expr::h5a4901312595da40iC5
  15:     0x7fdc7c0face0 - middle::trans::expr::trans_unary::h7f46b3d2ee23e0f1oy5
  16:     0x7fdc7c0f0000 - middle::trans::expr::trans_unadjusted::he0f7295d106fefd2Zd4
  17:     0x7fdc7c0b3810 - middle::trans::expr::trans::haaafc6b790c7b639Vw3
  18:     0x7fdc7c0b22c0 - middle::trans::expr::trans_into::h3d5706a30846aafa1s3
  19:     0x7fdc7c0b26e0 - middle::trans::controlflow::trans_block::hd5280d031efda9d6lGZ
  20:     0x7fdc7c162fe0 - middle::trans::base::trans_closure::h0a7f4de06bee1c8cXBf
  21:     0x7fdc7c0a41f0 - middle::trans::base::trans_fn::h8f8a2c035208e8d7lNf
  22:     0x7fdc7c0a48e0 - middle::trans::monomorphize::monomorphic_fn::h2dc0c402c9883ce927Y
  23:     0x7fdc7c0dc660 - middle::trans::callee::trans_fn_ref_with_substs::hdd194b502b4a58441m2
  24:     0x7fdc7c0d9c80 - middle::trans::callee::trans_fn_ref::h4330edb19ab1b6e6zb2
  25:     0x7fdc7c0e2570 - middle::trans::callee::trans_call::closure.124125
  26:     0x7fdc7c0ba020 - middle::trans::callee::trans_call_inner::hcbca3b6787659c03JI2
  27:     0x7fdc7c0e22c0 - middle::trans::callee::trans_call::h9fcac721e6cb55314C2
  28:     0x7fdc7c0f13c0 - middle::trans::expr::trans_rvalue_dps_unadjusted::hd9a2a83d30d7aaeftR4
  29:     0x7fdc7c0b22c0 - middle::trans::expr::trans_into::h3d5706a30846aafa1s3
  30:     0x7fdc7c191c90 - middle::trans::_match::store_local::closure.128240
  31:     0x7fdc7c191a80 - middle::trans::_match::mk_binding_alloca::h482564913738985314
  32:     0x7fdc7c1597e0 - middle::trans::_match::store_local::h3d0fc4ae7771500aNZi
  33:     0x7fdc7c0b18a0 - middle::trans::base::init_local::h2cb16046bc383b89xKe
  34:     0x7fdc7c0b0c60 - middle::trans::controlflow::trans_stmt::h4f1b84665f48152afBZ
  35:     0x7fdc7c0b26e0 - middle::trans::controlflow::trans_block::hd5280d031efda9d6lGZ
  36:     0x7fdc7c162fe0 - middle::trans::base::trans_closure::h0a7f4de06bee1c8cXBf
  37:     0x7fdc7c0a41f0 - middle::trans::base::trans_fn::h8f8a2c035208e8d7lNf
  38:     0x7fdc7c0a1850 - middle::trans::base::trans_item::h5de357321a9ed4f6E6f
  39:     0x7fdc7c16e5a0 - middle::trans::base::trans_crate::hc46c87ff47e81464a5g
  40:     0x7fdc7c5bfb70 - driver::driver::phase_4_translate_to_llvm::h045fe4f7e55962abvFx
  41:     0x7fdc7c5b5e70 - driver::driver::compile_input::hf1074c4e89201e93qcx
  42:     0x7fdc7c6412a0 - driver::run_compiler::h0ecb6658398d53f6J0A
  43:     0x7fdc7c641150 - driver::run::closure.147558
  44:     0x7fdc7bd09cd0 - task::TaskBuilder<S>::try_future::closure.101668
  45:     0x7fdc7bd09ab0 - task::TaskBuilder<S>::spawn_internal::closure.101639
  46:     0x7fdc7ceb1120 - task::spawn_opts::closure.8447
  47:     0x7fdc7b9503e0 - rust_try_inner
  48:     0x7fdc7b9503d0 - rust_try
  49:     0x7fdc7b8f3cf0 - unwind::try::h15600d03dfaaa405omd
  50:     0x7fdc7b8f3b70 - task::Task::run::h2760aad0762be53e2Bc
  51:     0x7fdc7ceb0e60 - task::spawn_opts::closure.8387
  52:     0x7fdc7b8f5440 - thread::thread_start::h7a688dc7bb49fbdedWc
  53:     0x7fdc7abf3ec0 - start_thread
  54:     0x7fdc7b5b99d9 - __clone
  55:                0x0 - <unknown>

while compile code:

#![feature(unboxed_closures, overloaded_calls, unboxed_closure_sugar)]

pub trait Seq<T> {
    fn pop(self) -> Result<(T, Self, Self), Self>;
}

impl<'a> Seq<char> for &'a str {
    fn pop(self) -> Result<(char, &'a str, &'a str), &'a str> {
        if self.is_empty() {
            Err(self)
        } else {
            Ok((self.char_at(0), self, self.slice_from(1)))
        }
    }
}

type ParseResult<S /*:Seq<C>*/,T> = Result<(T, S, S),S>;
type Parser<S /*:Seq<C>*/,T> = Box<|&: S| -> ParseResult<S /*:Seq<C>*/,T>>;

fn elem<T, S:Seq<T>, Res>(e:Box<|&: T| -> Option<Res>>) -> Parser<S, Res> {
  box |&: s:S| {
    match s.pop() {
      Err(b) => Err(b),
      Ok((c, b, n)) => match e.call((c,)) {
                         Some(r) => Ok((r, b, n)),
                         None => Err(b)
                       }
    }
  }
}

fn concat<C,S:Seq<C>,T1,T2>(p1: Parser<S, T1>, p2: Parser<S, T2>) -> Parser<S,(T1,T2)> {
  box |&: s:S| {
    match p1.call((s,)) {
       Err(b) => Err(b),
       Ok((r1, b, n1)) => {
         match p2.call((n1,)) {
            Err(_) => Err(b),
            Ok((r2, _, n2)) => Ok(((r1,r2), b, n2))
         }
       }
    }
  }
}

fn alter<C,S:Seq<C>,T>(p1: Parser<S, T>, p2: Parser<S, T>) -> Parser<S, T> {
  box |&: s:S| {
    match p1.call((s,)) {
       Err(b) => p2.call((b,)),
       r => r
    }
  }
}

fn digit(r:&int) -> Box<|&: char| -> Option<int>> {
  box |&: c:char| {
   let i = match c {
             '0'...'9' => { c as int - '0' as int },
             'a'...'z' => { 10 + c as int - 'a' as int },
             'A'...'Z' => { 10 + c as int - 'A' as int },
             _ => *r
           };
   if i < *r {
    Some(i)
   } else {
    None
   }
  }
}

fn do_fold<S,T,R>(p:&Parser<S,T>, l:&Box<|&: T,R| -> R>, b:S, i:R, s:S) -> ParseResult<S,R> {
  match p.call((s,)) {
    Err(n) => Ok((i,b,n)),
    Ok((r,_,n)) => {
      let v = l.call((r,i));
      do_fold(p,l,b,v,n)
    }
  }
}

fn fold1<S,T,R:Clone>(p:Parser<S,T>, l: Box<|&: T,R| -> R>, i:R) -> Parser<S,R> {
  box |&: s:S| {
    match p.call((s,)) {
      Err(e) => Err(e),
      Ok((r,b,n)) => {
        let v = l.call((r,i.clone()));
        do_fold(&p,&l,b,v,n)
      }
    }
  }
}

fn main() {
    static RADIX:int = 13;
    let p1 = fold1(elem(digit(&RADIX)), box |&: c:int, v:int| -> int {v*RADIX+c}, 0i) ;
    let p2 = alter(elem(box |&: c:char| { if c == 'z' { Some('Z') } else { None } }),
                   elem(box |&: c:char| { if c == 'w' { Some('W') } else { None } })) ;
    println!("{}", concat(p1, p2).call(("1awert",)));
}
@aturon aturon mentioned this issue Oct 16, 2014
47 tasks
@bkoropoff
Copy link
Contributor

The code is garbled, but the backtrace and error look related to #16791

@bkoropoff
Copy link
Contributor

@potan, can you re-test on the latest master now that the fix for #16791 went in?

@potan
Copy link
Author

potan commented Oct 29, 2014

Internal compiler error has fixed.
Now rustc outputs "error: cannot infer an appropriate lifetime due to conflicting requirements", but earlier this code worked :-).

@bkoropoff
Copy link
Contributor

One problem is that unboxed closures now default to by-ref capture where previously it was by move. After sprinkling the move keyword around, there were a few legitimate lifetime errors and missing bounds. After fixing them up it builds and runs. This bug can be closed.

#![feature(unboxed_closures, overloaded_calls, unboxed_closure_sugar)]

pub trait Seq<T> {
    fn pop(self) -> Result<(T, Self, Self), Self>;
}

impl<'a> Seq<char> for &'a str {
    fn pop(self) -> Result<(char, &'a str, &'a str), &'a str> {
        if self.is_empty() {
            Err(self)
        } else {
            Ok((self.char_at(0), self, self.slice_from(1)))
        }
    }
}

type ParseResult<S,T> = Result<(T, S, S),S>;
type Parser<S,T> = Box<|&: S| -> ParseResult<S,T>>;

fn elem<T, S:Seq<T>, Res>(e:Box<|&: T| -> Option<Res>>) -> Parser<S, Res> {
  box move |&: s:S| {
    match s.pop() {
      Err(b) => Err(b),
      Ok((c, b, n)) => match e.call((c,)) {
        Some(r) => Ok((r, b, n)),
        None => Err(b)
      }
    }
  }
}

fn concat<C,S:Seq<C>,T1,T2>(p1: Parser<S, T1>, p2: Parser<S, T2>) -> Parser<S,(T1,T2)> {
  box move |&: s:S| {
    match p1.call((s,)) {
       Err(b) => Err(b),
       Ok((r1, b, n1)) => {
         match p2.call((n1,)) {
            Err(_) => Err(b),
            Ok((r2, _, n2)) => Ok(((r1,r2), b, n2))
         }
       }
    }
  }
}

fn alter<C,S:Seq<C>,T>(p1: Parser<S, T>, p2: Parser<S, T>) -> Parser<S, T> {
  box move |&: s:S| {
    match p1.call((s,)) {
       Err(b) => p2.call((b,)),
       r => r
    }
  }
}

fn digit(r:&int) -> Box<|&: char| -> Option<int>> {
  let r = *r;
  box move |&: c:char| {
   let i = match c {
     '0'...'9' => { c as int - '0' as int },
     'a'...'z' => { 10 + c as int - 'a' as int },
     'A'...'Z' => { 10 + c as int - 'A' as int },
     _ => r
   };
   if i < r {
    Some(i)
   } else {
    None
   }
  }
}

fn do_fold<S,T,R>(p:&Parser<S,T>, l:&Box<|&: T,R| -> R>, b:S, i:R, s:S) -> ParseResult<S,R> {
  match p.call((s,)) {
    Err(n) => Ok((i,b,n)),
    Ok((r,_,n)) => {
      let v = l.call((r,i));
      do_fold(p,l,b,v,n)
    }
  }
}

fn fold1<S,T,R:Clone+'static>(p:Parser<S,T>, l: Box<|&: T,R| -> R>, i:R) -> Parser<S,R> {
  box move |&: s:S| {
    match p.call((s,)) {
      Err(e) => Err(e),
      Ok((r,b,n)) => {
        let v = l.call((r,i.clone()));
        do_fold(&p,&l,b,v,n)
      }
    }
  }
}

fn main() {
    static RADIX:int = 13;
    let p1 = fold1(elem(digit(&RADIX)), box |&: c:int, v:int| -> int {v*RADIX+c}, 0i) ;
    let p2 = alter(elem(box |&: c:char| { if c == 'z' { Some('Z') } else { None } }),
                   elem(box |&: c:char| { if c == 'w' { Some('W') } else { None } })) ;
    println!("{}", concat(p1, p2).call(("1awert",)));
}

@nodakai
Copy link
Contributor

nodakai commented Dec 21, 2014

@aturon Can you check the status of this issue? Seems like you can close this

@sfackler sfackler added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Dec 21, 2014
@nikomatsakis
Copy link
Contributor

Going to close this on basis of @bkoropoff's comments. Re-open if you think there is still a problem.

lnicola pushed a commit to lnicola/rust that referenced this issue Sep 25, 2024
…ykril

internal: Better testing infra for ratoml

This PR makes some improvements on how we test configs that come from `rust-analyzer.toml` files.
It was primarily used to solve rust-lang#18021 but along the way I could not really determine the cause of the said issue which makes me think that it may not be related to the changes that I made earlier to the ratoml infra. In either way `custom_snippets` are now made `global` because we still don't have a tree that maps a `SourceRootId` to a set of `Snippet`s.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants