Skip to content

Commit

Permalink
Accurate coverage with inlining on
Browse files Browse the repository at this point in the history
Fix #17476
  • Loading branch information
yuyichao committed Aug 23, 2016
1 parent 92c109e commit d8006e4
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2723,20 +2723,12 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
end
end

if !isempty(stmts)
if all(stmt -> (isa(stmt,Expr) && stmt.head === :line) || isa(stmt, LineNumberNode) || stmt === nothing,
stmts)
empty!(stmts)
else
local line::Int = linfo.def.line
if isa(stmts[1], LineNumberNode)
line = shift!(stmts).line
end
unshift!(stmts, Expr(:meta, :push_loc, linfo.def.file, linfo.def.name, line))
isa(stmts[end], LineNumberNode) && pop!(stmts)
push!(stmts, Expr(:meta, :pop_loc))
end
local line::Int = linfo.def.line
if !isempty(stmts) && isa(stmts[1], LineNumberNode)
line = (shift!(stmts)::LineNumberNode).line
end
unshift!(stmts, Expr(:meta, :push_loc, linfo.def.file, linfo.def.name, line))
push!(stmts, Expr(:meta, :pop_loc))
if !isempty(stmts) && !propagate_inbounds
# avoid redundant inbounds annotations
s_1, s_end = stmts[1], stmts[end]
Expand Down Expand Up @@ -2770,10 +2762,16 @@ inline_worthy(body::ANY, cost::Integer) = true

# should the expression be part of the inline cost model
function inline_ignore(ex::ANY)
isa(ex, LineNumberNode) ||
ex === nothing ||
isa(ex, Expr) && ((ex::Expr).head === :line ||
(ex::Expr).head === :meta)
if isa(ex, LineNumberNode) || ex === nothing
return true
end
if isa(ex, Expr)
ex = ex::Expr
head = ex.head
return (head === :line || head === :meta || head === :inbounds ||
head === :boundscheck)
end
return false
end

function inline_worthy(body::Expr, cost::Integer=1000) # precondition: 0 < cost; nominal cost = 1000
Expand All @@ -2783,7 +2781,7 @@ function inline_worthy(body::Expr, cost::Integer=1000) # precondition: 0 < cost;
symlim = 1000 + 5_000_000 ÷ cost
nstmt = 0
for stmt in body.args
if !inline_ignore(stmt)
if !(isa(stmt, SSAValue) || inline_ignore(stmt))
nstmt += 1
end
end
Expand Down

0 comments on commit d8006e4

Please sign in to comment.