Skip to content

Commit f3a34a3

Browse files
authored
try harder to find code locations in whereis (#644)
With this change, at least the tests in `test/interpret.jl` are passing on nightly
1 parent 50182dd commit f3a34a3

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/utils.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,11 @@ 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,Nothing,LineTypes}
280+
function linetable(arg, i::Integer; macro_caller::Bool=false, def=:var"n/a")::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
284-
# TODO: get the contextual name from the parent, rather than returning "n/a" (which breaks Cthulhu)
285-
nodes = Base.IRShow.buildLineInfoNode(lt, :var"n/a", i)
284+
nodes = Base.IRShow.buildLineInfoNode(lt, def, i)
286285
isempty(nodes) && return nothing
287286
return nodes[1] # ignore all inlining / macro expansion / etc :(
288287
else # VERSION < v"1.12.0-DEV.173"
@@ -389,10 +388,13 @@ method that issued the macro.
389388
function CodeTracking.whereis(framecode::FrameCode, pc::Int; kwargs...)
390389
codeloc = codelocation(framecode.src, pc)
391390
codeloc == 0 && return nothing
392-
lineinfo = linetable(framecode, codeloc; kwargs...)
393-
lineinfo === nothing && return nothing
394391
m = framecode.scope
395-
return isa(m, Method) ? whereis(lineinfo, m) : (getfile(lineinfo), getline(lineinfo))
392+
lineinfo = linetable(framecode, codeloc; kwargs..., def=isa(m, Method) ? m : :var"n/a")
393+
if m isa Method
394+
return lineinfo === nothing ? (String(m.file), m.line) : whereis(lineinfo, m)
395+
else
396+
return lineinfo === nothing ? nothing : (getfile(lineinfo), getline(lineinfo))
397+
end
396398
end
397399
CodeTracking.whereis(frame::Frame, pc::Int=frame.pc; kwargs...) = whereis(frame.framecode, pc; kwargs...)
398400

test/interpret.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,9 @@ file, line = JuliaInterpreter.whereis(fr)
471471
fr = JuliaInterpreter.enter_call(Test.eval, 1)
472472
file, line = JuliaInterpreter.whereis(fr)
473473
@test isfile(file)
474-
@test isfile(JuliaInterpreter.getfile(fr.framecode.src.linetable[1]))
474+
@static if VERSION < v"1.12.0-DEV.173"
475+
@test isfile(JuliaInterpreter.getfile(fr.framecode.src.linetable[1]))
476+
end
475477
@static if VERSION < v"1.9.0-DEV.846" # https://github.com/JuliaLang/julia/pull/45069
476478
@test occursin(Sys.STDLIB, repr(fr))
477479
else

0 commit comments

Comments
 (0)