Skip to content
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

Test & CoreLogging: improve inference & (no)specialization #39177

Merged
merged 3 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion base/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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"))


#-------------------------------------------------------------------------------
Expand Down
18 changes: 10 additions & 8 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -312,7 +312,9 @@ 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 : let quoted=quoted
sprint(io::IOBuffer->print(IOContext(io, :limit => true), quoted))*kw_suffix
end,
timholy marked this conversation as resolved.
Show resolved Hide resolved
source)
end

Expand Down Expand Up @@ -758,7 +760,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)
Expand All @@ -785,13 +787,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)
Expand Down Expand Up @@ -1462,7 +1464,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)
Expand Down
1 change: 1 addition & 0 deletions stdlib/Test/src/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down