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

Compiling a match on [T, ..N] uses O(N) stack space in rustc, leading to stack overflow #17877

Closed
chris-morgan opened this issue Oct 8, 2014 · 7 comments · Fixed by #17944
Closed

Comments

@chris-morgan
Copy link
Member

Minimal test case:

fn main() {
    match [0u8, ..1024] {
        _ => (),
    }
}

If 1024 doesn’t do it for you, try bumping it upwards. 10000 ought to do it. Just don’t try numbers like a million or you’ll be waiting a while before it crashes. And if you have anything like systemd-coredump start automatically, it’ll be busy for a while as well… I guess there are a few areas where [T, ..N] is not handled well for large N.

(Additional keywords: sized array.)

@chris-morgan
Copy link
Member Author

Running it under GDB shows that it’s flipping back and forth between two functions recursively:

#1212 0x00007ffff7059117 in middle::trans::_match::compile_submatch::h29738c0eba38cea6HCh ()
   from /home/chris/opt/rust/lib/librustc-4e7c5e5c.so
#1213 0x00007ffff705f644 in middle::trans::_match::compile_submatch_continue::hf73ae30528589902sIh ()
   from /home/chris/opt/rust/lib/librustc-4e7c5e5c.so

Whatever this recursive algorithm is needs to be made non-recursive.

@pnkfelix pnkfelix changed the title Compiling a match on [T, ..N] uses O(N) stack space, leading to stack overflow Compiling a match on [T, ..N] uses O(N) stack space in rustc, leading to stack overflow Oct 9, 2014
@chrisdew
Copy link

chrisdew commented Oct 9, 2014

There is a slight difference between this minimal test case, and the original issue #17874.

If I reduce the size of the array to 10 bytes in #17874, compilation never completes (no error is raised).

If I reduce the size of the array in this test case to 10 bytes, it compiles.

@pnkfelix
Copy link
Member

pnkfelix commented Oct 9, 2014

@chrisdew could you try to narrow down the test from #17874 , in the manner that chris-morgan has done here, but preserving the behavioral difference you are observing?

@chrisdew
Copy link

chrisdew commented Oct 9, 2014

@pnkfelix I will try my best (this lunchtime), but I only have three hours experience with Rust so far. Every few lines of code written or modified requires 15 minutes of Googling the docs. (This learning curve is still much less steep than Haskell's was.)

@chris-morgan
Copy link
Member Author

@chrisdew: feel free to drop by irc://irc.mozilla.org/#rust, you’ll get any help you need there quickly.

@chrisdew
Copy link

chrisdew commented Oct 9, 2014

@pnkfelix I was mistaken. I had a subsequent, chained, command on the command line which produced no output and hung. I mistook this for the compiler hanging.

@pnkfelix
Copy link
Member

pnkfelix commented Oct 9, 2014

@chrisdew okay, great, thanks for the update! (I now feel better about asking you to do the narrowing rather than attempting to do it myself.) ;)

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

Successfully merging a pull request may close this issue.

3 participants