Skip to content

Compiler: abstract calls: type assert to help stability#57582

Merged
aviatesk merged 3 commits into
JuliaLang:masterfrom
nsajko:Compiler_abstract_calls_type_assert_Int
Mar 12, 2025
Merged

Compiler: abstract calls: type assert to help stability#57582
aviatesk merged 3 commits into
JuliaLang:masterfrom
nsajko:Compiler_abstract_calls_type_assert_Int

Conversation

@nsajko

@nsajko nsajko commented Feb 28, 2025

Copy link
Copy Markdown
Member

It seems la is getting inferred as Integer instead of as Int for some reason.

This reduces the number of invalidations on running this code from 456 to 219:

struct I <: Integer end
Base.Int64(::I) = 7

@nsajko

This comment was marked as outdated.

@JeffBezanson

Copy link
Copy Markdown
Member

Huh, this is strange. It's just a Vector{Any}; we should figure out why it can't infer length.

@aviatesk

Copy link
Copy Markdown
Member

argtypes in abstract_call_builtin is fine, but the one in abstract_call_known is now captured... I think we really need to finish #56687 and make captured variables inferable, or declare the type for the captured one at least.

@aviatesk

Copy link
Copy Markdown
Member

So I'd suggest

diff --git a/Compiler/src/abstractinterpretation.jl b/Compiler/src/abstractinterpretation.jl
index 8035216f1e..2a904e5688 100644
--- a/Compiler/src/abstractinterpretation.jl
+++ b/Compiler/src/abstractinterpretation.jl
@@ -2621,7 +2621,8 @@ end
 function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
         arginfo::ArgInfo, si::StmtInfo, sv::AbsIntState,
         max_methods::Int = get_max_methods(interp, f, sv))
-    (; fargs, argtypes) = arginfo
+    argtypes::Vector{Any} = arginfo.argtypes
+    fargs = arginfo.fargs
     la = length(argtypes)
     𝕃ᵢ = typeinf_lattice(interp)
     if isa(f, Builtin)

for now.

nsajko added 2 commits March 12, 2025 09:40
It seems `la` is getting inferred as `Integer` instead of as `Int` for
some reason.

This reduces the number of invalidations from 2061 to 2046 on running
this code:

```julia
struct I <: Integer end
Base.Int64(::I) = 7
```
@nsajko nsajko force-pushed the Compiler_abstract_calls_type_assert_Int branch from e041bb0 to 6139d7c Compare March 12, 2025 08:41
Comment thread Compiler/src/abstractinterpretation.jl Outdated
@nsajko nsajko requested a review from aviatesk March 12, 2025 11:42
@aviatesk aviatesk merged commit ce747fe into JuliaLang:master Mar 12, 2025
@nsajko nsajko deleted the Compiler_abstract_calls_type_assert_Int branch March 12, 2025 18:18
serenity4 pushed a commit to serenity4/julia that referenced this pull request May 1, 2025
@JamesWrigley JamesWrigley added the backport 1.12 Change should be backported to release-1.12 label Feb 25, 2026
@JamesWrigley

Copy link
Copy Markdown
Member

(I took the liberty of adding the backport label since it helps with invalidations: #60807)

KristofferC pushed a commit that referenced this pull request Mar 3, 2026
@KristofferC KristofferC removed the backport 1.12 Change should be backported to release-1.12 label Mar 25, 2026
mtfishman added a commit to ITensor/BlockSparseArrays.jl that referenced this pull request Apr 16, 2026
Julia v1.12.6 fixed type inference for abstract array dispatch
(JuliaLang/julia#57582), which makes JLArray-backed BlockSparseMatrix
operations (eig, svd, qr, iszero on views) work correctly. Use
`broken = gpu_broken` with a VERSION check so tests remain broken
on older Julia versions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants