Description
This kind of function, where @inbounds
affects the value returned, used to be inferred as consistent in v1.10, but is not in v1.11 and above:
julia> function f()
@boundscheck return true
false
end
f (generic function with 1 method)
julia> Base.infer_effects(f, Tuple{})
(!c,+e,+n,+t,+s,+m,+u,+o,+r)
Given that it's not consistent any more, should that pattern be avoided?
More specifically, things like this are relatively common:
@boundscheck checkbounds(Bool, A, index) || return false
return additional_error_check(...)
Should the @boundscheck
annotation be removed from code like that, while keeping all error checks, to allow constant folding?
The @boundscheck
doc string also needs to be clarified I think.
Examples of the usage of this pattern in Base
:
julia/base/strings/substring.jl
Lines 106 to 110 in 1117df6
Lines 106 to 111 in 1117df6
julia/base/permuteddimsarray.jl
Lines 79 to 83 in 1117df6
Lines 411 to 428 in 1117df6
Lines 237 to 250 in 1117df6
Lines 280 to 292 in 1117df6
julia/base/multidimensional.jl
Lines 369 to 374 in 1117df6
julia/base/multidimensional.jl
Lines 1627 to 1641 in 1117df6
julia/base/multidimensional.jl
Lines 1647 to 1669 in 1117df6
Lines 1027 to 1030 in 1117df6