Skip to content

Commit

Permalink
single scan for slot ids [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Aug 16, 2017
1 parent 59d0059 commit c3c50b9
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -346,31 +346,28 @@ This serves as a warning of potential type instability. Not all non-leaf types a
problematic for performance, so the results need to be used judiciously.
See [`@code_warntype`](@ref man-code-warntype) for more information.
"""
function code_warntype(io::IO, f, @nospecialize(t))
function is_variable_used(bodies::Vector, slotnames, v)
for body in bodies
is_variable_used(body, slotnames, v) && return true
function code_warntype(io::IO, f, t::ANY) #@nospecialize(t))
function find_used_slotids(cinfo::CodeInfo)
used_slotids = Set{Int}()
for node in cinfo.code
populate_slotids!(used_slotids, node)
end
return false
return used_slotids
end

function is_variable_used(expr::Expr, slotnames, v)
for arg in expr.args
is_variable_used(arg, slotnames, v) && return true
end
return false
end

is_variable_used(arg::SlotNumber, slotnames, v) = slotnames[arg.id] == v
is_variable_used(arg, slotnames, v) = false
populate_slotids!(used_slotids, arg::Vector) = foreach(x -> populate_slotids!(used_slotids, x), arg)
populate_slotids!(used_slotids, arg::Expr) = foreach(x -> populate_slotids!(used_slotids, x), arg.args)
populate_slotids!(used_slotids, arg::Slot) = push!(used_slotids, arg.id)
populate_slotids!(used_slotids, arg) = used_slotids

emph_io = IOContext(io, :TYPEEMPHASIZE => true)
for (src, rettype) in code_typed(f, t)
used_slotids = find_used_slotids(src)
println(emph_io, "Variables:")
slotnames = sourceinfo_slotnames(src)
for i = 1:length(slotnames)
print(emph_io, " ", slotnames[i])
isused = is_variable_used(src.code, slotnames, slotnames[i])
isused = i in used_slotids
if isa(src.slottypes, Array)
show_expr_type(emph_io, src.slottypes[i], isused)
end
Expand Down

0 comments on commit c3c50b9

Please sign in to comment.