Skip to content

Commit 7ccc7b8

Browse files
authored
Narrow convert methods to reduce invalidations (#172)
This package caused >1000 invalidations for DifferentialEquations. The main problem is a pair of `convert` methods: one is redundant with a method in Base (and needlessly invalidates some code), and another intersected with signatures like `convert(Base.SHA1, ::Any)` and other crazy types. The reason is because the `T` in `APL{T}` is completely unconstrained, and consequently it's possible in principle for it to be a `REPLTerminal` or a `Module` or whatever. It didn't seem as if that were the real intent of the convert method.
1 parent 49eb7da commit 7ccc7b8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/conversion.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ function Base.convert(::Type{T}, p::AbstractPolynomial) where T <: AbstractTermL
6060
end
6161

6262
MA.scaling(p::AbstractPolynomialLike{T}) where {T} = convert(T, p)
63-
Base.convert(::Type{Any}, p::APL) = p
6463
# Conversion polynomial -> scalar
65-
function Base.convert(S::Type{<:Union{Number, T}}, p::APL{T}) where T
64+
function scalarize(::Type{S}, p::APL) where S
6665
s = zero(S)
6766
for t in terms(p)
6867
if !isconstant(t)
@@ -73,5 +72,6 @@ function Base.convert(S::Type{<:Union{Number, T}}, p::APL{T}) where T
7372
end
7473
s
7574
end
75+
Base.convert(::Type{T}, p::APL) where T<:Number = scalarize(T, p)
7676

7777
Base.convert(::Type{PT}, p::PT) where {PT<:APL} = p

0 commit comments

Comments
 (0)