-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
relax dispatch for the IteratorSize
method for Generator
#58110
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
relax dispatch for the IteratorSize
method for Generator
#58110
Conversation
@@ -98,7 +98,7 @@ IteratorSize(::Type{Any}) = SizeUnknown() | |||
|
|||
IteratorSize(::Type{<:Tuple}) = HasLength() | |||
IteratorSize(::Type{<:AbstractArray{<:Any,N}}) where {N} = HasShape{N}() | |||
IteratorSize(::Type{Generator{I,F}}) where {I,F} = IteratorSize(I) | |||
IteratorSize(::Type{<:Generator{I}}) where {I} = (@isdefined I) ? IteratorSize(I) : SizeUnknown() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apologies for the dumb question, but in which scenario would @isdefined I
return false
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The bottom type does it:
julia> struct S{P} end
julia> f(::Type{<:S}) = "fallback"
f (generic function with 1 method)
julia> f(::Type{<:S{P}}) where {P} = (@isdefined P) ? "is defined" : "is not defined"
f (generic function with 2 methods)
julia> f(Union{})
"is not defined"
@isdefined
is often used like that in eltype
method definitions.
f1dfaaf
to
6d55b1e
Compare
Rebased to get rid of the merge commit. Not sure, but I think the merge commit could have prevented automatic backport. |
Most PRs are squash-merged, there's no merge commit anyway. |
I think the autobackport functionality maybe works directly with the PR, not with the squashed commit, though? Again, not sure. |
Fixes #58109