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

Don't error if we don't have line information #634

Merged
merged 2 commits into from
Jul 18, 2024
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
34 changes: 18 additions & 16 deletions src/interpret.jl
Original file line number Diff line number Diff line change
Expand Up @@ -457,23 +457,25 @@ function coverage_visit_line!(frame::Frame)
code.report_coverage || return
src = code.src
@static if VERSION ≥ v"1.12.0-DEV.173"
lineinfo = linetable(src, pc)
file, line = lineinfo.file, lineinfo.line
if line != frame.last_codeloc
file isa Symbol || (file = Symbol(file)::Symbol)
@ccall jl_coverage_visit_line(file::Cstring, sizeof(file)::Csize_t, line::Cint)::Cvoid
frame.last_codeloc = line
end
lineinfo = linetable(src, pc)
if lineinfo !== nothing
file, line = lineinfo.file, lineinfo.line
if line != frame.last_codeloc
file isa Symbol || (file = Symbol(file)::Symbol)
@ccall jl_coverage_visit_line(file::Cstring, sizeof(file)::Csize_t, line::Cint)::Cvoid
frame.last_codeloc = line
end
end
else # VERSION < v"1.12.0-DEV.173"
codeloc = src.codelocs[pc]
if codeloc != frame.last_codeloc && codeloc != 0
linetable = src.linetable::Vector{Any}
lineinfo = linetable[codeloc]::Core.LineInfoNode
file, line = lineinfo.file, lineinfo.line
file isa Symbol || (file = Symbol(file)::Symbol)
@ccall jl_coverage_visit_line(file::Cstring, sizeof(file)::Csize_t, line::Cint)::Cvoid
frame.last_codeloc = codeloc
end
codeloc = src.codelocs[pc]
if codeloc != frame.last_codeloc && codeloc != 0
linetable = src.linetable::Vector{Any}
lineinfo = linetable[codeloc]::Core.LineInfoNode
file, line = lineinfo.file, lineinfo.line
file isa Symbol || (file = Symbol(file)::Symbol)
@ccall jl_coverage_visit_line(file::Cstring, sizeof(file)::Csize_t, line::Cint)::Cvoid
frame.last_codeloc = codeloc
end
end # @static if
end

Expand Down
10 changes: 7 additions & 3 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,14 @@ function linetable(arg)
return ci.linetable::Union{Vector{Core.LineInfoNode},Vector{Any}} # issue #264
end # @static if
end
function linetable(arg, i::Integer; macro_caller::Bool=false)::Union{Expr,LineTypes}
function linetable(arg, i::Integer; macro_caller::Bool=false)::Union{Expr,Nothing,LineTypes}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linetable(arg, ::Integer) is used in the other places too, like linenumber(::FrameCode, pc), so better to handle the nothing case there too?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the other option would be to synthesize a special LineNumber node that indicates the absence of information. That way clients that don't care don't have to worry about it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the nothing option since anything that isn't prepared will hard-error.

lt = linetable(arg)
@static if VERSION ≥ v"1.12.0-DEV.173"
# TODO: decode the linetable at this frame efficiently by reimplementing this here
# TODO: get the contextual name from the parent, rather than returning "n/a" (which breaks Cthulhu)
return Base.IRShow.buildLineInfoNode(lt, :var"n/a", i)[1] # ignore all inlining / macro expansion / etc :(
nodes = Base.IRShow.buildLineInfoNode(lt, :var"n/a", i)
isempty(nodes) && return nothing
return nodes[1] # ignore all inlining / macro expansion / etc :(
else # VERSION < v"1.12.0-DEV.173"
lin = lt[i]::Union{Expr,LineTypes}
if macro_caller
Expand Down Expand Up @@ -351,9 +353,10 @@ function lineoffset(framecode::FrameCode)
return offset
end

function getline(ln::Union{LineTypes,Expr})
function getline(ln::Union{LineTypes,Expr,Nothing})
_getline(ln::LineTypes) = Int(ln.line)
_getline(ln::Expr) = ln.args[1]::Int # assuming ln.head === :line
_getline(::Nothing) = nothing
return _getline(ln)
end
function getfile(ln::Union{LineTypes,Expr})
Expand Down Expand Up @@ -387,6 +390,7 @@ function CodeTracking.whereis(framecode::FrameCode, pc::Int; kwargs...)
codeloc = codelocation(framecode.src, pc)
codeloc == 0 && return nothing
lineinfo = linetable(framecode, codeloc; kwargs...)
lineinfo === nothing && return nothing
m = framecode.scope
return isa(m, Method) ? whereis(lineinfo, m) : (getfile(lineinfo), getline(lineinfo))
end
Expand Down
Loading