-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Type instability when slicing tuples #30386
Comments
Here is the relevant commit by @JeffBezanson c3f3b48 included in PR #27634 |
Did this infer before that commit? The compiler generally doesn't know the values inside a range. For |
It seems so? julia> f(xs) = xs[1:end-1]
f (generic function with 1 method)
julia> @inferred f((1, 2, 3))
ERROR: return type Tuple{Int64,Int64} does not match inferred return type Tuple{Vararg{Int64,N} where N}
Stacktrace:
[1] error(::String) at ./error.jl:33
[2] top-level scope at none:0
julia> Base.getindex(t::Tuple, r::AbstractUnitRange{<:Real}) =
(o = first(r) - 1; ntuple(n -> t[o + n], length(r)))
julia> @inferred f((1, 2, 3))
(1, 2)
julia> VERSION
v"1.1.0-DEV.865" |
const propagation seems to handle it:
|
Well, that's impressive I guess :) However it was not inferrable in 0.6, 0.7, or 1.0 (or any other prior version). I changed this because it was a compiler performance hot spot. So any change to make this inferrable needs to show minimal compile-time cost. |
Try using the |
I think there’s still the case when you might slice by truly variable indices, in which case attempting to infer this will lead to slowdowns even in the <16 case |
True, though before special-casing this in inference it might be worth seeing how bad it is. I'd be a bit surprised if it's common. Jeff, were you just looking at the compilation of julia itself or some other compiler-performance test? Also noticed above:
This already exists and is currently called |
The following change seems to introduce type instability when slicing tuples, which is sometimes not desired. (identified by @tkf )
julia/base/range.jl
Line 197 in c3f3b48
MWE:
See also discussion on discourse.
The text was updated successfully, but these errors were encountered: