Skip to content

Commit 3d1598e

Browse files
timholyvtjnash
andauthored
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 <vtjnash@gmail.com>
1 parent 97bd48c commit 3d1598e

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

base/logging.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ struct NullLogger <: AbstractLogger; end
101101
min_enabled_level(::NullLogger) = AboveMaxLevel
102102
shouldlog(::NullLogger, args...) = false
103103
handle_message(::NullLogger, args...; kwargs...) =
104-
error("Null logger handle_message() should not be called")
104+
(@nospecialize; error("Null logger handle_message() should not be called"))
105105

106106

107107
#-------------------------------------------------------------------------------

stdlib/Test/src/Test.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,14 @@ function eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode, negate
284284

285285
elseif evaluated.head === :call
286286
op = evaled_args[1]
287-
kwargs = evaled_args[2].args # Keyword arguments from `Expr(:parameters, ...)`
287+
kwargs = (evaled_args[2]::Expr).args # Keyword arguments from `Expr(:parameters, ...)`
288288
args = evaled_args[3:n]
289289

290290
res = op(args...; kwargs...)
291291

292292
# Create "Evaluated" expression which looks like the original call but has all of
293293
# the arguments evaluated
294-
func_sym = quoted_args[1]
294+
func_sym = quoted_args[1]::Union{Symbol,Expr}
295295
if isempty(kwargs)
296296
quoted = Expr(:call, func_sym, args...)
297297
elseif func_sym === : && !res
@@ -312,7 +312,7 @@ function eval_test(evaluated::Expr, quoted::Expr, source::LineNumberNode, negate
312312

313313
Returned(res,
314314
# stringify arguments in case of failure, for easy remote printing
315-
res === true ? quoted : sprint(io->print(IOContext(io, :limit => true), quoted))*kw_suffix,
315+
res === true ? quoted : sprint(print, quoted, context=(:limit => true)) * kw_suffix,
316316
source)
317317
end
318318

@@ -758,7 +758,7 @@ struct FallbackTestSet <: AbstractTestSet end
758758
fallback_testset = FallbackTestSet()
759759

760760
struct FallbackTestSetException <: Exception
761-
msg::AbstractString
761+
msg::String
762762
end
763763

764764
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,
785785
along with a summary of the test results.
786786
"""
787787
mutable struct DefaultTestSet <: AbstractTestSet
788-
description::AbstractString
789-
results::Vector
788+
description::String
789+
results::Vector{Any}
790790
n_passed::Int
791791
anynonpass::Bool
792792
verbose::Bool
793793
end
794-
DefaultTestSet(desc; verbose = false) = DefaultTestSet(desc, [], 0, false, verbose)
794+
DefaultTestSet(desc::AbstractString; verbose::Bool = false) = DefaultTestSet(String(desc)::String, [], 0, false, verbose)
795795

796796
# For a broken result, simply store the result
797797
record(ts::DefaultTestSet, t::Broken) = (push!(ts.results, t); t)
@@ -1462,7 +1462,7 @@ want to set this to `false`. See [`Base.isambiguous`](@ref).
14621462
function detect_ambiguities(mods...;
14631463
recursive::Bool = false,
14641464
ambiguous_bottom::Bool = false)
1465-
@nospecialize mods
1465+
@nospecialize
14661466
ambs = Set{Tuple{Method,Method}}()
14671467
mods = collect(mods)::Vector{Module}
14681468
function sortdefs(m1::Method, m2::Method)

stdlib/Test/src/logging.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ end
4040

4141
function handle_message(logger::TestLogger, level, msg, _module,
4242
group, id, file, line; kwargs...)
43+
@nospecialize
4344
push!(logger.logs, LogRecord(level, msg, _module, group, id, file, line, kwargs))
4445
end
4546

0 commit comments

Comments
 (0)