Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
julia -e '
using Pkg
Pkg.develop(path=".")
Pkg.add(url="https://github.com/timholy/Revise.jl")
Pkg.add("Revise")
Pkg.test("Revise")
'
- name: Test while running Revise
Expand Down
2 changes: 1 addition & 1 deletion src/CodeTracking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Otherwise `loc` will be `(filepath, line)`.
"""
function whereis(sf::StackTraces.StackFrame)
sf.linfo === nothing && return nothing
return whereis(sf, sf.linfo.def)
return whereis(sf, getmethod(sf.linfo))
end

"""
Expand Down
23 changes: 22 additions & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function linerange(def::Expr)
end
linerange(arg) = linerange(convert(Expr, arg)) # Handle Revise's RelocatableExpr

function findline(ex, order)
function findline(ex::Expr, order)
ex.head === :line && return ex.args[1], true
for a in order(ex.args)
a isa LineNumberNode && return a.line, true
Expand All @@ -194,6 +194,27 @@ end
fileline(lin::LineInfoNode) = String(lin.file), lin.line
fileline(lnn::LineNumberNode) = String(lnn.file), lnn.line

if VERSION ≥ v"1.12.0-DEV.173" # https://github.com/JuliaLang/julia/pull/52415
function linetable_scopes(m::Method)
src = Base.uncompressed_ast(m)
lts = [Vector{Base.Compiler.IRShow.LineInfoNode}() for _ = eachindex(src.code)]
for pc = eachindex(src.code)
Base.IRShow.append_scopes!(lts[pc], pc, src.debuginfo, m)
end
return lts
end
else
function linetable_scopes(m::Method)
src = Base.uncompressed_ast(m)
lt, cl = src.linetable, src.codelocs
return [iszero(cl[pc]) ? Core.LineInfoNode[] : [lt[cl[pc]]] for pc = eachindex(cl)]
end
end

getmethod(m::Method) = m
getmethod(mi::Core.MethodInstance) = getmethod(mi.def)
getmethod(ci::Core.CodeInstance) = getmethod(ci.def)

# This regex matches the pseudo-file name of a REPL history entry.
const rREPL = r"^REPL\[(\d+)\]$"
# Match anonymous function names
Expand Down
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,13 @@ isdefined(Main, :Revise) ? Main.Revise.includet("script.jl") : include("script.j
@info "hello"
end
m = first(methods(f150))
src = Base.uncompressed_ast(m)
idx = findfirst(lin -> String(lin.file) == @__FILE__, src.linetable)
lin = src.linetable[idx]
scopes = CodeTracking.linetable_scopes(m)
idx = findfirst(sc -> all(lin -> String(lin.file) == @__FILE__, sc), scopes)
lin = first(scopes[idx])
file, line = whereis(lin, m)
@test endswith(file, String(lin.file))
idx = findfirst(lin -> String(lin.file) != @__FILE__, src.linetable)
lin = src.linetable[idx]
idx = findfirst(sc -> !all(lin -> String(lin.file) == @__FILE__, sc), scopes)
lin = first(scopes[idx])
file, line = whereis(lin, m)
if !Sys.iswindows()
@test endswith(file, String(lin.file))
Expand Down
Loading