Skip to content

Commit

Permalink
Merge pull request #347 from timholy/teh/nightly
Browse files Browse the repository at this point in the history
Fix tests on Julia nightly
  • Loading branch information
timholy authored Mar 21, 2023
2 parents 479bb48 + 83c504b commit a44318f
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 24 deletions.
10 changes: 10 additions & 0 deletions src/invalidations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,16 @@ end

Base.isempty(methinvs::MethodInvalidations) = isempty(methinvs.mt_backedges) && isempty(methinvs.backedges) # ignore mt_cache

function Base.:(==)(methinvs1::MethodInvalidations, methinvs2::MethodInvalidations)
methinvs1.method == methinvs2.method || return false
methinvs1.reason == methinvs2.reason || return false
methinvs1.mt_backedges == methinvs2.mt_backedges || return false
methinvs1.backedges == methinvs2.backedges || return false
methinvs1.mt_cache == methinvs2.mt_cache || return false
methinvs1.mt_disable == methinvs2.mt_disable || return false
return true
end

countchildren(sigtree::Pair{<:Any,Union{InstanceNode,MethodInstance}}) = countchildren(sigtree.second)
countchildren(::MethodInstance) = 1

Expand Down
24 changes: 16 additions & 8 deletions test/snoopi_deep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ end
@test :build_stale stalenames
@test :use_stale stalenames
trees = invalidation_trees(invalidations)
tree = trees[findfirst(tree -> !isempty(tree.backedges), trees)]
tree = length(trees) == 1 ? only(trees) : trees[findfirst(tree -> !isempty(tree.backedges), trees)]
@test tree.method == which(StaleA.stale, (String,)) # defined in StaleC
@test all(be -> Core.MethodInstance(be).def == which(StaleA.stale, (Any,)), tree.backedges)
if Base.VERSION > v"1.8.0-DEV.368"
Expand Down Expand Up @@ -913,20 +913,19 @@ end
@test sig == mi_stale
@test convert(Core.MethodInstance, root) == Core.MethodInstance(only(hits)) == methodinstance(StaleB.useA, ())
# What happens when we can't find it in the tree?
pipe = Pipe() # suppress warning
if any(isequal("verify_methods"), invalidations)
# The 1.9+ format
invscopy = copy(invalidations)
idx = findlast(==("verify_methods"), invscopy)
invscopy[idx+1] = 22
redirect_stderr(pipe) do
redirect_stderr(devnull) do
broken_trees = invalidation_trees(invscopy)
@test isempty(precompile_blockers(broken_trees, tinf))
end
else
# The older format
idx = findfirst(isequal("jl_method_table_insert"), invalidations)
redirect_stdout(pipe) do
redirect_stdout(devnull) do
broken_trees = invalidation_trees(invalidations[idx+1:end])
@test isempty(precompile_blockers(broken_trees, tinf))
end
Expand Down Expand Up @@ -958,10 +957,19 @@ end

if Base.VERSION >= v"1.7"
@testset "JET integration" begin
f(c) = sum(c[1])
c = Any[Any[1,2,3]]
tinf = @snoopi_deep f(c)
rpt = SnoopCompile.JET.@report_call f(c)
function mysum(c) # vendor a simple version of `sum`
isempty(c) && return zero(eltype(c))
s = first(c)
for x in Iterators.drop(c, 1)
s += x
end
return s
end
call_mysum(cc) = mysum(cc[1])

cc = Any[Any[1,2,3]]
tinf = @snoopi_deep call_mysum(cc)
rpt = SnoopCompile.JET.@report_call call_mysum(cc)
@test isempty(SnoopCompile.JET.get_reports(rpt))
itrigs = inference_triggers(tinf)
irpts = report_callees(itrigs)
Expand Down
45 changes: 29 additions & 16 deletions test/snoopr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,18 @@ end
# These next are identical to the above
@test methinvs.method == m
@test methinvs.reason === :inserting
root = only(methinvs.backedges)
@test root.mi == mi3
@test SnoopCompile.getroot(root) === root
@test root.depth == 0
child = only(root.children)
@test child.mi == mi1
@test SnoopCompile.getroot(child) === root
@test child.depth == 1
if isempty(child.children)
have_backedges = !isempty(methinvs.backedges)
if have_backedges
root = only(methinvs.backedges)
@test root.mi == mi3
@test SnoopCompile.getroot(root) === root
@test root.depth == 0
child = only(root.children)
@test child.mi == mi1
@test SnoopCompile.getroot(child) === root
@test child.depth == 1
end
if isempty(methinvs.backedges) || isempty(child.children)
# the mt_backedges got invalidated first
sig, root = only(methinvs.mt_backedges)
@test sig === Tuple{typeof(Main.SnooprTests.f), Any}
Expand All @@ -132,8 +135,13 @@ end
print(io, methinvs)
str = String(take!(io))
@test startswith(str, "inserting f(::Float32)")
@test occursin("backedges: 1: superseding f(::AbstractFloat)", str)
@test occursin("with MethodInstance for $(prefix)f(::AbstractFloat) ($targetdepth children)", str)
if !isempty(methinvs.backedges)
@test occursin("backedges: 1: superseding f(::AbstractFloat)", str)
@test occursin("with MethodInstance for $(prefix)f(::AbstractFloat) ($targetdepth children)", str)
else
@test occursin("signature Tuple{typeof($(prefix)f), Any} triggered", str)
@test occursin("for $(prefix)applyf(::Vector{Any}) ($targetdepth children)", str)
end

show(io, root; minchildren=1)
str = String(take!(io))
Expand All @@ -153,10 +161,15 @@ end
"MethodInstance for $(prefix)applyf(::$(Vector{Any})) (1 children)")
@test lines[2] == ""

ftrees = filtermod(@__MODULE__, trees)
ftree = only(ftrees)
@test ftree.backedges == methinvs.backedges
@test isempty(ftree.mt_backedges)
if have_backedges
ftrees = filtermod(@__MODULE__, trees)
ftree = only(ftrees)
@test ftree.backedges == methinvs.backedges
@test isempty(ftree.mt_backedges)
else
ftrees = filtermod(SnooprTests, trees)
@test ftrees == trees
end

cai = Any[1]
cas = Any[:sym]
Expand Down Expand Up @@ -201,7 +214,7 @@ end
@test occursin("Invalidations %", str)

trees = invalidation_trees(invs)
@test length(trees) == 3
@test length(trees) >= 3
io = IOBuffer()
show(io, trees)
str = String(take!(io))
Expand Down

0 comments on commit a44318f

Please sign in to comment.