From 040b236000721200cc001c950bfdf620af4bd65e Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Fri, 13 Aug 2021 17:24:07 -0500 Subject: [PATCH] Narrow `convert` methods to reduce invalidations 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. --- src/conversion.jl | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/conversion.jl b/src/conversion.jl index 5d513b4c..20b54702 100644 --- a/src/conversion.jl +++ b/src/conversion.jl @@ -60,9 +60,8 @@ function Base.convert(::Type{T}, p::AbstractPolynomial) where T <: AbstractTermL end MA.scaling(p::AbstractPolynomialLike{T}) where {T} = convert(T, p) -Base.convert(::Type{Any}, p::APL) = p # Conversion polynomial -> scalar -function Base.convert(S::Type{<:Union{Number, T}}, p::APL{T}) where T +function Base.convert(S::Type{<:Union{Number, T}}, p::APL{T}) where T<:Number s = zero(S) for t in terms(p) if !isconstant(t)