force specialization of dims argument type where it may be Colon
#1318
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discussed in the Performance Tips in the Manual, Julia avoids specializing calls on the type of
Function
arguments by default.The function
:
,(:) isa Function
, is often used not as a callable, but as the special value for specifying the "full range" or "all dimensions". However in such cases we often forget to force specialization on the type of:
. This change fixes that.See PR JuliaLang/julia#59474, which applies the same kind of change in Julia itself.
NB: I don't have an example where this change helps for StaticArrays, however the eliminated invalidation in the linked JuliaLang/julia PR is proof that it does help in some cases. Finding such examples is difficult because the compiler is often able to achieve good results because of constant propagation. However constprop is often fragile, so it is better to avoid relying on it. For example, constprop through recursion is not even attempted by the Julia compiler.
I believe this change should not cause any real-world compile time regression, as
:
is the only function that is valid as a dims argument.