Skip to content

Commit

Permalink
Qualify function when printing MethodInstance (JuliaLang#38608)
Browse files Browse the repository at this point in the history
Also print file & line for the case `l.def::Module`. This is already done
for stackframes but it is useful to implement it more generally.
  • Loading branch information
timholy authored and ElOceanografo committed May 4, 2021
1 parent 59e97c2 commit 5ca7570
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
15 changes: 13 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -984,18 +984,29 @@ function sourceinfo_slotnames(src::CodeInfo)
return printnames
end

function show(io::IO, l::Core.MethodInstance)
show(io::IO, l::Core.MethodInstance) = show_mi(io, l)

function show_mi(io::IO, l::Core.MethodInstance, from_stackframe::Bool=false)
def = l.def
if isa(def, Method)
if isdefined(def, :generator) && l === def.generator
print(io, "MethodInstance generator for ")
show(io, def)
else
print(io, "MethodInstance for ")
show_tuple_as_call(io, def.name, l.specTypes)
show_tuple_as_call(io, def.name, l.specTypes, false, nothing, nothing, true)
end
else
print(io, "Toplevel MethodInstance thunk")
# `thunk` is not very much information to go on. If this
# MethodInstance is part of a stacktrace, it gets location info
# added by other means. But if it isn't, then we should try
# to print a little more identifying information.
if !from_stackframe
linetable = l.uninferred.linetable
line = isempty(linetable) ? "unknown" : (lt = linetable[1]; string(lt.file) * ':' * string(lt.line))
print(io, " from ", def, " starting at ", line)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion base/stacktraces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ function show_spec_linfo(io::IO, frame::StackFrame)
Base.show_tuple_as_call(io, def.name, sig, true, nothing, argnames)
end
else
Base.show(io, linfo)
Base.show_mi(io, linfo, true)
end
elseif linfo isa CodeInfo
print(io, "top-level scope")
Expand Down
2 changes: 1 addition & 1 deletion test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ let code = """
"""

bt_str = read(`$(Base.julia_cmd()) --startup-file=no --compile=min -e $code`, String)
@test occursin("InterpreterIP in MethodInstance for foo", bt_str)
@test occursin(r"InterpreterIP in MethodInstance for .*A\.foo", bt_str)
@test occursin("InterpreterIP in top-level CodeInfo for Main.A", bt_str)
end

0 comments on commit 5ca7570

Please sign in to comment.