Skip to content

[RFC] Log a backtrace on entrance to type inference (option 2) #58124

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 10 additions & 0 deletions Compiler/src/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1410,9 +1410,15 @@ function add_codeinsts_to_jit!(interp::AbstractInterpreter, ci, source_mode::UIn
return ci
end

const collect_dispatch_backtrace = fill(false)
const dispatch_backtrace = IdDict{CodeInstance,Any}()

function typeinf_ext_toplevel(interp::AbstractInterpreter, mi::MethodInstance, source_mode::UInt8)
ci = typeinf_ext(interp, mi, source_mode)
ci = add_codeinsts_to_jit!(interp, ci, source_mode)
if collect_dispatch_backtrace[]
dispatch_backtrace[ci] = backtrace()
end
return ci
end

Expand All @@ -1432,6 +1438,7 @@ function typeinf_ext_toplevel(methods::Vector{Any}, worlds::Vector{UInt}, trim_m
inspected = IdSet{CodeInstance}()
tocompile = Vector{CodeInstance}()
codeinfos = []
bt = collect_dispatch_backtrace[] ? backtrace() : nothing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is not actually relevant to dispatch, so these additional changes (just the first one) should not be included in this PR

# first compute the ABIs of everything
latest = true # whether this_world == world_counter()
for this_world in reverse(sort!(worlds))
Expand Down Expand Up @@ -1469,6 +1476,9 @@ function typeinf_ext_toplevel(methods::Vector{Any}, worlds::Vector{UInt}, trim_m
end
while !isempty(tocompile)
callee = pop!(tocompile)
if collect_dispatch_backtrace[]
dispatch_backtrace[callee] = bt
end
callee in inspected && continue
# now make sure everything has source code, if desired
mi = get_ci_mi(callee)
Expand Down