Skip to content

Commit

Permalink
no longer warn in code_warntype for unused variables [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Aug 16, 2017
1 parent 42abb03 commit 59d0059
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion base/interactiveutil.jl
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,35 @@ 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
end
return false
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

emph_io = IOContext(io, :TYPEEMPHASIZE => true)
for (src, rettype) in code_typed(f, t)
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])
if isa(src.slottypes, Array)
show_expr_type(emph_io, src.slottypes[i], true)
show_expr_type(emph_io, src.slottypes[i], isused)
end
if !isused
print(emph_io, " (Unused in body)")
end
print(emph_io, '\n')
end
Expand Down

0 comments on commit 59d0059

Please sign in to comment.