Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged

Conversation

nsajko
Copy link
Contributor

@nsajko nsajko commented Feb 28, 2025

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
Member

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

@aviatesk
Copy link
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
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
@nsajko nsajko requested a review from aviatesk March 12, 2025 11:42
@aviatesk aviatesk merged commit ce747fe into JuliaLang:master Mar 12, 2025
6 of 9 checks passed
@nsajko nsajko deleted the Compiler_abstract_calls_type_assert_Int branch March 12, 2025 18:18
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.

3 participants