Skip to content

Commit

Permalink
Inferrability: eliminate more Core.Box (JuliaLang#44029)
Browse files Browse the repository at this point in the history
These stem from julia#15276, i.e.,
https://docs.julialang.org/en/v1/manual/performance-tips/#man-performance-captured
They were identified by scanning all compiled MethodInstances with
hasbox in the newly-released MethodAnalysis 0.4.5.

Core.Box often causes "follow-on" inference problems,
but for these cases there were relatively few, which may be why
these didn't show up earlier during the Great Invalidation Hunt.
Still, there doesn't seem to be any particular reason not to fix them.

This doesn't eliminate all Core.Box cases from Base, but only a
handful remain. The most common remaining case stems from inner
functions calling themselves.

It also prevents a couple of Test invalidations

Co-authored-by: Jameson Nash <[email protected]>
  • Loading branch information
2 people authored and LilithHafner committed Feb 22, 2022
1 parent 5cb3776 commit faa5788
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
6 changes: 4 additions & 2 deletions base/compiler/ssair/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,10 @@ function show_ir_stmt(io::IO, code::Union{IRCode, CodeInfo}, idx::Int, line_info

@assert new_node_inst !== UNDEF # we filtered these out earlier
show_type = should_print_ssa_type(new_node_inst)
with_output_color(:green, io) do io′
print_stmt(io′, node_idx, new_node_inst, used, maxlength_idx, false, show_type)
let maxlength_idx=maxlength_idx, show_type=show_type
with_output_color(:green, io) do io′
print_stmt(io′, node_idx, new_node_inst, used, maxlength_idx, false, show_type)
end
end

if new_node_type === UNDEF # try to be robust against errors
Expand Down
16 changes: 9 additions & 7 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,15 @@ function showerror_ambiguous(io::IO, meth, f, args)
sigfix = typeintersect(m.sig, sigfix)
end
if isa(unwrap_unionall(sigfix), DataType) && sigfix <: Tuple
if all(m->morespecific(sigfix, m.sig), meth)
print(io, "\nPossible fix, define\n ")
Base.show_tuple_as_call(io, :function, sigfix)
else
println(io)
print(io, "To resolve the ambiguity, try making one of the methods more specific, or ")
print(io, "adding a new method more specific than any of the existing applicable methods.")
let sigfix=sigfix
if all(m->morespecific(sigfix, m.sig), meth)
print(io, "\nPossible fix, define\n ")
Base.show_tuple_as_call(io, :function, sigfix)
else
println(io)
print(io, "To resolve the ambiguity, try making one of the methods more specific, or ")
print(io, "adding a new method more specific than any of the existing applicable methods.")
end
end
end
nothing
Expand Down
4 changes: 2 additions & 2 deletions base/shell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,8 @@ function print_shell_escaped_posixly(io::IO, args::AbstractString...)
first || print(io, ' ')
# avoid printing quotes around simple enough strings
# that any (reasonable) shell will definitely never consider them to be special
have_single = false
have_double = false
have_single::Bool = false
have_double::Bool = false
function isword(c::AbstractChar)
if '0' <= c <= '9' || 'a' <= c <= 'z' || 'A' <= c <= 'Z'
# word characters
Expand Down
2 changes: 1 addition & 1 deletion base/weakkeydict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ end

function getkey(wkh::WeakKeyDict{K}, kk, default) where K
k = lock(wkh) do
k = getkey(wkh.ht, kk, nothing)
local k = getkey(wkh.ht, kk, nothing)
k === nothing && return nothing
return k.value
end
Expand Down
2 changes: 1 addition & 1 deletion stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1971,7 +1971,7 @@ function enter_prefix_search(s::MIState, p::PrefixHistoryPrompt, backward::Bool)
parent = mode(s)

transition(s, p) do
pss = state(s, p)
local pss = state(s, p)
pss.parent = parent
pss.histprompt.parent_prompt = parent
pss.prefix = String(buf.data[1:position(buf)])
Expand Down
4 changes: 2 additions & 2 deletions stdlib/Test/src/Test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct Pass <: Result
value
source::Union{Nothing,LineNumberNode}
message_only::Bool
function Pass(test_type::Symbol, orig_expr, data, thrown, source=nothing, message_only=false)
function Pass(test_type::Symbol, orig_expr, data, thrown, source::Union{Nothing,LineNumberNode}=nothing, message_only::Bool=false)
return new(test_type, orig_expr, data, thrown, source, message_only)
end
end
Expand Down Expand Up @@ -168,7 +168,7 @@ struct Error <: Result
backtrace::String
source::LineNumberNode

function Error(test_type, orig_expr, value, bt, source)
function Error(test_type::Symbol, orig_expr, value, bt, source::LineNumberNode)
if test_type === :test_error
bt = scrub_exc_stack(bt)
end
Expand Down

0 comments on commit faa5788

Please sign in to comment.