Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage: ensure topline is recorded during inlining #42170

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -304,29 +304,47 @@ function ir_inline_item!(compact::IncrementalCompact, idx::Int, argexprs::Vector
boundscheck::Symbol, todo_bbs::Vector{Tuple{Int, Int}})
# Ok, do the inlining here
spec = item.spec::ResolvedInliningSpec
sparam_vals = item.mi.sparam_vals
def = item.mi.def::Method
inline_cfg = spec.ir.cfg
stmt = compact.result[idx][:inst]
linetable_offset::Int32 = length(linetable)
# Append the linetable of the inlined function to our line table
inlined_at = Int(compact.result[idx][:line])
for entry in spec.ir.linetable
push!(linetable, LineInfoNode(entry.module, entry.method, entry.file, entry.line,
(entry.inlined_at > 0 ? entry.inlined_at + linetable_offset : inlined_at)))
topline::Int32 = linetable_offset + Int32(1)
coverage = coverage_enabled(def.module)
push!(linetable, LineInfoNode(def.module, def.name, def.file, Int(def.line), inlined_at))
oldlinetable = spec.ir.linetable
for oldline in 1:length(oldlinetable)
entry = oldlinetable[oldline]
newentry = LineInfoNode(entry.module, entry.method, entry.file, entry.line,
(entry.inlined_at > 0 ? entry.inlined_at + linetable_offset + (oldline == 1) : inlined_at))
if oldline == 1
# check for a duplicate on the first iteration (likely true)
if newentry === linetable[topline]
continue
else
linetable_offset += 1
end
end
push!(linetable, newentry)
end
if coverage && spec.ir.stmts[1][:line] + linetable_offset != topline
insert_node_here!(compact, NewInstruction(Expr(:code_coverage_effect), Nothing, topline))
end
(; def, sparam_vals) = item.mi
nargs_def = def.nargs::Int32
isva = nargs_def > 0 && def.isva
sig = def.sig
if isva
vararg = mk_tuplecall!(compact, argexprs[nargs_def:end], compact.result[idx][:line])
vararg = mk_tuplecall!(compact, argexprs[nargs_def:end], topline)
argexprs = Any[argexprs[1:(nargs_def - 1)]..., vararg]
end
is_opaque = isa(def, Method) && def.is_for_opaque_closure
is_opaque = def.is_for_opaque_closure
if is_opaque
# Replace the first argument by a load of the capture environment
argexprs[1] = insert_node_here!(compact,
NewInstruction(Expr(:call, GlobalRef(Core, :getfield), argexprs[1], QuoteNode(:captures)),
spec.ir.argtypes[1], compact.result[idx][:line]))
spec.ir.argtypes[1], topline))
end
flag = compact.result[idx][:flag]
boundscheck_idx = boundscheck
Expand Down
6 changes: 3 additions & 3 deletions test/testhelpers/coverage_file.info
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ DA:11,1
DA:12,1
DA:14,0
DA:17,1
DA:19,1
DA:19,2
DA:20,1
DA:22,1
LH:10
LF:13
LH:12
LF:14
end_of_record
2 changes: 1 addition & 1 deletion test/testhelpers/coverage_file.info.bad
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ DA:12,1
DA:14,0
DA:17,1
DA:18,0
DA:19,1
DA:19,2
DA:20,1
DA:22,1
DA:1234,0
Expand Down