Skip to content

Commit fed1161

Browse files
speed up first test fail print
1 parent 8780aa9 commit fed1161

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

base/errorshow.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -638,12 +638,12 @@ const update_stackframes_callback = Ref{Function}(identity)
638638
const STACKTRACE_MODULECOLORS = Iterators.Stateful(Iterators.cycle([:magenta, :cyan, :green, :yellow]))
639639
const STACKTRACE_FIXEDCOLORS = IdDict(Base => :light_black, Core => :light_black)
640640

641-
function show_full_backtrace(io::IO, trace::Vector; print_linebreaks::Bool, prefix=nothing)
641+
function show_full_backtrace(io::IO, trace::Vector; print_linebreaks::Bool, prefix::Union{Nothing,String}=nothing)
642642
num_frames = length(trace)
643643
ndigits_max = ndigits(num_frames)
644644

645645
println(io)
646-
prefix === nothing || print(io, prefix)
646+
prefix isa String && print(io, prefix)
647647
println(io, "Stacktrace:")
648648

649649
for (i, (frame, n)) in enumerate(trace)
@@ -704,7 +704,7 @@ function show_reduced_backtrace(io::IO, t::Vector; prefix=nothing)
704704
try invokelatest(update_stackframes_callback[], displayed_stackframes) catch end
705705

706706
println(io)
707-
prefix === nothing || print(io, prefix)
707+
prefix isa String && print(io, prefix)
708708
println(io, "Stacktrace:")
709709

710710
ndigits_max = ndigits(length(t))
@@ -713,7 +713,7 @@ function show_reduced_backtrace(io::IO, t::Vector; prefix=nothing)
713713
frame_counter = 1
714714
for i in eachindex(displayed_stackframes)
715715
(frame, n) = displayed_stackframes[i]
716-
prefix === nothing || print(io, prefix)
716+
prefix isa String && print(io, prefix)
717717
print_stackframe(io, frame_counter, frame, n, ndigits_max, STACKTRACE_FIXEDCOLORS, STACKTRACE_MODULECOLORS; prefix)
718718

719719
if i < length(displayed_stackframes)
@@ -725,7 +725,7 @@ function show_reduced_backtrace(io::IO, t::Vector; prefix=nothing)
725725
cycle_length = repeated_cycle[1][2]
726726
repetitions = repeated_cycle[1][3]
727727
popfirst!(repeated_cycle)
728-
prefix === nothing || print(io, prefix)
728+
prefix isa String && print(io, prefix)
729729
printstyled(io,
730730
"--- the above ", cycle_length, " lines are repeated ",
731731
repetitions, " more time", repetitions>1 ? "s" : "", " ---", color = :light_black)
@@ -743,7 +743,7 @@ end
743743
# Print a stack frame where the module color is determined by looking up the parent module in
744744
# `modulecolordict`. If the module does not have a color, yet, a new one can be drawn
745745
# from `modulecolorcycler`.
746-
function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulecolordict, modulecolorcycler; prefix=nothing)
746+
function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulecolordict, modulecolorcycler; prefix::Union{Nothing,String}=nothing)
747747
m = Base.parentmodule(frame)
748748
modulecolor = if m !== nothing
749749
m = parentmodule_before_main(m)
@@ -766,7 +766,7 @@ end
766766
parentmodule_before_main(x) = parentmodule_before_main(parentmodule(x))
767767

768768
# Print a stack frame where the module color is set manually with `modulecolor`.
769-
function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulecolor; prefix=nothing)
769+
function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulecolor; prefix::Union{Nothing,String}=nothing)
770770
file, line = string(frame.file), frame.line
771771

772772
# Used by the REPL to make it possible to open
@@ -781,7 +781,7 @@ function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulec
781781
digit_align_width = ndigits_max + 2
782782

783783
# frame number
784-
prefix === nothing || print(io, prefix)
784+
prefix isa String && print(io, prefix)
785785
print(io, " ", lpad("[" * string(i) * "]", digit_align_width))
786786
print(io, " ")
787787

@@ -791,7 +791,7 @@ function print_stackframe(io, i, frame::StackFrame, n::Int, ndigits_max, modulec
791791
end
792792
println(io)
793793

794-
prefix === nothing || print(io, prefix)
794+
prefix isa String && print(io, prefix)
795795
# @ Module path / file : line
796796
print_module_path_file(io, modul, file, line; modulecolor, digit_align_width)
797797

@@ -820,7 +820,7 @@ function print_module_path_file(io, modul, file, line; modulecolor = :light_blac
820820
printstyled(io, basename(file), ":", line; color = :light_black, underline = true)
821821
end
822822

823-
function show_backtrace(io::IO, t::Vector; prefix=nothing)
823+
function show_backtrace(io::IO, t::Vector; prefix::Union{Nothing,String}=nothing)
824824
if haskey(io, :last_shown_line_infos)
825825
empty!(io[:last_shown_line_infos])
826826
end

contrib/generate_precompile.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ precompile(Base.indexed_iterate, (Pair{Symbol, Union{Nothing, String}}, Int, Int
4242
precompile(Tuple{typeof(Base.Threads.atomic_add!), Base.Threads.Atomic{Int}, Int})
4343
precompile(Tuple{typeof(Base.Threads.atomic_sub!), Base.Threads.Atomic{Int}, Int})
4444
45+
# error handling
46+
precompile(Tuple{typeof(Core.kwcall), NamedTuple{(:prefix,), Tuple{String}}, typeof(Base.show_backtrace), Base.TTY, Array{Union{Ptr{Nothing}, Base.InterpreterIP}, 1}})
47+
precompile(Tuple{typeof(Core.kwcall), NamedTuple{(:backtrace,), Tuple{Bool}}, typeof(Base.showerror), Base.IOContext{Base.GenericIOBuffer{Memory{UInt8}}}, ErrorException, Array{Union{Ptr{Nothing}, Base.InterpreterIP}, 1}})
48+
precompile(Tuple{Base.var"##with_output_color#856", Bool, Bool, Bool, Bool, Bool, Bool, typeof(Base.with_output_color), Function, Symbol, Base.TTY, Symbol, Vararg{Any}})
49+
4550
# LazyArtifacts (but more generally helpful)
4651
precompile(Tuple{Type{Base.Val{x} where x}, Module})
4752
precompile(Tuple{Type{NamedTuple{(:honor_overrides,), T} where T<:Tuple}, Tuple{Bool}})

0 commit comments

Comments
 (0)