Skip to content

Commit 46032c5

Browse files
timholyvtjnash
andauthored
Inferrability: eliminate more Core.Box (#44029)
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 <vtjnash@gmail.com>
1 parent bd9c510 commit 46032c5

File tree

6 files changed

+19
-15
lines changed

6 files changed

+19
-15
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ end
130130

131131
function getkey(wkh::WeakKeyDict{K}, kk, default) where K
132132
k = lock(wkh) do
133-
k = getkey(wkh.ht, kk, nothing)
133+
local k = getkey(wkh.ht, kk, nothing)
134134
k === nothing && return nothing
135135
return k.value
136136
end

stdlib/REPL/src/LineEdit.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ function enter_prefix_search(s::MIState, p::PrefixHistoryPrompt, backward::Bool)
19711971
parent = mode(s)
19721972

19731973
transition(s, p) do
1974-
pss = state(s, p)
1974+
local pss = state(s, p)
19751975
pss.parent = parent
19761976
pss.histprompt.parent_prompt = parent
19771977
pss.prefix = String(buf.data[1:position(buf)])

stdlib/Test/src/Test.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct Pass <: Result
8787
value
8888
source::Union{Nothing,LineNumberNode}
8989
message_only::Bool
90-
function Pass(test_type::Symbol, orig_expr, data, thrown, source=nothing, message_only=false)
90+
function Pass(test_type::Symbol, orig_expr, data, thrown, source::Union{Nothing,LineNumberNode}=nothing, message_only::Bool=false)
9191
return new(test_type, orig_expr, data, thrown, source, message_only)
9292
end
9393
end
@@ -168,7 +168,7 @@ struct Error <: Result
168168
backtrace::String
169169
source::LineNumberNode
170170

171-
function Error(test_type, orig_expr, value, bt, source)
171+
function Error(test_type::Symbol, orig_expr, value, bt, source::LineNumberNode)
172172
if test_type === :test_error
173173
bt = scrub_exc_stack(bt)
174174
end

0 commit comments

Comments
 (0)