Skip to content

Commit

Permalink
Allow a Tuple{typeof(f),...} as root of ascend tree
Browse files Browse the repository at this point in the history
  • Loading branch information
timholy committed Aug 15, 2024
1 parent b0dd201 commit c35cd0a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Cthulhu"
uuid = "f68482b8-f384-11e8-15f7-abe071a5a75f"
authors = ["Valentin Churavy <[email protected]> and contributors"]
version = "2.13.0"
version = "2.14.0"

[deps]
CodeTracking = "da1fd8a2-8d9e-5ec2-8556-3022fb5608a2"
Expand Down
4 changes: 3 additions & 1 deletion src/backedges.jl
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ specTypes(mi::MethodInstance) = mi.specTypes
instance(mi::MethodInstance) = mi
nextnode(mi, edge) = edge

instance(@nospecialize(tt::Type)) = tt

instance(sfs::Vector{StackTraces.StackFrame}) = isempty(sfs) ? CC.Timings.ROOTmi : sfs[end].linfo::MethodInstance # we checked this type condition within `buildframes`
method(sfs::Vector{StackTraces.StackFrame}) = method(instance(sfs))
backedges(sframes::Vector{StackTraces.StackFrame}) = (ret = sframes[2:end]; isempty(ret) ? () : (ret,))
Expand Down Expand Up @@ -188,7 +190,7 @@ function treelist!(parent::Node, io::IO, mi, indent::AbstractString, visited::Ba
indent *= " "
for edge in backedges(mi)
str = indent * callstring(io, edge)
child = Node(Data(str, instance(edge)), parent)
child = Node(typeof(parent.data)(str, instance(edge)), parent)
treelist!(child, io, nextnode(mi, edge), indent, visited)
end
return parent
Expand Down
10 changes: 10 additions & 0 deletions src/callsite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ end

# maybe_callsite for higher-level inputs
maybe_callsite(cs::Callsite, callee::MethodInstance) = maybe_callsite(cs.info, callee)
maybe_callsite(cs::Callsite, @nospecialize(tt::Type)) = maybe_callsite(cs.info, tt)
maybe_callsite(info::CallInfo, callee::MethodInstance) = maybe_callsite(get_mi(info), callee)
# Special CallInfo cases:
function maybe_callsite(info::MultiCallInfo, callee::MethodInstance)
Expand All @@ -517,4 +518,13 @@ end
maybe_callsite(info::PureCallInfo, mi::MethodInstance) = mi.specTypes <: Tuple{mapany(Core.Typeof ∘ unwrapconst, info.argtypes)...}
maybe_callsite(info::RTCallInfo, mi::MethodInstance) = false

function maybe_callsite(info::RTCallInfo, @nospecialize(tt::Type))
info.f === tt.parameters[1] && info.argtyps == tt.parameters[2:end]
end
function maybe_callsite(info::MICallInfo, @nospecialize(tt::Type))
info.mi.specTypes <: tt
end

maybe_callsite(info::CallInfo, @nospecialize(tt::Type)) = false

unwrapconst(@nospecialize(arg)) = arg isa Core.Const ? arg.val : arg
2 changes: 1 addition & 1 deletion src/reflection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ function callinfo(sig, rt, max_methods=-1; world=get_world_counter())
return MultiCallInfo(sig, rt, callinfos)
end

function find_caller_of(interp::AbstractInterpreter, callee::MethodInstance, caller::MethodInstance; allow_unspecialized::Bool=false)
function find_caller_of(interp::AbstractInterpreter, callee::Union{MethodInstance,Type}, caller::MethodInstance; allow_unspecialized::Bool=false)
interp′ = CthulhuInterpreter(interp)
do_typeinf!(interp′, caller)
locs = Tuple{Core.LineInfoNode,Int}[]
Expand Down

0 comments on commit c35cd0a

Please sign in to comment.