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

rustc runs out of memory when compiling an invalid macro #37113

Closed
jbendig opened this issue Oct 12, 2016 · 2 comments
Closed

rustc runs out of memory when compiling an invalid macro #37113

jbendig opened this issue Oct 12, 2016 · 2 comments

Comments

@jbendig
Copy link

jbendig commented Oct 12, 2016

Compiling this invalid macro code with rustc causes all system memory to be used up until the process is killed.

macro_rules! test_macro {
    ( $( $t:ty ),* $(),*) => {
        enum SomeEnum {
            $( $t, )*
        };
    };
}

fn main() {
    test_macro!(String,);
}

I expected rustc to display an error message and return immediately. Instead, an error message is reported and then rustc hangs and eats up all available system memory.

I tried both stable and nightly:

  • stable-x86_64-unknown-linux-gnu - rustc 1.12.0 (3191fba 2016-09-23)
  • nightly-x86_64-unknown-linux-gnu - rustc 1.14.0-nightly (a3bc191 2016-10-10)

I think this might be related to #33136.

@jonas-schievink
Copy link
Contributor

cc @TimNN, who I think has (had?) a fix for this

@TimNN
Copy link
Contributor

TimNN commented Oct 12, 2016

I'm pretty sure this is a different issue (here, OOM occurs due to the error), my fix for empty repetitions has been merged.

My guess is that this is somehow related to parser recovery.

goffrie added a commit to goffrie/rust that referenced this issue Oct 27, 2016
If we encounter a syntax error inside of a braced block, then we should
fail by consuming the rest of the block if possible.
This implements such recovery for enums and structs.

Fixes rust-lang#37113.
goffrie added a commit to goffrie/rust that referenced this issue Oct 27, 2016
If we can't make progress when parsing a macro expansion as a statement
then we should just bail.

This alleviates the symptoms shown in e.g. rust-lang#37113 but it doesn't fix the
problem that parsing invalid enum bodies (and others) leaves the parser
in a crappy state.
bors added a commit that referenced this issue Oct 27, 2016
Recover out of an enum or struct's braced block.

If we encounter a syntax error inside of a braced block, then we should
fail by consuming the rest of the block if possible.
This implements such recovery for enums and structs.

Fixes #37113.
bors added a commit that referenced this issue Nov 11, 2016
Don't spin expanding stmt macros.

If we can't make progress when parsing a macro expansion as a statement then we should just bail.

This alleviates the symptoms shown in e.g. #37113 and #37234 but it doesn't fix the problem that parsing invalid enum bodies (and others) leaves the parser in a crappy state.

I'm not sold on this strategy (checking `tokens_consumed`), so if anyone has a better idea, I'm all ears!
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