-
-
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
Constant Propagation on Base.getindex
#35531
Comments
😱 |
Can you give a bit more detail about the types involved and how the constants arise? For instance, in your example the |
Ah, sorry about that line ... In StaticKernels the user can create a kernel by specifying a kernel function and apply it similar to a regular function using e.g. # 1d finite difference kernel
k = Kernel{(0:1,)}(w -> w[1] - w[0])
map(k, rand(10), StaticKernels.ExtensionConstant(0)) So the kernel function is called with a statically sized moving window @propagate_inbounds @inline function Base.getindex(w::Window{<:Any,N}, wi::CartesianIndex{N}) where N
# central piece to get efficient boundary handling.
# we rely on the compiler to constant propagate this check away
checkbounds(Bool, w, wi) || return getindex_extension(w, wi, extension(w.kernel))
return getindex_parent(w, position(w) + wi)
end If getindex does not constant propagate, then |
This seems to have been resolved by #43852 which refined the heuristic for constant propagation of |
Due to high compile times for very large static vectors constant propagation was changed in #32105 to bail out on
Base.getindex
in cases where the object is any non-singletonAbstractArray
.This can prevent one from harnessing constant propagation to provide type-stability in cases where the index is constant:
A more concrete usecase is the package StaticKernels where the user is defining a kernel function with constant relative indexing on a moving
Window
array that efficiently handles array boundaries using the type system.In order not to sacrifice the user interface the current workaround is to not inherit from
AbstractArray
even though it would make sense.Can we provide a method for array types to opt-in to constant propagation for getindex or refine the current heuristic?
The text was updated successfully, but these errors were encountered: