Reduce repetitions from long backtrace #28016
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.
This PR fixes #24592.
The stacktrace itself is not modified, but the printing function
show_backtrace
now shrinks repeated sequences of function calls into a single sequence, followed by a message stating how many times this sequence occurred in the backtrace. This works in a recursive fashion too and does not override the original optimization (for sequences of only one call), as the following example shows:This PR is not specific to StackOverflowError, it works with any showed backtrace. It should also work with backtraces from the compiler, such as a stack overflow during inference, but I did not test that.
Additionally, since the whole operation of detecting repetitions in backtraces can take some time, it is only triggered if the backtrace contains more than 50 function calls. This restriction (and the constant 50) can be changed of course, I just didn't know how desirable it was to impact small backtraces.
I took this opportunity to remove the side-effect function argument of
process_backtrace
since it could advantageously be replaced by a simple return value. This change is breaking butprocess_backtrace
is not exported and I couldn't find any use of it in the packages I had installed.