Skip to content

Commit e4fe254

Browse files
authored
Target verify_methods to backedges (#359)
These were incorrectly assigned to mt_backedges. Fixes #357
1 parent 85d38e8 commit e4fe254

File tree

3 files changed

+30
-15
lines changed

3 files changed

+30
-15
lines changed

src/invalidations.jl

+14-5
Original file line numberDiff line numberDiff line change
@@ -156,12 +156,12 @@ end
156156
struct MethodInvalidations
157157
method::Method
158158
reason::Symbol # :inserting or :deleting
159-
mt_backedges::Vector{Pair{Any,Union{InstanceNode,MethodInstance}}} # sig=>root for immediate, calleemi=>callermi for delayed
159+
mt_backedges::Vector{Pair{Type,Union{InstanceNode,MethodInstance}}} # sig=>root
160160
backedges::Vector{InstanceNode}
161161
mt_cache::Vector{MethodInstance}
162162
mt_disable::Vector{MethodInstance}
163163
end
164-
methinv_storage() = Pair{Any,InstanceNode}[], InstanceNode[], MethodInstance[], MethodInstance[]
164+
methinv_storage() = Pair{Type,InstanceNode}[], InstanceNode[], MethodInstance[], MethodInstance[]
165165
function MethodInvalidations(method::Method, reason::Symbol)
166166
MethodInvalidations(method, reason, methinv_storage()...)
167167
end
@@ -467,9 +467,18 @@ function invalidation_trees(list; exclude_corecompiler::Bool=true)
467467
ret = get(backedge_table, next, nothing)
468468
ret === nothing && (@warn "$next not found in `backedge_table`"; continue)
469469
trig, causes = ret
470-
newnode = InstanceNode(mi, 1)
471-
push!(mt_backedges, trig => newnode)
472-
backedge_table[mi] = newnode
470+
if isa(trig, MethodInstance)
471+
newnode = InstanceNode(trig, 1)
472+
push!(backedges, newnode)
473+
newchild = InstanceNode(mi, 2)
474+
push!(newnode.children, newchild)
475+
backedge_table[trig] = newnode
476+
backedge_table[mi] = newchild
477+
else
478+
newnode = InstanceNode(mi, 1)
479+
push!(mt_backedges, trig => newnode)
480+
backedge_table[mi] = newnode
481+
end
473482
for cause in causes
474483
add_method_trigger!(methodinvs, cause, :inserting, mt_backedges, backedges, mt_cache, mt_disable)
475484
end

test/snoopi_deep.jl

+13-9
Original file line numberDiff line numberDiff line change
@@ -883,10 +883,14 @@ end
883883
@test tree.method == which(StaleA.stale, (String,)) # defined in StaleC
884884
@test all(be -> Core.MethodInstance(be).def == which(StaleA.stale, (Any,)), tree.backedges)
885885
if Base.VERSION > v"1.8.0-DEV.368"
886-
tree = trees[findfirst(tree -> !isempty(tree.mt_backedges), trees)]
887-
@test only(tree.mt_backedges).first.def == which(StaleA.stale, (Any,))
888-
@test which(only(tree.mt_backedges).first.specTypes) == which(StaleA.stale, (String,))
889-
@test convert(Core.MethodInstance, only(tree.mt_backedges).second).def == which(StaleB.useA, ())
886+
root = only(filter(tree.backedges) do be
887+
Core.MethodInstance(be).specTypes.parameters[end] === String
888+
end)
889+
@test convert(Core.MethodInstance, root.children[1]).def == which(StaleB.useA, ())
890+
m2 = which(StaleB.useA2, ())
891+
if any(item -> isa(item, Core.MethodInstance) && item.def == m2, invalidations) # requires julia#49449
892+
@test convert(Core.MethodInstance, root.children[1].children[1]).def == m2
893+
end
890894
tinf = @snoopi_deep begin
891895
StaleB.useA()
892896
StaleC.call_buildstale("hi")
@@ -908,10 +912,10 @@ end
908912
# If we don't discount ones left in an invalidated state,
909913
# we get mt_backedges with a MethodInstance middle entry too
910914
strees2 = precompile_blockers(invalidations, tinf; min_world_exclude=0)
911-
sig, root, hits = only(only(strees2).mt_backedges)
915+
root, hits = only(only(strees2).backedges)
912916
mi_stale = only(filter(mi -> endswith(String(mi.def.file), "StaleA.jl"), methodinstances(StaleA.stale, (String,))))
913-
@test sig == mi_stale
914-
@test convert(Core.MethodInstance, root) == Core.MethodInstance(only(hits)) == methodinstance(StaleB.useA, ())
917+
@test Core.MethodInstance(root) == mi_stale
918+
@test Core.MethodInstance(only(hits)) == methodinstance(StaleB.useA, ())
915919
# What happens when we can't find it in the tree?
916920
if any(isequal("verify_methods"), invalidations)
917921
# The 1.9+ format
@@ -933,7 +937,7 @@ end
933937
# IO
934938
io = IOBuffer()
935939
print(io, trees)
936-
@test occursin(r"stale\(x::String\) (in|@) StaleC.*formerly stale\(x\) (in|@) StaleA", String(take!(io)))
940+
@test occursin(r"stale\(x::String\) (in|@) StaleC", String(take!(io)))
937941
if !healed
938942
print(io, strees)
939943
str = String(take!(io))
@@ -949,7 +953,7 @@ end
949953
print(io, only(strees2))
950954
str = String(take!(io))
951955
@test occursin(r"inserting stale\(.* (in|@) StaleC.*invalidated:", str)
952-
@test occursin("mt_backedges", str)
956+
@test !occursin("mt_backedges", str)
953957
@test occursin(r"blocked.*InferenceTimingNode: .*/.* on StaleB.useA", str)
954958
end
955959
Pkg.activate(cproj)

test/testmodules/Stale/StaleB/src/StaleB.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ using StaleA
77

88
# This will be invalidated if StaleC is loaded
99
useA() = StaleA.stale("hello")
10+
useA2() = useA()
11+
useA3() = useA2()
1012

1113
# force precompilation
12-
useA()
14+
useA3()
1315

1416
end

0 commit comments

Comments
 (0)