Skip to content

Commit a44318f

Browse files
authored
Merge pull request #347 from timholy/teh/nightly
Fix tests on Julia nightly
2 parents 479bb48 + 83c504b commit a44318f

File tree

3 files changed

+55
-24
lines changed

3 files changed

+55
-24
lines changed

src/invalidations.jl

+10
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ end
168168

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

171+
function Base.:(==)(methinvs1::MethodInvalidations, methinvs2::MethodInvalidations)
172+
methinvs1.method == methinvs2.method || return false
173+
methinvs1.reason == methinvs2.reason || return false
174+
methinvs1.mt_backedges == methinvs2.mt_backedges || return false
175+
methinvs1.backedges == methinvs2.backedges || return false
176+
methinvs1.mt_cache == methinvs2.mt_cache || return false
177+
methinvs1.mt_disable == methinvs2.mt_disable || return false
178+
return true
179+
end
180+
171181
countchildren(sigtree::Pair{<:Any,Union{InstanceNode,MethodInstance}}) = countchildren(sigtree.second)
172182
countchildren(::MethodInstance) = 1
173183

test/snoopi_deep.jl

+16-8
Original file line numberDiff line numberDiff line change
@@ -879,7 +879,7 @@ end
879879
@test :build_stale stalenames
880880
@test :use_stale stalenames
881881
trees = invalidation_trees(invalidations)
882-
tree = trees[findfirst(tree -> !isempty(tree.backedges), trees)]
882+
tree = length(trees) == 1 ? only(trees) : trees[findfirst(tree -> !isempty(tree.backedges), trees)]
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"
@@ -913,20 +913,19 @@ end
913913
@test sig == mi_stale
914914
@test convert(Core.MethodInstance, root) == Core.MethodInstance(only(hits)) == methodinstance(StaleB.useA, ())
915915
# What happens when we can't find it in the tree?
916-
pipe = Pipe() # suppress warning
917916
if any(isequal("verify_methods"), invalidations)
918917
# The 1.9+ format
919918
invscopy = copy(invalidations)
920919
idx = findlast(==("verify_methods"), invscopy)
921920
invscopy[idx+1] = 22
922-
redirect_stderr(pipe) do
921+
redirect_stderr(devnull) do
923922
broken_trees = invalidation_trees(invscopy)
924923
@test isempty(precompile_blockers(broken_trees, tinf))
925924
end
926925
else
927926
# The older format
928927
idx = findfirst(isequal("jl_method_table_insert"), invalidations)
929-
redirect_stdout(pipe) do
928+
redirect_stdout(devnull) do
930929
broken_trees = invalidation_trees(invalidations[idx+1:end])
931930
@test isempty(precompile_blockers(broken_trees, tinf))
932931
end
@@ -958,10 +957,19 @@ end
958957

959958
if Base.VERSION >= v"1.7"
960959
@testset "JET integration" begin
961-
f(c) = sum(c[1])
962-
c = Any[Any[1,2,3]]
963-
tinf = @snoopi_deep f(c)
964-
rpt = SnoopCompile.JET.@report_call f(c)
960+
function mysum(c) # vendor a simple version of `sum`
961+
isempty(c) && return zero(eltype(c))
962+
s = first(c)
963+
for x in Iterators.drop(c, 1)
964+
s += x
965+
end
966+
return s
967+
end
968+
call_mysum(cc) = mysum(cc[1])
969+
970+
cc = Any[Any[1,2,3]]
971+
tinf = @snoopi_deep call_mysum(cc)
972+
rpt = SnoopCompile.JET.@report_call call_mysum(cc)
965973
@test isempty(SnoopCompile.JET.get_reports(rpt))
966974
itrigs = inference_triggers(tinf)
967975
irpts = report_callees(itrigs)

test/snoopr.jl

+29-16
Original file line numberDiff line numberDiff line change
@@ -102,15 +102,18 @@ end
102102
# These next are identical to the above
103103
@test methinvs.method == m
104104
@test methinvs.reason === :inserting
105-
root = only(methinvs.backedges)
106-
@test root.mi == mi3
107-
@test SnoopCompile.getroot(root) === root
108-
@test root.depth == 0
109-
child = only(root.children)
110-
@test child.mi == mi1
111-
@test SnoopCompile.getroot(child) === root
112-
@test child.depth == 1
113-
if isempty(child.children)
105+
have_backedges = !isempty(methinvs.backedges)
106+
if have_backedges
107+
root = only(methinvs.backedges)
108+
@test root.mi == mi3
109+
@test SnoopCompile.getroot(root) === root
110+
@test root.depth == 0
111+
child = only(root.children)
112+
@test child.mi == mi1
113+
@test SnoopCompile.getroot(child) === root
114+
@test child.depth == 1
115+
end
116+
if isempty(methinvs.backedges) || isempty(child.children)
114117
# the mt_backedges got invalidated first
115118
sig, root = only(methinvs.mt_backedges)
116119
@test sig === Tuple{typeof(Main.SnooprTests.f), Any}
@@ -132,8 +135,13 @@ end
132135
print(io, methinvs)
133136
str = String(take!(io))
134137
@test startswith(str, "inserting f(::Float32)")
135-
@test occursin("backedges: 1: superseding f(::AbstractFloat)", str)
136-
@test occursin("with MethodInstance for $(prefix)f(::AbstractFloat) ($targetdepth children)", str)
138+
if !isempty(methinvs.backedges)
139+
@test occursin("backedges: 1: superseding f(::AbstractFloat)", str)
140+
@test occursin("with MethodInstance for $(prefix)f(::AbstractFloat) ($targetdepth children)", str)
141+
else
142+
@test occursin("signature Tuple{typeof($(prefix)f), Any} triggered", str)
143+
@test occursin("for $(prefix)applyf(::Vector{Any}) ($targetdepth children)", str)
144+
end
137145

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

156-
ftrees = filtermod(@__MODULE__, trees)
157-
ftree = only(ftrees)
158-
@test ftree.backedges == methinvs.backedges
159-
@test isempty(ftree.mt_backedges)
164+
if have_backedges
165+
ftrees = filtermod(@__MODULE__, trees)
166+
ftree = only(ftrees)
167+
@test ftree.backedges == methinvs.backedges
168+
@test isempty(ftree.mt_backedges)
169+
else
170+
ftrees = filtermod(SnooprTests, trees)
171+
@test ftrees == trees
172+
end
160173

161174
cai = Any[1]
162175
cas = Any[:sym]
@@ -201,7 +214,7 @@ end
201214
@test occursin("Invalidations %", str)
202215

203216
trees = invalidation_trees(invs)
204-
@test length(trees) == 3
217+
@test length(trees) >= 3
205218
io = IOBuffer()
206219
show(io, trees)
207220
str = String(take!(io))

0 commit comments

Comments
 (0)