Skip to content

Commit

Permalink
Inferrability: eliminate more Core.Box
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.
  • Loading branch information
timholy committed Feb 3, 2022
1 parent e3b681c commit 4884225
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 18 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
10 changes: 6 additions & 4 deletions base/weakkeydict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ function get!(default::Callable, wkh::WeakKeyDict{K}, key) where {K}
end

function getkey(wkh::WeakKeyDict{K}, kk, default) where K
k = lock(wkh) do
k = getkey(wkh.ht, kk, nothing)
k === nothing && return nothing
return k.value
k = let wkh=wkh
lock(wkh) do
k = getkey(wkh.ht, kk, nothing)
k === nothing && return nothing
return k.value
end
end
return k === nothing ? default : k::K
end
Expand Down
6 changes: 3 additions & 3 deletions stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1979,11 +1979,11 @@ function enter_prefix_search(s::MIState, p::PrefixHistoryPrompt, backward::Bool)
pss.indent = state(s, parent).indent
pss.mi = s
end
pss = state(s, p)
pss_ = state(s, p)
if backward
history_prev_prefix(pss, pss.histprompt.hp, pss.prefix)
history_prev_prefix(pss_, pss_.histprompt.hp, pss_.prefix)
else
history_next_prefix(pss, pss.histprompt.hp, pss.prefix)
history_next_prefix(pss_, pss_.histprompt.hp, pss_.prefix)
end
nothing
end
Expand Down

0 comments on commit 4884225

Please sign in to comment.