From 3d1598e9448c173b3c8d3da2c4f914e5f9611a38 Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Tue, 12 Jan 2021 08:48:30 -0600 Subject: [PATCH] Test & CoreLogging: improve inference & (no)specialization (#39177) This adjusts specialization in both Base.CoreLogging and Test, and transitions to concrete types in some Test structs. It also fixes a couple of inference problems. Co-authored-by: Jameson Nash --- base/logging.jl | 2 +- stdlib/Test/src/Test.jl | 16 ++++++++-------- stdlib/Test/src/logging.jl | 1 + 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/base/logging.jl b/base/logging.jl index 1727fc8b16f76..72bdb425b010a 100644 --- a/base/logging.jl +++ b/base/logging.jl @@ -101,7 +101,7 @@ struct NullLogger <: AbstractLogger; end min_enabled_level(::NullLogger) = AboveMaxLevel shouldlog(::NullLogger, args...) = false handle_message(::NullLogger, args...; kwargs...) = - error("Null logger handle_message() should not be called") + (@nospecialize; error("Null logger handle_message() should not be called")) #------------------------------------------------------------------------------- diff --git a/stdlib/Test/src/Test.jl b/stdlib/Test/src/Test.jl index ceee6ae727648..9005b2a8468b6 100644 --- a/stdlib/Test/src/Test.jl +++ b/stdlib/Test/src/Test.jl @@ -284,14 +284,14 @@ function eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode, negate elseif evaluated.head === :call op = evaled_args[1] - kwargs = evaled_args[2].args # Keyword arguments from `Expr(:parameters, ...)` + kwargs = (evaled_args[2]::Expr).args # Keyword arguments from `Expr(:parameters, ...)` args = evaled_args[3:n] res = op(args...; kwargs...) # Create "Evaluated" expression which looks like the original call but has all of # the arguments evaluated - func_sym = quoted_args[1] + func_sym = quoted_args[1]::Union{Symbol,Expr} if isempty(kwargs) quoted = Expr(:call, func_sym, args...) elseif func_sym === :≈ && !res @@ -312,7 +312,7 @@ function eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode, negate Returned(res, # stringify arguments in case of failure, for easy remote printing - res === true ? quoted : sprint(io->print(IOContext(io, :limit => true), quoted))*kw_suffix, + res === true ? quoted : sprint(print, quoted, context=(:limit => true)) * kw_suffix, source) end @@ -758,7 +758,7 @@ struct FallbackTestSet <: AbstractTestSet end fallback_testset = FallbackTestSet() struct FallbackTestSetException <: Exception - msg::AbstractString + msg::String end function Base.showerror(io::IO, ex::FallbackTestSetException, bt; backtrace=true) @@ -785,13 +785,13 @@ are any `Fail`s or `Error`s, an exception will be thrown only at the end, along with a summary of the test results. """ mutable struct DefaultTestSet <: AbstractTestSet - description::AbstractString - results::Vector + description::String + results::Vector{Any} n_passed::Int anynonpass::Bool verbose::Bool end -DefaultTestSet(desc; verbose = false) = DefaultTestSet(desc, [], 0, false, verbose) +DefaultTestSet(desc::AbstractString; verbose::Bool = false) = DefaultTestSet(String(desc)::String, [], 0, false, verbose) # For a broken result, simply store the result record(ts::DefaultTestSet, t::Broken) = (push!(ts.results, t); t) @@ -1462,7 +1462,7 @@ want to set this to `false`. See [`Base.isambiguous`](@ref). function detect_ambiguities(mods...; recursive::Bool = false, ambiguous_bottom::Bool = false) - @nospecialize mods + @nospecialize ambs = Set{Tuple{Method,Method}}() mods = collect(mods)::Vector{Module} function sortdefs(m1::Method, m2::Method) diff --git a/stdlib/Test/src/logging.jl b/stdlib/Test/src/logging.jl index 25a5e8c0cc9ad..7df7acbdd55e7 100644 --- a/stdlib/Test/src/logging.jl +++ b/stdlib/Test/src/logging.jl @@ -40,6 +40,7 @@ end function handle_message(logger::TestLogger, level, msg, _module, group, id, file, line; kwargs...) + @nospecialize push!(logger.logs, LogRecord(level, msg, _module, group, id, file, line, kwargs)) end