Skip to content

Commit 448f85d

Browse files
authored
Qualify function when printing MethodInstance (#38608)
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.
1 parent a1106b8 commit 448f85d

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

base/show.jl

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,18 +984,29 @@ function sourceinfo_slotnames(src::CodeInfo)
984984
return printnames
985985
end
986986

987-
function show(io::IO, l::Core.MethodInstance)
987+
show(io::IO, l::Core.MethodInstance) = show_mi(io, l)
988+
989+
function show_mi(io::IO, l::Core.MethodInstance, from_stackframe::Bool=false)
988990
def = l.def
989991
if isa(def, Method)
990992
if isdefined(def, :generator) && l === def.generator
991993
print(io, "MethodInstance generator for ")
992994
show(io, def)
993995
else
994996
print(io, "MethodInstance for ")
995-
show_tuple_as_call(io, def.name, l.specTypes)
997+
show_tuple_as_call(io, def.name, l.specTypes, false, nothing, nothing, true)
996998
end
997999
else
9981000
print(io, "Toplevel MethodInstance thunk")
1001+
# `thunk` is not very much information to go on. If this
1002+
# MethodInstance is part of a stacktrace, it gets location info
1003+
# added by other means. But if it isn't, then we should try
1004+
# to print a little more identifying information.
1005+
if !from_stackframe
1006+
linetable = l.uninferred.linetable
1007+
line = isempty(linetable) ? "unknown" : (lt = linetable[1]; string(lt.file) * ':' * string(lt.line))
1008+
print(io, " from ", def, " starting at ", line)
1009+
end
9991010
end
10001011
end
10011012

base/stacktraces.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ function show_spec_linfo(io::IO, frame::StackFrame)
241241
Base.show_tuple_as_call(io, def.name, sig, true, nothing, argnames)
242242
end
243243
else
244-
Base.show(io, linfo)
244+
Base.show_mi(io, linfo, true)
245245
end
246246
elseif linfo isa CodeInfo
247247
print(io, "top-level scope")

test/backtrace.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ let code = """
254254
"""
255255

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

0 commit comments

Comments
 (0)