-
-
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
fix invalidations due to convert(Nothing, ::Any) #39434
Conversation
base/some.jl
Outdated
convert(::Type{Nothing}, x) = throw(MethodError(convert, (Nothing, x))) | ||
convert(::Type{Nothing}, x::T) where {T>:Nothing} = throw(MethodError(convert, (Nothing, x))) |
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.
These two are equivalent, methods(convert)
should only list one of them, in particular the latter as it has replaced the former. If you find that you need both to get the desired effect, something weird is going on.
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.
Ah yes, you are correct:
julia> methods(convert, Tuple{Type{Nothing}, Any})
# 2 methods for generic function "convert":
[1] convert(::Type{Nothing}, ::Nothing) in Base at some.jl:39
[2] convert(::Type{Nothing}, x::T) where T>:Nothing in Base at some.jl:38
I think I was just a bit confused because I previously assumed the definition in line 35 would just be equivalent to defining convert(::Type{Nothing}, ::Nothing)
, but that caused problems.
Before this PR: ```julia julia> using SnoopCompileCore julia> struct A end julia> @Snoopr (::Type{<:A})(::AbstractVector) = 1 14-element Vector{Any}: MethodInstance for convert(::Type{Union{}}, ::AbstractArray) 1 MethodInstance for convert(::Type{Nothing}, ::Any) 2 MethodInstance for Union{}(::AbstractArray) "jl_method_table_insert" MethodInstance for Core.Compiler.convert(::Type{V} where V<:Core.Compiler.BitArray{1}, ::Vector{var"#s122"} where var"#s122"<:Union{Float32, Float64}) 1 MethodInstance for Core.Compiler.convert(::Type{T}, ::Vector{var"#s122"} where var"#s122"<:Union{Float32, Float64}) where T<:(Vector{T} where T) 1 MethodInstance for Union{}(::Vector{var"#s122"} where var"#s122"<:Union{Float32, Float64}) "jl_method_table_insert" (::Type{var"#s3"} where var"#s3"<:A)(::AbstractVector{T} where T) in Main at REPL[3]:1 "jl_method_table_insert" ``` After: ```julia julia> using SnoopCompileCore julia> struct A end julia> @Snoopr (::Type{<:A})(::AbstractVector) = 1 Any[] ``` This was causing invalidations in StaticArrays.
19809c9
to
34b7c78
Compare
@timholy Since this is my first foray into invalidation busting, would you mind taking a look whether this looks sensible to you? |
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.
Perfect.
This PR should fix this ambiguity:
julia> convert(Nothing, 3)
ERROR: MethodError: convert(::Type{Union{}}, ::Int64) is ambiguous. Candidates:
convert(::Type{T}, x::Number) where T<:AbstractChar in Base at char.jl:179
convert(::Type{T}, x::Number) where T<:Number in Base at number.jl:7
convert(::Type{Union{}}, x) in Base at essentials.jl:203
convert(::Type{T}, arg) where T<:VecElement in Base at baseext.jl:8
Possible fix, define
convert(::Type{Union{}}, ::Number)
Stacktrace:
[1] convert(#unused#::Type{Nothing}, x::Int64)
@ Base ./some.jl:36
[2] top-level scope
@ REPL[4]:1
But I'm puzzled about why this isn't picked up by detect_ambiguities(Base)
.
Ambiguities are permitted (in the test) for Union{} |
Ah, cool! Didn't even realize that. |
@vtjnash I am sure this has been discussed at some point, but how much havoc would it cause to have a non-inclusive |
xref #38455 (comment) |
Before this PR:
After:
This was causing invalidations in StaticArrays.