julia
julia copied to clipboard
suboptimal return type inference for `Base.setindex`
julia> Core.Compiler.return_type(Base.setindex, Tuple{Tuple,Nothing,Int}) <: Tuple
false
julia> versioninfo()
Julia Version 1.12.0-DEV.495
Commit 3c966a5107a (2024-05-09 11:53 UTC)
Build Info:
Official https://julialang.org/ release
Platform Info:
OS: Linux (x86_64-linux-gnu)
CPU: 8 × AMD Ryzen 3 5300U with Radeon Graphics
WORD_SIZE: 64
LLVM: libLLVM-17.0.6 (ORCJIT, znver2)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
FWIW the type inference for Base.setindex was better on v1.7.3.
A quick fix, for Base.setindex at least, is adding a ::Tuple type assertion for the Base._setindex return value.
However, I'm not sure why does the inference fail, actually? We do have:
Core.Compiler.return_type(ntuple, Tuple{Any,Val}) <: Tuple
Cthulhu.descend shows that, in Base._setindex, the return value gets inferred as Any even though the Val{N}() gets inferred as Val. Weird.