Closed matthias314 closed 1 month ago
Here is another example:
@stable function g(n)
n = Int(n)::Int
n
end
julia> g(1)
ERROR: TypeInstabilityError: Instability detected in `g` defined at REPL[2]:1 with arguments `(Int64,)`. Inferred to be `Any`, which is not a concrete type.
Oops, sorry, just saw this! (I posted another example on the discourse. Indeed this seems very real!)
I think it has to do with the closure manipulating a variable in the function argument
@stable function g(n)
n = Int(n)::Int
n
end
gets transformed to
function g(n)
function closure()
n = Int(n)::Int
n
end
closure()
end
(Excluding the inference checks). So it's something about how n
is both a function argument and is being modified by the closure...
This is similar to the reason why https://github.com/c42f/FastClosures.jl exists. Maybe a similar trick would work here.
Edit: nope... Doesn't fix it.
Sorry for posting it to Discourse. I've shortened the example, but I haven't tried to prove that the new one is indeed minimal.