Skip to content

Commit

Permalink
Update invalidation logging format (#306)
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
during deserialization (JuliaLang/julia#46920)
suggests this format may have some durability.

Co-authored-by: Rik Huijzer <[email protected]>
  • Loading branch information
timholy and rikhuijzer authored Oct 15, 2022
1 parent f4d9a7b commit ad792af
Show file tree
Hide file tree
Showing 3 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 <[email protected]>"]
version = "2.9.4"
version = "2.9.5"

[deps]
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Expand Down
2 changes: 1 addition & 1 deletion SnoopPrecompile/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ using UUIDs
end
close(pipe.in)
str = read(pipe.out, String)
@test occursin("UndefVarError: missing_function not defined", str)
@test occursin(r"UndefVarError: `?missing_function`? not defined", str)
end
end
50 changes: 47 additions & 3 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 @@ -371,6 +385,36 @@ function invalidation_trees(list; exclude_corecompiler::Bool=true)
end
elseif loctag == "insert_backedges_callee"
i = handle_insert_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

2 comments on commit ad792af

@timholy
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/70305

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v2.9.5 -m "<description of version>" ad792afcb320971231128479cff9baa3bd1245d0
git push origin v2.9.5

Please sign in to comment.