Skip to content

Reduce repetitions from long backtrace #28016

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

Merged
merged 1 commit into from
Jul 11, 2018

Conversation

Liozou
Copy link
Member

@Liozou Liozou commented Jul 9, 2018

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:

begin_loop() = a(120)
a(n) = n==0 ? switch_loop() : b(n-1)  # a calls b
b(n) = n==0 ? switch_loop() : c(n-1)  # b calls c
c(n) = n==0 ? switch_loop() : a(n-1)  # c calls a
switch_loop() = d(10)
d(n) = n==0 ? restart_loop() : d(n-1)  # d calls itself (old optimization)
restart_loop() = begin_loop() # big loop that encompasses the different cycles and stack overflows

julia> begin_loop()
ERROR: StackOverflowError:
Stacktrace:
 [1] c(::Int64) at ./REPL[4]:1
 [2] b(::Int64) at ./REPL[3]:1
 [3] a(::Int64) at ./REPL[2]:1
 ... (the last 3 lines are repeated 4 more times)
 [16] begin_loop() at ./REPL[1]:1
 [17] restart_loop() at ./REPL[7]:1
 [18] d(::Int64) at ./REPL[6]:1 (repeats 11 times)
 [19] switch_loop() at ./REPL[5]:1
 [20] a(::Int64) at ./REPL[2]:1
 [21] c(::Int64) at ./REPL[4]:1
 [22] b(::Int64) at ./REPL[3]:1
 ... (the last 3 lines are repeated 39 more times)
 [140] a(::Int64) at ./REPL[2]:1
 ... (the last 125 lines are repeated 591 more times)
 [74016] begin_loop() at ./REPL[1]:1
 [74017] restart_loop() at ./REPL[7]:1
 [74018] d(::Int64) at ./REPL[6]:1 (repeats 11 times)
 [74019] switch_loop() at ./REPL[5]:1
 [74020] a(::Int64) at ./REPL[2]:1
 [74021] c(::Int64) at ./REPL[4]:1
 [74022] b(::Int64) at ./REPL[3]:1
 ... (the last 3 lines are repeated 15 more times)
 [74068] a(::Int64) at ./REPL[2]:1
 [74069] c(::Int64) at ./REPL[4]:1

julia>

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 but process_backtrace is not exported and I couldn't find any use of it in the packages I had installed.

@Liozou
Copy link
Member Author

Liozou commented Jul 9, 2018

Actually it doesn't seem to be working with internal stack traces: I tried with #26665 but the cycles are not detected. If anyone could point me to the function that deals with printing these stacktraces I could have a look.

@JeffBezanson
Copy link
Member

This is awesome!

@mbauman
Copy link
Member

mbauman commented Jul 9, 2018

Actually it doesn't seem to be working with internal stack traces.

I think that's just fine. They shouldn't happen in the first place.

@Liozou
Copy link
Member Author

Liozou commented Jul 10, 2018

The Travis errors seem unrelated, although I am by no mean an expert in CI log reading. Should this be merged?

@StefanKarpinski
Copy link
Member

Looks good, although someone should review. @vtjnash? @JeffBezanson?

@JeffBezanson JeffBezanson merged commit b0240d9 into JuliaLang:master Jul 11, 2018
@Liozou Liozou deleted the overflow_error_printing branch July 11, 2018 19:30
@Liozou Liozou restored the overflow_error_printing branch July 19, 2018 14:38
@Liozou Liozou deleted the overflow_error_printing branch July 19, 2018 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Too long StackOverflowError backtrace
4 participants