Skip to content

Commit 4884225

Browse files
committed
Inferrability: eliminate more Core.Box
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.
1 parent e3b681c commit 4884225

File tree

5 files changed

+24
-18
lines changed

5 files changed

+24
-18
lines changed

base/compiler/ssair/show.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,8 +629,10 @@ function show_ir_stmt(io::IO, code::Union{IRCode, CodeInfo}, idx::Int, line_info
629629

630630
@assert new_node_inst !== UNDEF # we filtered these out earlier
631631
show_type = should_print_ssa_type(new_node_inst)
632-
with_output_color(:green, io) do io′
633-
print_stmt(io′, node_idx, new_node_inst, used, maxlength_idx, false, show_type)
632+
let maxlength_idx=maxlength_idx, show_type=show_type
633+
with_output_color(:green, io) do io′
634+
print_stmt(io′, node_idx, new_node_inst, used, maxlength_idx, false, show_type)
635+
end
634636
end
635637

636638
if new_node_type === UNDEF # try to be robust against errors

base/errorshow.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -345,13 +345,15 @@ function showerror_ambiguous(io::IO, meth, f, args)
345345
sigfix = typeintersect(m.sig, sigfix)
346346
end
347347
if isa(unwrap_unionall(sigfix), DataType) && sigfix <: Tuple
348-
if all(m->morespecific(sigfix, m.sig), meth)
349-
print(io, "\nPossible fix, define\n ")
350-
Base.show_tuple_as_call(io, :function, sigfix)
351-
else
352-
println(io)
353-
print(io, "To resolve the ambiguity, try making one of the methods more specific, or ")
354-
print(io, "adding a new method more specific than any of the existing applicable methods.")
348+
let sigfix=sigfix
349+
if all(m->morespecific(sigfix, m.sig), meth)
350+
print(io, "\nPossible fix, define\n ")
351+
Base.show_tuple_as_call(io, :function, sigfix)
352+
else
353+
println(io)
354+
print(io, "To resolve the ambiguity, try making one of the methods more specific, or ")
355+
print(io, "adding a new method more specific than any of the existing applicable methods.")
356+
end
355357
end
356358
end
357359
nothing

base/shell.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ function print_shell_escaped_posixly(io::IO, args::AbstractString...)
211211
first || print(io, ' ')
212212
# avoid printing quotes around simple enough strings
213213
# that any (reasonable) shell will definitely never consider them to be special
214-
have_single = false
215-
have_double = false
214+
have_single::Bool = false
215+
have_double::Bool = false
216216
function isword(c::AbstractChar)
217217
if '0' <= c <= '9' || 'a' <= c <= 'z' || 'A' <= c <= 'Z'
218218
# word characters

base/weakkeydict.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,12 @@ function get!(default::Callable, wkh::WeakKeyDict{K}, key) where {K}
129129
end
130130

131131
function getkey(wkh::WeakKeyDict{K}, kk, default) where K
132-
k = lock(wkh) do
133-
k = getkey(wkh.ht, kk, nothing)
134-
k === nothing && return nothing
135-
return k.value
132+
k = let wkh=wkh
133+
lock(wkh) do
134+
k = getkey(wkh.ht, kk, nothing)
135+
k === nothing && return nothing
136+
return k.value
137+
end
136138
end
137139
return k === nothing ? default : k::K
138140
end

stdlib/REPL/src/LineEdit.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,11 +1979,11 @@ function enter_prefix_search(s::MIState, p::PrefixHistoryPrompt, backward::Bool)
19791979
pss.indent = state(s, parent).indent
19801980
pss.mi = s
19811981
end
1982-
pss = state(s, p)
1982+
pss_ = state(s, p)
19831983
if backward
1984-
history_prev_prefix(pss, pss.histprompt.hp, pss.prefix)
1984+
history_prev_prefix(pss_, pss_.histprompt.hp, pss_.prefix)
19851985
else
1986-
history_next_prefix(pss, pss.histprompt.hp, pss.prefix)
1986+
history_next_prefix(pss_, pss_.histprompt.hp, pss_.prefix)
19871987
end
19881988
nothing
19891989
end

0 commit comments

Comments
 (0)