Skip to content

Conversation

@JamesWrigley
Copy link
Member

Currently it's inferred as Any because of the subtraction operation.

Should fix the second-to-last invalidation here from PythonCall.jl (CC @cjdoris):

 inserting &(x::Number, y::PythonCall.Py) @ PythonCall.Core ~/git/PythonCall.jl/src/Core/Py.jl:430 invalidated:                                                                                                                                
   mt_backedges:  1: signature Tuple{typeof(&), Bool, Any} triggered MethodInstance for Base.var"#string#403"(::Int64, ::Int64, ::typeof(string), ::Unsigned) (0 children)                                                                     
                  2: signature Tuple{typeof(&), Bool, Any} triggered MethodInstance for Base.var"#string#403"(::Int64, ::Int64, ::typeof(string), ::Signed) (0 children)                                                                       
                  3: signature Tuple{typeof(&), Bool, Any} triggered MethodInstance for Base.var"#string#403"(::Int64, ::Int64, ::typeof(string), ::Integer) (0 children)                                                                      
                  4: signature Tuple{typeof(&), Bool, Any} triggered MethodInstance for div(::Unsigned, ::Int64, ::RoundingMode{:Up}) (1 children)                                                                                             
                  5: signature Tuple{typeof(&), Bool, Any} triggered MethodInstance for isempty(::StepRange{Tuple{LineNumberNode, Expr}}) (2 children)                                                                                         
                  6: signature Tuple{typeof(&), Int64, Any} triggered MethodInstance for Base.hashindex(::Any, ::Any) (4 children)                                                                                                             
                  7: signature Tuple{typeof(&), Bool, Any} triggered MethodInstance for Base.Broadcast._broadcast_getindex_evalf(::typeof(&), ::Bool, ::Any) (5 children)                                                                      
                  8: signature Tuple{typeof(&), Bool, Any} triggered MethodInstance for isempty(::StepRange{String}) (10 children)                                                                                                             
                  9: signature Tuple{typeof(&), Int64, Any} triggered MethodInstance for Base.hashindex(::WeakRef, ::Any) (18 children)                                                                                                        
                 10: signature Tuple{typeof(&), Bool, Any} triggered MethodInstance for Base.checkbounds_indices(::Type{Bool}, ::Tuple, ::Tuple{CartesianIndex{2}}) (53 children)                                                              
                 11: signature Tuple{typeof(&), Bool, Any} triggered MethodInstance for isinf(::AbstractFloat) (202 children)                                                                                                                  
                 12: signature Tuple{typeof(&), Bool, Any} triggered MethodInstance for div(::Unsigned, ::Int64, ::RoundingMode{:Down}) (588 children)                                                                                         

Which according to Cthulhu is:

isinf(x::Real) @ Base ~/.julia/juliaup/julia-1.12.1+0.x64.linux.gnu/share/julia/base/float.jl:723                                                                                                                                              
723 isinf(x::AbstractFloat::Real)::Any = !(isnan(x::AbstractFloat)::Bool)::Bool & !(isfinite(x::AbstractFloat)::Any)::Any

Which leads to:

isfinite(x::AbstractFloat) @ Base ~/.julia/juliaup/julia-1.12.1+0.x64.linux.gnu/share/julia/base/float.jl:712
712 isfinite(x::AbstractFloat::AbstractFloat)::Any = !isnan((x::AbstractFloat - x::AbstractFloat)::Any)::Any

Currently it's inferred as `Any` because of the subtraction operation.
@adienes
Copy link
Member

adienes commented Oct 18, 2025

I don't understand; isnan is already ::Bool and ! is Bool -> Bool so why can't this infer?

@JamesWrigley
Copy link
Member Author

I believe this is the problem (from descend(isfinite, (AbstractFloat,))):

(x::AbstractFloat - x::AbstractFloat)::Any

The subtraction is inferred as Any so isnan(::Any) is getting called which also infers to Any.

Co-authored-by: Simeon David Schaub <[email protected]>
@KristofferC KristofferC added the backport 1.12 Change should be backported to release-1.12 label Oct 20, 2025
@KristofferC
Copy link
Member

KristofferC commented Oct 20, 2025

This feels completely unscalable but as long as we don't have a better solution, I guess we might just keep putting band aid on it like this.

@KristofferC KristofferC merged commit 78ba3be into JuliaLang:master Oct 20, 2025
8 checks passed
@JamesWrigley JamesWrigley deleted the isfinite-invalidations branch October 20, 2025 11:45
KristofferC pushed a commit that referenced this pull request Oct 21, 2025
KristofferC pushed a commit that referenced this pull request Oct 21, 2025
@KristofferC KristofferC mentioned this pull request Oct 21, 2025
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.12 Change should be backported to release-1.12

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants