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

cat_expr Errd on "fold" #25076

Closed
adinapoli opened this issue May 3, 2015 · 7 comments · Fixed by #25123
Closed

cat_expr Errd on "fold" #25076

adinapoli opened this issue May 3, 2015 · 7 comments · Fixed by #25123
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ P-medium Medium priority

Comments

@adinapoli
Copy link

Hello folks,

I'm dutifully reporting this as the compiler told me to so. The bug is the same reported already by #24504 and #22897, although it appeared on a different circumstance. I have this simple program (I'm a Rust newbie so It's very likely I'm doing things terribly wrong):

use std::io::*;

const initial_height: u32 = 1;

fn summer_growth(h: u32) -> u32 {
    h + 1
}

fn spring_growth(h: u32) -> u32 {
    h * 2
}

fn utopian_tree(cycles: u32) -> u32 {
    (0..cycles).fold(|acc, x| grow(acc,x), initial_height);
}

fn grow(acc: u32, cycle: u32) -> u32 {
    match cycle % 2 == 0 {
        true => spring_growth(acc),
        false => summer_growth(acc)
    }
}

fn main () {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    let test_cases: u32 = buf.trim().parse().unwrap();
    for _ in 0..test_cases {
        stdin().read_line(&mut buf).unwrap();
        let cycle: u32 = buf.trim().parse().unwrap();
        println!("{}", utopian_tree(cycle));
    }
}

Expected outcome:

  • The compile to tell me how wrong I am

Actual outcome:

☁  algorithms  rustc utopian_tree.rs -o utopian_tree
utopian_tree.rs:14:5: 14:59 error: internal compiler error: cat_expr Errd
utopian_tree.rs:14     (0..cycles).fold(|acc, x| grow(acc,x), initial_height);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/m
aster/CONTRIBUTING.md#bug-reports
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/
beta-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:149

Meta

☁  algorithms  rustc --version --verbose
rustc 1.0.0-beta.2 (e9080ec39 2015-04-16) (built 2015-04-16)
binary: rustc
commit-hash: e9080ec39d9a44eb0773d648b348575b19f655e5
commit-date: 2015-04-16
build-date: 2015-04-16
host: x86_64-apple-darwin
release: 1.0.0-beta.2
☁  algorithms

Shows up with latest beta as well:

☁  algorithms  rustc utopian_tree.rs -o utopian_tree
utopian_tree.rs:14:5: 14:59 error: internal compiler error: cat_expr Errd
utopian_tree.rs:14     (0..cycles).fold(|acc, x| grow(acc,x), initial_height);
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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
note: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'Box<Any>', /Users/rustbuild/src/rust-buildbot/slave/beta-dist-rustc-mac/build/src/libsyntax/diagnostic.rs:149


☁  algorithms  rustc --verbose --version
rustc 1.0.0-beta.4 (850151a75 2015-04-30) (built 2015-04-30)
binary: rustc
commit-hash: 850151a75709f146addd30bbbf1f23d384f0b381
commit-date: 2015-04-30
build-date: 2015-04-30
host: x86_64-apple-darwin
release: 1.0.0-beta.4
☁  algorithms
@pnkfelix
Copy link
Member

pnkfelix commented May 3, 2015

cc me

@nagisa
Copy link
Member

nagisa commented May 3, 2015

stack backtrace:
   1:     0x7f290f12bee9 - sys::backtrace::write::h9d474f8e9af32ff4eas
   2:     0x7f290f133a29 - panicking::on_panic::h780bc016e25d560eHOw
   3:     0x7f290f0f4a52 - rt::unwind::begin_unwind_inner::he10b5af763481bfaRtw
   4:     0x7f290c4e999d - rt::unwind::begin_unwind::h10007532221998759728
   5:     0x7f290c4e9932 - diagnostic::SpanHandler::span_bug::hdbc9b25081b2fe3dKWB
   6:     0x7f290d10f83d - session::Session::abort_if_errors::ha2c34f711c028133dJq
   7:     0x7f290e9d6f54 - check_crate::closure.38688
   8:     0x7f290e9d0180 - check_crate::h08a7388cd8cd25829BC
   9:     0x7f290f678bb8 - driver::phase_3_run_analysis_passes::h876ca40ef22f652btGa
  10:     0x7f290f659fec - driver::compile_input::h19dbb81f9d079a10Qba
  11:     0x7f290f712dc1 - run_compiler::h6fdcc5ae4819da2c65b
  12:     0x7f290f710612 - boxed::F.FnBox<A>::call_box::h15867338134671801927
  13:     0x7f290f70fbd9 - rt::unwind::try::try_fn::h10571205104630549427
  14:     0x7f290f1a72f8 - rust_try_inner
  15:     0x7f290f1a72e5 - rust_try
  16:     0x7f290f70fe74 - boxed::F.FnBox<A>::call_box::h11752498478748955554
  17:     0x7f290f1327c1 - sys::thread::Thread::new::thread_start::h9f92b31902592327dAv
  18:     0x7f29091e5373 - start_thread
  19:     0x7f290ed8827c - clone
  20:                0x0 - <unknown>

@arielb1
Copy link
Contributor

arielb1 commented May 3, 2015

Minified:

fn utopian_tree(cycles: u32) {
    <_>::fold((cycles..), ||{}, ());
}

We do write ty_err to node 11 (<_>::fold((cycles..), || { }, ()))). Apparently we somehow don't report an error.

@jdm jdm added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label May 4, 2015
@pnkfelix
Copy link
Member

pnkfelix commented May 4, 2015

triage: P-medium

@rust-highfive rust-highfive added the P-medium Medium priority label May 4, 2015
@arielb1
Copy link
Contributor

arielb1 commented May 4, 2015

Whoops. There is indeed an error, which is indeed gets to report_selection_error, but when we do resolve_type_vars_if_possible (error_reporting.rs:184), we get an error, and think this one was a duplicate.

@arielb1
Copy link
Contributor

arielb1 commented May 4, 2015

no_std version:

#![feature(no_std,lang_items)]
#![no_std]
#![crate_type="rlib"]

#[lang="sized"] pub trait Sized {}

struct S;

trait InOut<T> { type Out; }

impl MIterator<u32> for S {}

trait MIterator<T> : Sized {
    fn _fold<B, F: InOut<B, Out=B>>(self, init: B, f: F) -> B { loop {} }
}

fn bot<T>() -> T { loop {} }

fn utopian_tree() {
    <S as MIterator<u32>>::_fold(S, bot(), ());
}

fn main() {}

@arielb1
Copy link
Contributor

arielb1 commented May 5, 2015

You don't even need the trait:

struct S;

trait InOut<T> { type Out; }

fn do_fold<B, F: InOut<B, Out=B>>(init: B, f: F)  { }

fn bot<T>() -> T { loop {} }

fn main() {
    do_fold(bot(), ());
}

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) ❄️ P-medium Medium priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants