Skip to content

Commit

Permalink
Update invalidation logging format
Browse files Browse the repository at this point in the history
This updates to the logging format used by the most recent nightly build
of Julia (1.9). While there has been a lot of churn in this area, there
are reasons to hope that we're entering a period of stability: there are
no known "holes" in our coverage after resolving the `invoke` issues
(JuliaLang/julia#46010 and fixup PRs that came
later), and the subsequent major rewrite of the invalidation logic
(JuliaLang/julia#46920) suggests this format may
have some durability.
  • Loading branch information
timholy committed Oct 15, 2022
1 parent f4d9a7b commit 36757bd
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SnoopCompile"
uuid = "aa65fe97-06da-5843-b5b1-d5d13cad87d2"
author = ["Tim Holy <tim.holy@gmail.com>"]
version = "2.9.4"
version = "2.9.5"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
52 changes: 48 additions & 4 deletions src/invalidations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ mutable struct InstanceNode
end
InstanceNode(mi::MethodInstance, children::Vector{InstanceNode}) = return new(mi, 0, children)
# Create child with a given `parent`. Checks that the depths are consistent.
function InstanceNode(mi::MethodInstance, parent::InstanceNode, depth)
@assert parent.depth + Int32(1) == depth
function InstanceNode(mi::MethodInstance, parent::InstanceNode, depth=parent.depth+Int32(1))
depth !== nothing && @assert parent.depth + Int32(1) == depth
child = new(mi, depth, InstanceNode[], parent)
push!(parent.children, child)
return child
Expand Down Expand Up @@ -249,6 +249,12 @@ function showlist(io::IO, treelist, indent::Int=0)
end
end

if Base.VERSION >= v"1.9.0-DEV.1512"
new_backedge_table() = Dict{Union{Int32,MethodInstance},Union{Tuple{Any,Vector{Any}},InstanceNode}}()
else
new_backedge_table() = Dict{Tuple{Int32,UInt64},Tuple{Any,Vector{Any}}}()
end

"""
trees = invalidation_trees(list)
Expand Down Expand Up @@ -288,6 +294,11 @@ See the documentation for further details.
function invalidation_trees(list; exclude_corecompiler::Bool=true)

function handle_insert_backedges(list, i, callee)
if Base.VERSION >= v"1.9.0-DEV.1512"
key, causes = list[i+=1], list[i+=1]
backedge_table[key] = (callee, causes)
return i
end
if Base.VERSION >= v"1.9.0-DEV.1432"
key = (list[i+=1], list[i+=1])
backedge_table[key] = (callee, list[i+=1])
Expand Down Expand Up @@ -316,7 +327,7 @@ function invalidation_trees(list; exclude_corecompiler::Bool=true)
leaf = nothing
mt_backedges, backedges, mt_cache, mt_disable = methinv_storage()
reason = nothing
backedge_table = Dict{Tuple{Int32,UInt64},Tuple{Any,Vector{Any}}}()
backedge_table = new_backedge_table()
i = 0
while i < length(list)
item = list[i+=1]
Expand All @@ -337,6 +348,9 @@ function invalidation_trees(list; exclude_corecompiler::Bool=true)
end
elseif isa(item, String)
loctag = item
if Base.VERSION >= v"1.9.0-DEV.1512" && loctag ("insert_backedges_callee", "verify_methods")
empty!(backedge_table)
end
if loctag == "invalidate_mt_cache"
push!(mt_cache, mi)
leaf = nothing
Expand Down Expand Up @@ -370,7 +384,37 @@ function invalidation_trees(list; exclude_corecompiler::Bool=true)
leaf = nothing
end
elseif loctag == "insert_backedges_callee"
i = handle_insert_backedges(list, i, mi)
i = handle_insert_backedges!(mt_backedges, backedges, list, i, mi)
elseif loctag == "verify_methods"
next = list[i+=1]
if isa(next, Integer)
trig, causes = backedge_table[next]
newnode = InstanceNode(mi, 1)
push!(mt_backedges, trig => newnode)
backedge_table[mi] = newnode
for cause in causes
add_method_trigger!(methodinvs, cause, :inserting, mt_backedges, backedges, mt_cache, mt_disable)
end
mt_backedges, backedges, mt_cache, mt_disable = methinv_storage()
leaf = nothing
reason = nothing
else
@assert isa(next, MethodInstance) "unexpected logging format"
parent = backedge_table[next]
found = false
for child in parent.children
if child.mi == mi
found = true
break
end
end
if !found
newnode = InstanceNode(mi, parent)
if !haskey(backedge_table, mi)
backedge_table[mi] = newnode
end
end
end
elseif loctag == "insert_backedges"
if Base.VERSION >= v"1.9.0-DEV.1432"
key = (list[i+=1], list[i+=1])
Expand Down

0 comments on commit 36757bd

Please sign in to comment.