Skip to content

Commit d54b626

Browse files
committed
Make some tests warnings, not errors
1 parent fee3f0d commit d54b626

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

test/inference_qa.jl

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# This file is a part of Julia. License is MIT: https://julialang.org/license
22

3-
# The aim of these tests is to enforce a minimum quality of inferrability of Julia's
4-
# Base and specifically its precompiled methods. Passing these tests does not
5-
# indicate that Julia has no inference problems, but they are designed to catch some
6-
# inadvertent problems. While `@inferred` only tests the return type, the tests
7-
# in this file are designed to check the overall inference quality of method *internals*.
3+
# The aim of these tests is to enforce "quality assurance" for inferrability of Julia's
4+
# Base and specifically its precompiled methods. Passing these tests & warnings does not
5+
# indicate that Julia has no inference problems, but they are designed to reveal what
6+
# would otherwise be hidden problems. While `@inferred` only tests the return type, the tests
7+
# in this file are designed to check the overall inference quality of method internals.
88

9-
# If you fail tests here, you can usually fix problems using `@code_warntype` or Cthulhu.jl's `@descend`.
9+
# If you fail tests or get new warnings here, you can usually fix problems using
10+
# `@code_warntype` or Cthulhu.jl's `@descend`.
1011

1112
using Test
1213

@@ -84,9 +85,8 @@ end
8485
@test isempty(remove_unlikely_methodinstances(atrisk_triggers(m, first.(mivulnerabilities_exported))))
8586

8687
# It's far less important to protect against invalidation of private functions,
87-
# since generally packages should not extend these functions. Nevertheless it wouldn't
88-
# be a bad thing.
89-
@test_broken isempty(remove_unlikely_methodinstances(atrisk_triggers(m, first.(mivulnerabilities_private))))
88+
# since generally packages should not extend these functions.
89+
# @test_broken isempty(remove_unlikely_methodinstances(atrisk_triggers(m, first.(mivulnerabilities_private))))
9090
end
9191
end
9292

@@ -104,13 +104,17 @@ end
104104
# Test overall number of atrisk MethodInstances and their average number of backedges
105105
badexp = Set(remove_unlikely_methodinstances(first.(mivulnerabilities_exported)))
106106
badcounts = filter(pr->pr.first badexp, mivulnerabilities_exported)
107-
@test length(badcounts) < 1250 # 1000
108-
if length(badcounts) < 800
107+
threshbc = 1000
108+
if length(badcounts) > threshbc
109+
@warn "There are $(length(badcounts)) at-risk specializations of exported methods, which is above the previous threshold"
110+
elseif length(badcounts) < 0.8*threshbc
109111
@info "There are now only $(length(badcounts)) at-risk specializations of exported methods, consider dropping the threshold"
110112
end
111113
meancounts = sum(last.(badcounts))/length(badcounts)
112-
@test meancounts < 33 # 32
113-
if meancounts < 24
114+
threshmc = 19
115+
if meancounts > threshmc
116+
@warn "The mean number of at-risk backedges is now $meancounts, which is above the previous threshold"
117+
elseif meancounts < 0.8*threshmc
114118
@info "The mean number of at-risk backedges is now only $meancounts, consider dropping the threshold"
115119
end
116120
end
@@ -199,17 +203,19 @@ end
199203
# Check that we never infer certain methodinstances,
200204
# It would be great to broaden this beyond Real, but this is a good start.
201205
# If you fail these tests, it means an internal operation forced
202-
# the compiler to infer one of these methods for a problematic combination of types.
206+
# the compiler to generate one of these methods for a poorly-inferred combination of types.
203207
function subtype_real(@nospecialize T)
204208
while isa(T, TypeVar)
205209
T = T.ub
206210
end
207211
return T<:Real
208212
end
209-
for f in (==, isequal, <, <=)
213+
for f in (==, <,) # isequal, <=)
210214
for mi in methodinstances(f)
211215
if any(subtype_real, Base.unwrap_unionall(mi.specTypes).parameters)
212-
@test !is_atrisk_type(mi.specTypes)
216+
if is_atrisk_type(mi.specTypes)
217+
@warn "Specialization $(mi.specTypes) was inferred, this may indicate degraded inference quality"
218+
end
213219
end
214220
end
215221
end

0 commit comments

Comments
 (0)