Skip to content

Commit e2bbe47

Browse files
Kenotimholy
andauthored
Don't error if we don't have line information (#634)
* Don't error if we don't have line information `whereis` is already allowed to return `nothing`. It's possible for codeloc to be != 0, but for Core.Compiler to still be unable to produce a location. In that case, also return `nothing`. * propagate the `nothing` case --------- Co-authored-by: Tim Holy <[email protected]>
1 parent 6031ed7 commit e2bbe47

File tree

2 files changed

+25
-19
lines changed

2 files changed

+25
-19
lines changed

src/interpret.jl

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -457,23 +457,25 @@ function coverage_visit_line!(frame::Frame)
457457
code.report_coverage || return
458458
src = code.src
459459
@static if VERSION v"1.12.0-DEV.173"
460-
lineinfo = linetable(src, pc)
461-
file, line = lineinfo.file, lineinfo.line
462-
if line != frame.last_codeloc
463-
file isa Symbol || (file = Symbol(file)::Symbol)
464-
@ccall jl_coverage_visit_line(file::Cstring, sizeof(file)::Csize_t, line::Cint)::Cvoid
465-
frame.last_codeloc = line
466-
end
460+
lineinfo = linetable(src, pc)
461+
if lineinfo !== nothing
462+
file, line = lineinfo.file, lineinfo.line
463+
if line != frame.last_codeloc
464+
file isa Symbol || (file = Symbol(file)::Symbol)
465+
@ccall jl_coverage_visit_line(file::Cstring, sizeof(file)::Csize_t, line::Cint)::Cvoid
466+
frame.last_codeloc = line
467+
end
468+
end
467469
else # VERSION < v"1.12.0-DEV.173"
468-
codeloc = src.codelocs[pc]
469-
if codeloc != frame.last_codeloc && codeloc != 0
470-
linetable = src.linetable::Vector{Any}
471-
lineinfo = linetable[codeloc]::Core.LineInfoNode
472-
file, line = lineinfo.file, lineinfo.line
473-
file isa Symbol || (file = Symbol(file)::Symbol)
474-
@ccall jl_coverage_visit_line(file::Cstring, sizeof(file)::Csize_t, line::Cint)::Cvoid
475-
frame.last_codeloc = codeloc
476-
end
470+
codeloc = src.codelocs[pc]
471+
if codeloc != frame.last_codeloc && codeloc != 0
472+
linetable = src.linetable::Vector{Any}
473+
lineinfo = linetable[codeloc]::Core.LineInfoNode
474+
file, line = lineinfo.file, lineinfo.line
475+
file isa Symbol || (file = Symbol(file)::Symbol)
476+
@ccall jl_coverage_visit_line(file::Cstring, sizeof(file)::Csize_t, line::Cint)::Cvoid
477+
frame.last_codeloc = codeloc
478+
end
477479
end # @static if
478480
end
479481

src/utils.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,14 @@ function linetable(arg)
277277
return ci.linetable::Union{Vector{Core.LineInfoNode},Vector{Any}} # issue #264
278278
end # @static if
279279
end
280-
function linetable(arg, i::Integer; macro_caller::Bool=false)::Union{Expr,LineTypes}
280+
function linetable(arg, i::Integer; macro_caller::Bool=false)::Union{Expr,Nothing,LineTypes}
281281
lt = linetable(arg)
282282
@static if VERSION v"1.12.0-DEV.173"
283283
# TODO: decode the linetable at this frame efficiently by reimplementing this here
284284
# TODO: get the contextual name from the parent, rather than returning "n/a" (which breaks Cthulhu)
285-
return Base.IRShow.buildLineInfoNode(lt, :var"n/a", i)[1] # ignore all inlining / macro expansion / etc :(
285+
nodes = Base.IRShow.buildLineInfoNode(lt, :var"n/a", i)
286+
isempty(nodes) && return nothing
287+
return nodes[1] # ignore all inlining / macro expansion / etc :(
286288
else # VERSION < v"1.12.0-DEV.173"
287289
lin = lt[i]::Union{Expr,LineTypes}
288290
if macro_caller
@@ -351,9 +353,10 @@ function lineoffset(framecode::FrameCode)
351353
return offset
352354
end
353355

354-
function getline(ln::Union{LineTypes,Expr})
356+
function getline(ln::Union{LineTypes,Expr,Nothing})
355357
_getline(ln::LineTypes) = Int(ln.line)
356358
_getline(ln::Expr) = ln.args[1]::Int # assuming ln.head === :line
359+
_getline(::Nothing) = nothing
357360
return _getline(ln)
358361
end
359362
function getfile(ln::Union{LineTypes,Expr})
@@ -387,6 +390,7 @@ function CodeTracking.whereis(framecode::FrameCode, pc::Int; kwargs...)
387390
codeloc = codelocation(framecode.src, pc)
388391
codeloc == 0 && return nothing
389392
lineinfo = linetable(framecode, codeloc; kwargs...)
393+
lineinfo === nothing && return nothing
390394
m = framecode.scope
391395
return isa(m, Method) ? whereis(lineinfo, m) : (getfile(lineinfo), getline(lineinfo))
392396
end

0 commit comments

Comments
 (0)