Skip to content

Infinite memory use with nested * repetition in macro #24858

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
ghost opened this issue Apr 27, 2015 · 4 comments
Closed

Infinite memory use with nested * repetition in macro #24858

ghost opened this issue Apr 27, 2015 · 4 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.

Comments

@ghost
Copy link

ghost commented Apr 27, 2015

Play rust link: http://is.gd/DVjBtk

macro_rules! a {(<$($($d:expr),*$($c:ident),*)*>) => (B<$($d,)*$($c,)*>);}a! (<>);
@Aatch Aatch changed the title Rustc are draining system memory when compiling with these code. Rustc is draining system memory when compiling this code. Apr 27, 2015
@Aatch Aatch added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) labels Apr 27, 2015
@huonw huonw changed the title Rustc is draining system memory when compiling this code. Infinite memory use with nested * repetition in macro Oct 12, 2015
@huonw
Copy link
Member

huonw commented Oct 12, 2015

Minimal example:

macro_rules! a {
    ($($($d:tt)*)*) => ();
}

a!();

@zakarumych
Copy link
Contributor

So problem code is double repetition?
Is there any workaround?

@jonas-schievink
Copy link
Contributor

I don't think the root problem is a double-repetition, but rather a repetition of something that can be 0 tokens long. In this case $($d:tt)* can contain 0 tokens, which then cause the memory explosion on the attempt to repeat it. Replacing the inner repetition with $($d:tt)+ prevents this bug, changing the outer repetition to use + doesn't.

See #28085, which I think is a duplicate of this (tl;dr: replacing the matcher with just $()+ or $()* also causes this).

@jonas-schievink
Copy link
Contributor

Also, this looks like a duplicate of #5067

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
Projects
None yet
Development

No branches or pull requests

5 participants