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

Implement line number correction for methods and method lists #278

Merged
merged 1 commit into from
Apr 5, 2019
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
14 changes: 14 additions & 0 deletions src/Revise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,17 @@ function update_stacktrace_lineno!(trace)
return trace
end

function method_location(method::Method)
# Why not just call `whereis`? Because that forces tracking. This is being
# clever by recognizing that these entries exist only if there have been updates.
updated = get(CodeTracking.method_info, method.sig, nothing)
if updated !== nothing
lnn = updated[1]
return lnn.file, lnn.line
end
return method.file, method.line
end

@noinline function run_backend(backend)
while true
tls = task_local_storage()
Expand Down Expand Up @@ -948,6 +959,9 @@ function __init__()
end
# Correct line numbers for code moving around
Base.update_stackframes_callback[] = update_stacktrace_lineno!
if isdefined(Base, :methodloc_callback)
Base.methodloc_callback[] = method_location
end
# Populate CodeTracking data for dependencies and initialize watching
for mod in (CodeTracking, OrderedCollections, JuliaInterpreter, LoweredCodeUtils)
id = PkgId(mod)
Expand Down
10 changes: 9 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,11 @@ foo(y::Int) = y-51
bt = throwing_function(Revise.update_stacktrace_lineno!(stacktrace(catch_backtrace())))
@test bt.file == Symbol(filename) && bt.line == 2
end
io = IOBuffer()
if isdefined(Base, :methodloc_callback)
print(io, methods(triggered))
@test occursin(filename * ":2", String(take!(io)))
end
sleep(2.1)
open(filename, "w") do io
println(io, """
Expand Down Expand Up @@ -1065,7 +1070,6 @@ foo(y::Int) = y-51
stacktrace(catch_backtrace())
end
targetstr = filename * ":3"
io = IOBuffer()
Base.show_backtrace(io, st)
@test occursin(targetstr, String(take!(io)))
# Long stacktraces take a different path, test this too
Expand All @@ -1074,6 +1078,10 @@ foo(y::Int) = y-51
end
Base.show_backtrace(io, st)
@test occursin(targetstr, String(take!(io)))
if isdefined(Base, :methodloc_callback)
print(io, methods(triggered))
@test occursin(filename * ":3", String(take!(io)))
end

push!(to_remove, filename)
end
Expand Down