-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Macro recursion limit is still too low #38541
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
Comments
You don't need to define your own vec, simply up the recursion limit. Put That said (1) |
I put the attribute with some insanely high number (10k or something) in my own crate and it still hit the recursion limit. Ultimately I decided to just keep the boilerplate as editing the datastructure is not exactly fast or pleasant, and it's easy to mess up to boot. That said, I would still like the recursion limit to either be raised to some really high number (e.g. 10k) or just to disappear at all. The fact that it even exists is I think more of a necessary (for now) evil, as with traversers (e.g. macros) this isn't something I intuitively think of. In fact Rust is the first language I've used that actually limits how far the code can recurse, apparently with the goal of guaranteeing that compilation actually completes. if I'm correct, I'd still choose letting go the recursion limit as even with the attribute it can still give rise to problems. On top of that, you'll likely notice if the code either 1. doesn't compile and errors out or 2. takes an extraordinary amount of time to complete e.g. 10 minutes or more for a "Hello world" style program. |
Just to make sure, did you use the attribute form with the |
If increasing the limit to a ridiculous number doesn't resolve the problem, that's a clue that you might actually have unbounded recursion ( |
I guess we'll need to see the code at this point. If a non-recursive macro can trigger the recursion limit, there is a problem somewhere. That said, I just checked and you don't need a nightly to use |
Fair warning, it's pretty huge. But I can't and won't split it up since it's a parse tree resulting from a grammar I did not define (i.e. the xquery grammar).
Please let me know if you have any questions and I'll do my best to answer them. let expected = Node::new(ComparisonExpr).children(vec![
Node::new(StringConcatExpr).children(vec![
Node::new(RangeExpr).children(vec![
Node::new(AdditiveExpr).children(vec![
Node::new(MultiplicativeExpr).children(vec![
Node::new(UnionExpr).children(vec![
Node::new(IntersectExceptExpr).children(vec![
Node::new(InstanceofExpr).children(vec![
Node::new(TreatExpr).children(vec![
Node::new(CastableExpr).children(vec![
Node::new(CastExpr).children(vec![
Node::new(ArrowExpr).children(vec![
Node::new(UnaryExpr).children(vec![
Node::new(ValueExpr).children(vec![
Node::new(SimpleMapExpr).children(vec![
Node::new(PathExpr).children(vec![
Node::new(RelativePathExpr).children(vec![
Node::new(StepExpr).children(vec![
Node::new(PostfixExpr).children(vec![
Node::new(PrimaryExpr).children(vec![
Node::new(VarRef).children(vec![
Node::new(Operator).data("$"),
Node::new(VarName).data("CashFlowOperatingActivities"), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]),
Node::new(Meta(Opt)).children(vec![
Node::new(Meta(Seq)).children(vec![
Node::new(Whitespace).data(" "),
Node::new(Meta(Or)).children(vec![
Node::new(GeneralComp).children(vec![
Node::new(Operator).data("="), ]), ]),
Node::new(Whitespace).data(" \n"),
Node::new(StringConcatExpr).children(vec![
Node::new(RangeExpr).children(vec![
Node::new(AdditiveExpr).children(vec![
Node::new(MultiplicativeExpr).children(vec![
Node::new(UnionExpr).children(vec![
Node::new(IntersectExceptExpr).children(vec![
Node::new(InstanceofExpr).children(vec![
Node::new(TreatExpr).children(vec![
Node::new(CastableExpr).children(vec![
Node::new(CastExpr).children(vec![
Node::new(ArrowExpr).children(vec![
Node::new(UnaryExpr).children(vec![
Node::new(Meta(MultStar)).children(vec![
Node::new(Meta(Or)).children(vec![
Node::new(Operator).data("-"), ]),
Node::new(Meta(Opt)).children(vec![
Node::new(Meta(Seq)).children(vec![
Node::new(Whitespace).data(" "), ]), ]), ]),
Node::new(ValueExpr).children(vec![
Node::new(SimpleMapExpr).children(vec![
Node::new(PathExpr).children(vec![
Node::new(RelativePathExpr).children(vec![
Node::new(StepExpr).children(vec![
Node::new(PostfixExpr).children(vec![
Node::new(PrimaryExpr).children(vec![
Node::new(FunctionCall).children(vec![
Node::new(EQName).children(vec![
Node::new(QName).children(vec![
Node::new(UnprefixedName).data("sum"), ]), ]),
Node::new(ArgumentList).children(vec![
Node::new(Delimiter).data("("),
Node::new(Meta(Opt)).children(vec![
Node::new(Meta(Seq)).children(vec![
Node::new(Argument).children(vec![
Node::new(ExprSingle).children(vec![
Node::new(OrExpr).children(vec![
Node::new(AndExpr).children(vec![
Node::new(ComparisonExpr).children(vec![
Node::new(StringConcatExpr).children(vec![
Node::new(RangeExpr).children(vec![
Node::new(AdditiveExpr).children(vec![
Node::new(MultiplicativeExpr).children(vec![
Node::new(UnionExpr).children(vec![
Node::new(IntersectExceptExpr).children(vec![
Node::new(InstanceofExpr).children(vec![
Node::new(TreatExpr).children(vec![
Node::new(CastableExpr).children(vec![
Node::new(CastExpr).children(vec![
Node::new(ArrowExpr).children(vec![
Node::new(UnaryExpr).children(vec![
Node::new(ValueExpr).children(vec![
Node::new(SimpleMapExpr).children(vec![
Node::new(PathExpr).children(vec![
Node::new(RelativePathExpr).children(vec![
Node::new(StepExpr).children(vec![
Node::new(PostfixExpr).children(vec![
Node::new(PrimaryExpr).children(vec![
Node::new(VarRef).children(vec![
Node::new(Operator).data("$"),
Node::new(VarName).data("varArc_ConsolidatedCashFlowStatement_MsgConsolidatedSumOfChildrenParentDebit1_ChildrenOfCashFlowOperatingActivitiesCredit"), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]),
Node::new(Delimiter).data(")"), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]),
Node::new(Meta(MultStar)).children(vec![
Node::new(Meta(Opt)).children(vec![
Node::new(Meta(Seq)).children(vec![
Node::new(Whitespace).data(" \n"), ]), ]),
Node::new(Meta(Or)).children(vec![
Node::new(Operator).data("+"), ]),
Node::new(Meta(Opt)).children(vec![
Node::new(Meta(Seq)).children(vec![
Node::new(Whitespace).data(" "), ]), ]),
Node::new(MultiplicativeExpr).children(vec![
Node::new(UnionExpr).children(vec![
Node::new(IntersectExceptExpr).children(vec![
Node::new(InstanceofExpr).children(vec![
Node::new(TreatExpr).children(vec![
Node::new(CastableExpr).children(vec![
Node::new(CastExpr).children(vec![
Node::new(ArrowExpr).children(vec![
Node::new(UnaryExpr).children(vec![
Node::new(ValueExpr).children(vec![
Node::new(SimpleMapExpr).children(vec![
Node::new(PathExpr).children(vec![
Node::new(RelativePathExpr).children(vec![
Node::new(StepExpr).children(vec![
Node::new(PostfixExpr).children(vec![
Node::new(PrimaryExpr).children(vec![
Node::new(FunctionCall).children(vec![
Node::new(EQName).children(vec![
Node::new(QName).children(vec![
Node::new(UnprefixedName).data("sum"), ]), ]),
Node::new(ArgumentList).children(vec![
Node::new(Delimiter).data("("),
Node::new(Meta(Opt)).children(vec![
Node::new(Meta(Seq)).children(vec![
Node::new(Argument).children(vec![
Node::new(ExprSingle).children(vec![
Node::new(OrExpr).children(vec![
Node::new(AndExpr).children(vec![
Node::new(ComparisonExpr).children(vec![
Node::new(StringConcatExpr).children(vec![
Node::new(RangeExpr).children(vec![
Node::new(AdditiveExpr).children(vec![
Node::new(MultiplicativeExpr).children(vec![
Node::new(UnionExpr).children(vec![
Node::new(IntersectExceptExpr).children(vec![
Node::new(InstanceofExpr).children(vec![
Node::new(TreatExpr).children(vec![
Node::new(CastableExpr).children(vec![
Node::new(CastExpr).children(vec![
Node::new(ArrowExpr).children(vec![
Node::new(UnaryExpr).children(vec![
Node::new(ValueExpr).children(vec![
Node::new(SimpleMapExpr).children(vec![
Node::new(PathExpr).children(vec![
Node::new(RelativePathExpr).children(vec![
Node::new(StepExpr).children(vec![
Node::new(PostfixExpr).children(vec![
Node::new(PrimaryExpr).children(vec![
Node::new(VarRef).children(vec![
Node::new(Operator).data("$"),
Node::new(VarName).data("varArc_ConsolidatedCashFlowStatement_MsgConsolidatedSumOfChildrenParentDebit1_ChildrenOfCashFlowOperatingActivitiesDebit"), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]),
Node::new(Delimiter).data(")"), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]), ]); |
It looks like you're using trailing commas. That's the case where the |
Maybe we can make the recursion detection somehow detect nested macro invocations in the original source code. That case feels like something the author intended (and can't really be infinitely recursive, which AFAIK is what we're trying to prevent). |
We need a way to reproduce this issue. I don't think recursion limit behaves in the way it has been described here. |
@bluss What form do you prefer? |
Gist is great! |
This gist demonstrates the issue nicely. I tested it on the playground and there I can reproduce the issue. |
Thank you! Raising the recursion limit removes the recursion limit error (playground link), so that seems to be as expected. However, there is a regression here: It used to recommend raising the recursion limit, but it does not. |
Okay, so this is literally caused by manually nesting too many macro calls,
not by a malformed macro. The only recourse is raising the recursion limit
(which should be possible now due to the many amazing optimizations by
@jseyfried).
…On Thu, Jan 5, 2017 at 12:56 PM, bluss ***@***.***> wrote:
Raising the recursion limit removes the recursion limit error (playground
link)
<https://play.rust-lang.org/?gist=a7fa712d3a5f2021ed396671781508c4&version=stable&backtrace=0>,
so that seems to be as expected.
However, there is a regression here: It used to recommend raising the
recursion limit, but it does not.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#38541 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC3n-ubTJZD7WabxD2bfxhhXlZK8pm2ks5rPS64gaJpZM4LT46p>
.
|
The reporter seemed to say raising the recursion limit didn't help, but it does with the code in the gist. What I can see, the reported issue does not exist. On raising the limit, I'm in favour. |
Since we seem to believe that the author's problem was presumably fixable via recursion limit raising, but we do want to increase the macro recursion limit, I'm going to close this in favor of #22552, the original macro recursion limit raising issue. |
I've seen this issue, and since it's closed I've decided to open a new one.
I have just hit this limit. The problem for me is that I hit it while using
std::vec!
, and AFAICT the only way to accommodate more elements is not just by specifying#[recursion_limit = "10000"]
but also defining my own version ofvec!
since otherwise the defaultvec!
macro will simply ignore the attribute as it's not defined in my crate.I don't believe it's a good idea for Rust programmers to have to define their own versions of definitions in
std
, hence the issue.The text was updated successfully, but these errors were encountered: