Skip to content

Commit 41fb2e4

Browse files
timholyrikhuijzer
andcommitted
Update invalidation logging format
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. Co-authored-by: Rik Huijzer <[email protected]>
1 parent f4d9a7b commit 41fb2e4

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "SnoopCompile"
22
uuid = "aa65fe97-06da-5843-b5b1-d5d13cad87d2"
33
author = ["Tim Holy <[email protected]>"]
4-
version = "2.9.4"
4+
version = "2.9.5"
55

66
[deps]
77
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"

src/invalidations.jl

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ mutable struct InstanceNode
6363
end
6464
InstanceNode(mi::MethodInstance, children::Vector{InstanceNode}) = return new(mi, 0, children)
6565
# Create child with a given `parent`. Checks that the depths are consistent.
66-
function InstanceNode(mi::MethodInstance, parent::InstanceNode, depth)
67-
@assert parent.depth + Int32(1) == depth
66+
function InstanceNode(mi::MethodInstance, parent::InstanceNode, depth=parent.depth+Int32(1))
67+
depth !== nothing && @assert parent.depth + Int32(1) == depth
6868
child = new(mi, depth, InstanceNode[], parent)
6969
push!(parent.children, child)
7070
return child
@@ -249,6 +249,12 @@ function showlist(io::IO, treelist, indent::Int=0)
249249
end
250250
end
251251

252+
if Base.VERSION >= v"1.9.0-DEV.1512"
253+
new_backedge_table() = Dict{Union{Int32,MethodInstance},Union{Tuple{Any,Vector{Any}},InstanceNode}}()
254+
else
255+
new_backedge_table() = Dict{Tuple{Int32,UInt64},Tuple{Any,Vector{Any}}}()
256+
end
257+
252258
"""
253259
trees = invalidation_trees(list)
254260
@@ -288,6 +294,11 @@ See the documentation for further details.
288294
function invalidation_trees(list; exclude_corecompiler::Bool=true)
289295

290296
function handle_insert_backedges(list, i, callee)
297+
if Base.VERSION >= v"1.9.0-DEV.1512"
298+
key, causes = list[i+=1], list[i+=1]
299+
backedge_table[key] = (callee, causes)
300+
return i
301+
end
291302
if Base.VERSION >= v"1.9.0-DEV.1432"
292303
key = (list[i+=1], list[i+=1])
293304
backedge_table[key] = (callee, list[i+=1])
@@ -316,7 +327,7 @@ function invalidation_trees(list; exclude_corecompiler::Bool=true)
316327
leaf = nothing
317328
mt_backedges, backedges, mt_cache, mt_disable = methinv_storage()
318329
reason = nothing
319-
backedge_table = Dict{Tuple{Int32,UInt64},Tuple{Any,Vector{Any}}}()
330+
backedge_table = new_backedge_table()
320331
i = 0
321332
while i < length(list)
322333
item = list[i+=1]
@@ -337,6 +348,9 @@ function invalidation_trees(list; exclude_corecompiler::Bool=true)
337348
end
338349
elseif isa(item, String)
339350
loctag = item
351+
if Base.VERSION >= v"1.9.0-DEV.1512" && loctag ("insert_backedges_callee", "verify_methods")
352+
empty!(backedge_table)
353+
end
340354
if loctag == "invalidate_mt_cache"
341355
push!(mt_cache, mi)
342356
leaf = nothing
@@ -371,6 +385,36 @@ function invalidation_trees(list; exclude_corecompiler::Bool=true)
371385
end
372386
elseif loctag == "insert_backedges_callee"
373387
i = handle_insert_backedges(list, i, mi)
388+
elseif loctag == "verify_methods"
389+
next = list[i+=1]
390+
if isa(next, Integer)
391+
trig, causes = backedge_table[next]
392+
newnode = InstanceNode(mi, 1)
393+
push!(mt_backedges, trig => newnode)
394+
backedge_table[mi] = newnode
395+
for cause in causes
396+
add_method_trigger!(methodinvs, cause, :inserting, mt_backedges, backedges, mt_cache, mt_disable)
397+
end
398+
mt_backedges, backedges, mt_cache, mt_disable = methinv_storage()
399+
leaf = nothing
400+
reason = nothing
401+
else
402+
@assert isa(next, MethodInstance) "unexpected logging format"
403+
parent = backedge_table[next]
404+
found = false
405+
for child in parent.children
406+
if child.mi == mi
407+
found = true
408+
break
409+
end
410+
end
411+
if !found
412+
newnode = InstanceNode(mi, parent)
413+
if !haskey(backedge_table, mi)
414+
backedge_table[mi] = newnode
415+
end
416+
end
417+
end
374418
elseif loctag == "insert_backedges"
375419
if Base.VERSION >= v"1.9.0-DEV.1432"
376420
key = (list[i+=1], list[i+=1])

0 commit comments

Comments
 (0)