Use forward traversal for unconditional recursion lint #70973
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While reviewing #70822, I noted that #54444 could be solved without requiring the predecessor graph and without allocating a
Vec<Span>
for every basic block. The unconditional recursion lint is not a performance bottleneck however, so I approved #70822 as it was.Nevertheless, I wanted to try implementing my idea using
TriColorDepthFirstSearch
, which is a DFS that can differentiate between forward/tree edges and backward ones. I found this approach more straightforward than the existing one, so I'm opening this PR to see if it is desirable.The pass is now just a DFS across the control-flow graph. We ignore false edges and false unwinds, as well as the successors of recursive calls, just like existing pass does. If we see a back-edge (loop) or a terminator that would cause us to yield control-flow back to the caller (
Return
,Resume
, etc.), we know that the function does not unconditionally recurse.r? @jonas-schievink