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

Suspected compiler bug: task 'rustc' has overflowed its stack #17874

Closed
chrisdew opened this issue Oct 8, 2014 · 1 comment
Closed

Suspected compiler bug: task 'rustc' has overflowed its stack #17874

chrisdew opened this issue Oct 8, 2014 · 1 comment

Comments

@chrisdew
Copy link

chrisdew commented Oct 8, 2014

The following code results in:

   Compiling chat v0.1.0 (file:///home/chris/rust/chat)
task 'rustc' has overflowed its stack
Could not compile `chat`.
use std::io::{TcpListener, TcpStream};
use std::io::{Acceptor, Listener};

enum StreamOrSlice {
     Strm(TcpStream),
     Slc(uint, [u8, ..1024])
}

fn main() {
    let listener = TcpListener::bind("127.0.0.1", 5555);

    // bind the listener to the specified address
    let mut acceptor = listener.listen();

    let (tx, rx) = channel();

    spawn(proc() {
        let mut streams: Vec<TcpStream> = Vec::new();
        loop {
            let rxd: StreamOrSlice = rx.recv();
            match rxd {
                Strm(stream) => {
                    streams.push(stream);
                }
                Slc(len, buf) => {
                    for stream in streams.iter_mut() {
                        let _ = stream.write(buf.slice(0, len));
                    }
                }
            }
        }
    });

    // accept connections and process them, spawning a new tasks for each one
    for stream in acceptor.incoming() {
        match stream {
            Err(e) => { /* connection failed */ }
            Ok(mut stream) => {
                // connection succeeded
                tx.send(Strm(stream.clone()));
                let tx2 = tx.clone();
                spawn(proc() {
                    let mut buf: [u8, ..1024] = [0, ..1024];
                    loop {
                        let len = stream.read(buf);
                        tx2.send(Slc(len.unwrap(), buf));
                    }
                })
            }
        }
    }
}

P.S.

chris@grey:~$ rustc --version
rustc 0.12.0-nightly (a70a0374e 2014-10-01 21:27:19 +0000)
@chrisdew chrisdew changed the title Suspected compiler bug: Suspected compiler bug: task 'rustc' has overflowed its stack Oct 8, 2014
@chris-morgan
Copy link
Member

The actual problem being exposed here is the match on [u8, ..1024] which I reported as #17877.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants