Skip to content

Commit fedf447

Browse files
authored
Support Core.Compiler.InterpreterIP in building stacktraces (#38566)
The new inference timing captures a backtrace for each descent into inference as a mechanism to find out who it was triggered by. This allows us to convert those backtraces to stacktraces.
1 parent 630acfc commit fedf447

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

base/stacktraces.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ end
118118

119119
const top_level_scope_sym = Symbol("top-level scope")
120120

121-
function lookup(ip::Base.InterpreterIP)
121+
function lookup(ip::Union{Base.InterpreterIP,Core.Compiler.InterpreterIP})
122122
code = ip.code
123123
if code === nothing
124124
# interpreted top-level expression with no CodeInfo
@@ -157,7 +157,7 @@ Returns a stack trace in the form of a vector of `StackFrame`s. (By default stac
157157
doesn't return C functions, but this can be enabled.) When called without specifying a
158158
trace, `stacktrace` first calls `backtrace`.
159159
"""
160-
function stacktrace(trace::Vector{<:Union{Base.InterpreterIP,Ptr{Cvoid}}}, c_funcs::Bool=false)
160+
function stacktrace(trace::Vector{<:Union{Base.InterpreterIP,Core.Compiler.InterpreterIP,Ptr{Cvoid}}}, c_funcs::Bool=false)
161161
stack = StackTrace()
162162
for ip in trace
163163
for frame in lookup(ip)

test/compiler/inference.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2885,6 +2885,8 @@ end
28852885
@test sort([mi_info.mi.def.name for (time,mi_info) in flatten_times(timing1)[end-1:end]]) == [:i, :i2]
28862886
@test all(child->isa(child.bt, Vector), timing1.children)
28872887
@test all(child->child.bt===nothing, timing1.children[1].children)
2888+
# Test the stacktrace
2889+
@test isa(stacktrace(timing1.children[1].bt), Vector{Base.StackTraces.StackFrame})
28882890
# Test that inference has cached some of the Method Instances
28892891
timing2 = time_inference() do
28902892
@eval M.g(2, 3.0)

0 commit comments

Comments
 (0)