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
Memory leakage when applying recursive combinators #884
Comments
Hello, Thanks for the report! Would you have, by any chance, more information? For example, and simple self-contained |
I've been looking at this a bit. The "leak" looks to me more like an infinite recursion, and it's during parser generation, rather than an issue in the generated parser. Just dropping the provided grammar in a file, and running It seems to be something about the fact that the recursive macro expansion isn't just passing through the args. Replacing I haven't looked at the macro expansion code much in the past, so I'm still trying to get my head around what we do there to figure out what's going wrong. |
I think this is a fundamental limitation of how lalrpop implements macros. lalrpop macros resolve the generic arguments into the actual callers, then treats every resolved generic as a grammar nonterminal. So, for example Common recursive macros, such as the ones http://lalrpop.github.io/lalrpop/tutorial/006_macros.html terminate because once we resolve the generics in the macro definition, we end up with a nonterminal we already have (for example the macro def for I think that rewriting the grammar to treat the generic as a nonterminal would work. Something like:
That errors, because the original grammar is invalid totally besides this issue, but it doesn't recurse infinitely. I'm not really sure about the following two questions:
I'm out of time for today, but I might try to put together a proof of concept for the above approach in a few days, and we could discuss the above questions in PR discussion. I'm curious if anyone has any other thoughts or things I'm missing in the interim though. |
If we took inspiration from |
Yeah, it's crude, and I was initially opposed, but as I thought on it, I think trying to do true detection is probably too big of a can of worms, and as you said, just detecting deep recurion is minimally invasive. I submitted #896 doing the recursion counting approach. Let me know what you think. |
Fixed with #896 |
lalrpop version: 0.20.0 ~ 0.20.2
The text was updated successfully, but these errors were encountered: