Skip to content

Conversation

nsajko
Copy link
Member

@nsajko nsajko commented Aug 27, 2025

Fix a regression where abstract return type inference of sizeof(::Array) used to produce Any after Julia v1.11.

Fix a regression where abstract return type inference of
`sizeof(::Array)` used to produce `Any` after Julia v1.11.
@nsajko nsajko added the arrays [a, r, r, a, y, s] label Aug 27, 2025
@JeffBezanson
Copy link
Member

I think instead we can delete some of the redundant Array length methods.

@JeffBezanson
Copy link
Member

This should fix all these issues:

--- a/base/essentials.jl
+++ b/base/essentials.jl
@@ -7,9 +7,7 @@ const Callable = Union{Function,Type}
 const Bottom = Union{}
 
 # Define minimal array interface here to help code used in macros:
-length(a::Array{T, 0}) where {T} = 1
 length(a::Array{T, 1}) where {T} = getfield(a, :size)[1]
-length(a::Array{T, 2}) where {T} = (sz = getfield(a, :size); sz[1] * sz[2])

@nsajko
Copy link
Member Author

nsajko commented Aug 27, 2025

instead we can delete some of the redundant Array length methods

I know (already opened relevant PRs before), but this seemed like on OK quick fix. Relevant PRs:

@nsajko
Copy link
Member Author

nsajko commented Aug 27, 2025

In particular, an issue with the proposed diff above @JeffBezanson, as pointed out in a comment by @KristofferC in one of the linked PRs of mine, is that it would cause new invalidations. That is why now I'm trying to combine deleting unnecessary length methods with lowering max_methods for length (and other functions).

@nsajko
Copy link
Member Author

nsajko commented Aug 27, 2025

However it still might make sense to do the simple ::Int typeasserts where backportable.

@JeffBezanson
Copy link
Member

Why does it cause invalidations? I would think adding new methods could not invalidate length(::Array). Do we have examples of this?

If it is indeed a problem, maybe keeping the method for Vector will help.

@nsajko
Copy link
Member Author

nsajko commented Aug 28, 2025

You're right, PR #57627 does not seem to cause any invalidation. I'm moving the tests from these few most recent PRs to that PR.

@nsajko nsajko closed this Aug 28, 2025
@nsajko nsajko deleted the abstract_return_type_inference_sizeof-Array branch August 28, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arrays [a, r, r, a, y, s]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants