1
1
# This file is a part of Julia. License is MIT: https://julialang.org/license
2
2
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.
8
8
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`.
10
11
11
12
using Test
12
13
84
85
@test isempty (remove_unlikely_methodinstances (atrisk_triggers (m, first .(mivulnerabilities_exported))))
85
86
86
87
# 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))))
90
90
end
91
91
end
92
92
@@ -104,13 +104,17 @@ end
104
104
# Test overall number of atrisk MethodInstances and their average number of backedges
105
105
badexp = Set (remove_unlikely_methodinstances (first .(mivulnerabilities_exported)))
106
106
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
109
111
@info " There are now only $(length (badcounts)) at-risk specializations of exported methods, consider dropping the threshold"
110
112
end
111
113
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
114
118
@info " The mean number of at-risk backedges is now only $meancounts , consider dropping the threshold"
115
119
end
116
120
end
@@ -199,17 +203,19 @@ end
199
203
# Check that we never infer certain methodinstances,
200
204
# It would be great to broaden this beyond Real, but this is a good start.
201
205
# 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.
203
207
function subtype_real (@nospecialize T)
204
208
while isa (T, TypeVar)
205
209
T = T. ub
206
210
end
207
211
return T<: Real
208
212
end
209
- for f in (== , isequal, < , <= )
213
+ for f in (== , < ,) # isequal , <=)
210
214
for mi in methodinstances (f)
211
215
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
213
219
end
214
220
end
215
221
end
0 commit comments