-
Notifications
You must be signed in to change notification settings - Fork 220
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
Change recursion checks to be rule based, better match the spec #443
Change recursion checks to be rule based, better match the spec #443
Conversation
if ctx == nil { | ||
return | ||
} | ||
ruleIndex := ctx.GetRuleIndex() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Speed-wise, it might make more sense to use map[int]*int. That way you do not need to do do both a lookup and insert into a map each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
if ctx == nil { | ||
return | ||
} | ||
ruleIndex := ctx.GetRuleIndex() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is safe. I remember having to put the increment after the recursion check. But looking at ANTLR Go, it appears that if EnterEveryRule panics, ExitEveryRule should not be called. Might want to double-check, otherwise things could go negative.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Added a defensive check since I'm using a pointer now as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, note that I added a check to validate that error recovery limits were being tested properly as well. I made a minor code change to prevent double-reporting of error recovery issues as a result of the test.
if ctx == nil { | ||
return | ||
} | ||
ruleIndex := ctx.GetRuleIndex() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. Added a defensive check since I'm using a pointer now as well.
if ctx == nil { | ||
return | ||
} | ||
ruleIndex := ctx.GetRuleIndex() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
PTAL |
The CEL spec indicates that the max recursion limit for any one grammar element
is effectively 32. At present, the current recursion limiting strategy employed by
the parser only checks for recursion at the top-level
expr
node, but recursion canalso occur within subrules like
calc
,member
, etc. The new strategy enforcesthe configured limit on a per-rule basis, rather than just for
expr
to account forrecursion in subrules.