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
Changes from 1 commit
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
7 changes: 5 additions & 2 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 @@ -387,6 +389,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