generic size: avoid method static parameters and abstract type assert#59465
Merged
vtjnash merged 4 commits intoJuliaLang:masterfrom Sep 26, 2025
Merged
generic size: avoid method static parameters and abstract type assert#59465vtjnash merged 4 commits intoJuliaLang:masterfrom
size: avoid method static parameters and abstract type assert#59465vtjnash merged 4 commits intoJuliaLang:masterfrom
Conversation
Member
Author
|
Indeed, this PR is a prerequisite for PR #59442. Otherwise three of these effect inference tests fail: julia/Compiler/test/effects.jl Lines 792 to 797 in cdd4ac5 |
701c909 to
94abb7f
Compare
nsajko
added a commit
to nsajko/julia
that referenced
this pull request
Sep 3, 2025
The generic method `size(::AbstractArray, ::Any)` currently has: * method static parameters * an abstract type assert (`::Integer`) in the method body PR JuliaLang#59442 aims to make this generic method be used for `Array` and `Memory`, by deleting the more specific methods. It is my understanding that method static parameters and abstract type asserts can cause performance issues, when they're not optimized out, which happens when the argument types are not concretely inferred. So I'm putting up this PR, which eliminates the method static parameters and the `typeassert`, to prevent any possible regressions from PR JuliaLang#59442. Another thing that is necessary for preserving good abstract inference is to convert the index to `Int` before using it. This is correct it there can't be more than `typemax(Int)` dimensions anyway. (cherry picked from PR JuliaLang#59465)
nsajko
added a commit
to nsajko/julia
that referenced
this pull request
Sep 3, 2025
The generic method `size(::AbstractArray, ::Any)` currently has: * method static parameters * an abstract type assert (`::Integer`) in the method body PR JuliaLang#59442 aims to make this generic method be used for `Array` and `Memory`, by deleting the more specific methods. It is my understanding that method static parameters and abstract type asserts can cause performance issues, when they're not optimized out, which happens when the argument types are not concretely inferred. So I'm putting up this PR, which eliminates the method static parameters and the `typeassert`, to prevent any possible regressions from PR JuliaLang#59442. Another thing that is necessary for preserving good abstract inference is to convert the index to `Int` before using it. This is correct it there can't be more than `typemax(Int)` dimensions anyway. (cherry picked from PR JuliaLang#59465)
nsajko
added a commit
to nsajko/julia
that referenced
this pull request
Sep 3, 2025
The generic method `size(::AbstractArray, ::Any)` currently has: * method static parameters * an abstract type assert (`::Integer`) in the method body PR JuliaLang#59442 aims to make this generic method be used for `Array` and `Memory`, by deleting the more specific methods. It is my understanding that method static parameters and abstract type asserts can cause performance issues, when they're not optimized out, which happens when the argument types are not concretely inferred. So I'm putting up this PR, which eliminates the method static parameters and the `typeassert`, to prevent any possible regressions from PR JuliaLang#59442. Another thing that is necessary for preserving good abstract inference is to convert the index to `Int` before using it. This is correct it there can't be more than `typemax(Int)` dimensions anyway. (cherry picked from PR JuliaLang#59465)
8302694 to
4f3b8c2
Compare
nsajko
added a commit
to nsajko/julia
that referenced
this pull request
Sep 3, 2025
The generic method `size(::AbstractArray, ::Any)` currently has: * method static parameters * an abstract type assert (`::Integer`) in the method body PR JuliaLang#59442 aims to make this generic method be used for `Array` and `Memory`, by deleting the more specific methods. It is my understanding that method static parameters and abstract type asserts can cause performance issues, when they're not optimized out, which happens when the argument types are not concretely inferred. So I'm putting up this PR, which eliminates the method static parameters and the `typeassert`, to prevent any possible regressions from PR JuliaLang#59442. Another thing that is necessary for preserving good abstract inference is to convert the index to `Int` before using it. This is correct it there can't be more than `typemax(Int)` dimensions anyway. (cherry picked from PR JuliaLang#59465)
nsajko
added a commit
to nsajko/julia
that referenced
this pull request
Sep 3, 2025
The generic method `size(::AbstractArray, ::Any)` currently has: * method static parameters * an abstract type assert (`::Integer`) in the method body PR JuliaLang#59442 aims to make this generic method be used for `Array` and `Memory`, by deleting the more specific methods. It is my understanding that method static parameters and abstract type asserts can cause performance issues, when they're not optimized out, which happens when the argument types are not concretely inferred. So I'm putting up this PR, which eliminates the method static parameters and the `typeassert`, to prevent any possible regressions from PR JuliaLang#59442. Another thing that is necessary for preserving good abstract inference is to convert the index to `Int` before using it. This is correct it there can't be more than `typemax(Int)` dimensions anyway. (cherry picked from PR JuliaLang#59465)
Member
Author
|
bump |
Member
Author
|
ping |
vtjnash
requested changes
Sep 9, 2025
Member
vtjnash
left a comment
There was a problem hiding this comment.
I don't like this. It changes clear code into a mess. Changing to simplified code like this would be okay though:
function size(t::AbstractArray, dim)
d = Int(dim)::Int
s = size(t)
d <= length(s) ? s[d] : 1
end
a4f8310 to
4ae27ee
Compare
JeffBezanson
reviewed
Sep 9, 2025
Member
Author
|
bump? or merge PR #59512? |
oscardssmith
approved these changes
Sep 23, 2025
The generic method `size(::AbstractArray, ::Any)` currently has: * method static parameters * an abstract type assert (`::Integer`) in the method body PR JuliaLang#59442 aims to make this generic method be used for `Array` and `Memory`, by deleting the more specific methods. It is my understanding that method static parameters and abstract type asserts can cause performance issues, when they're not optimized out, which happens when the argument types are not concretely inferred. So I'm putting up this PR, which eliminates the method static parameters and the `typeassert`, to prevent any possible regressions from PR JuliaLang#59442. Another thing that is necessary for preserving good abstract inference is to convert the index to `Int` before using it. This is correct it there can't be more than `typemax(Int)` dimensions anyway.
Now this PR changes behavior: non-`Integer` values are allowed for the second argument as long as they are convertible to `Int`.
6655c96 to
91a1978
Compare
Member
Author
|
@vtjnash your suggestion was implemented, however your negative review is still around. Also, there's now an approval. Can you take a look again? |
vtjnash
approved these changes
Sep 26, 2025
oscardssmith
pushed a commit
that referenced
this pull request
Sep 27, 2025
Changes:
* Eliminate some nongeneric `length` methods:
* `GenericMemory`
* `Slice`
* `IdentityUnitRange`
* `CartesianIndices`
* `LogicalIndex`
* `CodeUnits`
* `UnsafeView` (from the `Random` stdlib)
* Eliminate some nongeneric two-argument `size` methods:
* `GenericMemory`
* `Array`
* `BitVector`
Depends on PR #59465 to prevent abstract inference regressions.
xal-0
pushed a commit
to xal-0/julia
that referenced
this pull request
Sep 30, 2025
…rt (JuliaLang#59465) The generic method `size(::AbstractArray, ::Any)` currently has: * method static parameters * an abstract type assert (`::Integer`) in the method body PR JuliaLang#59442 aims to make this generic method be used for `Array` and `Memory`, by deleting the more specific methods. It is my understanding that method static parameters and abstract type asserts can cause performance issues, when they're not optimized out, which happens when the argument types are not concretely inferred. So I'm putting up this PR, which eliminates the method static parameters and the `typeassert`, to prevent any possible regressions from PR JuliaLang#59442. Another thing that is necessary for preserving good abstract inference is to convert the index argument to `Int` before using it. This is correct as there can't be more than `typemax(Int)` dimensions anyway (the `N` type parameter to `AbstractArray` is an `Int` value).
xal-0
pushed a commit
to xal-0/julia
that referenced
this pull request
Sep 30, 2025
…9442) Changes: * Eliminate some nongeneric `length` methods: * `GenericMemory` * `Slice` * `IdentityUnitRange` * `CartesianIndices` * `LogicalIndex` * `CodeUnits` * `UnsafeView` (from the `Random` stdlib) * Eliminate some nongeneric two-argument `size` methods: * `GenericMemory` * `Array` * `BitVector` Depends on PR JuliaLang#59465 to prevent abstract inference regressions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The generic method
size(::AbstractArray, ::Any)currently has:method static parameters
an abstract type assert (
::Integer) in the method bodyPR #59442 aims to make this generic method be used for
ArrayandMemory, by deleting the more specific methods.It is my understanding that method static parameters and abstract type asserts can cause performance issues, when they're not optimized out, which happens when the argument types are not concretely inferred.
So I'm putting up this PR, which eliminates the method static parameters and the
typeassert, to prevent any possible regressions from PR #59442.Another thing that is necessary for preserving good abstract inference is to convert the index argument to
Intbefore using it. This is correct as there can't be more thantypemax(Int)dimensions anyway (theNtype parameter toAbstractArrayis anIntvalue).