-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Eliminate some invalidations from loading FixedPointNumbers [tweaked #35733] #35803
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
Conversation
Why is Statistics testing
? PR to statistics: https://github.com/JuliaLang/Statistics.jl/pull/36 |
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.
I suspect that for this particular PR we will be best waiting until Jeff or Jameson weighs in...but FWIW, here are some thoughts.
@@ -3,6 +3,8 @@ | |||
# promote Bool to any other numeric type | |||
promote_rule(::Type{Bool}, ::Type{T}) where {T<:Number} = T | |||
|
|||
convert(::Type{Bool}, x::Bool) = x # prevent invalidation |
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.
This one might not be necessary either, after the Union{}
stuff is fixed. It's just a really common case that would otherwise fall back to convert(::Type{T}, x::T)
.
@@ -49,6 +49,7 @@ Char | |||
(::Type{AbstractChar})(x::Number) = Char(x) | |||
(::Type{T})(x::AbstractChar) where {T<:Union{Number,AbstractChar}} = T(codepoint(x)) | |||
(::Type{T})(x::T) where {T<:AbstractChar} = x | |||
AbstractChar(x::AbstractChar) = 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.
Possibly ditto.
@@ -179,6 +180,7 @@ convert(::Type{AbstractChar}, x::Number) = Char(x) # default to Char | |||
convert(::Type{T}, x::Number) where {T<:AbstractChar} = T(x) | |||
convert(::Type{T}, x::AbstractChar) where {T<:Number} = T(x) | |||
convert(::Type{T}, c::AbstractChar) where {T<:AbstractChar} = T(c) | |||
convert(::Type{AbstractChar}, c::AbstractChar) = c |
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.
...possibly same for everything up to the reduce_empty
stuff.
@@ -306,25 +306,29 @@ with reduction `op` over an empty array with element type of `T`. | |||
|
|||
If not defined, this will throw an `ArgumentError`. | |||
""" | |||
reduce_empty(op, T) = _empty_reduce_error() | |||
reduce_empty(::typeof(+), T) = zero(T) | |||
reduce_empty(op, ::Type{T}) where T = _empty_reduce_error() |
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.
AFAICT this is not a signature-based invalidation, this is one that came from jl_method_table_disable
which seems to have Base.delete_method
as its only caller. I don't have a very good handle on what is going on here, sorry.
One interesting thing is that the inferred return type is Union{}
(even before loading FixedPointNumbers):
julia> code_typed(Base.reduce_empty, (Base.BottomRF{typeof(max)}, Type{VersionNumber}); optimize=false)
1-element Array{Any,1}:
CodeInfo(
1 ─ %1 = Base.getproperty(op, :rf)::Core.Compiler.Const(max, false)
│ Base.reduce_empty(%1, T)::Union{}
└── Core.Compiler.Const(:(return %2), false)::Union{}
) => Union{}
I thought this PR would be more trivial than it was. Now when it starts generating discussion I think it is best to just close it to keep the focus in #35733. |
#35733 but with the controversial
::Union{}
methods removed. Still provides a significant speedup in the test case posted in that PR.No impact on sysimage size.