What is `ANY`, and how is it different from` Any`?

In the last 0.5 nights of Julia, I began to notice type parameters named ANY , with restrictions on ANY subtypes. Of course, it is always true, since all types are subtypes of ANY

For example:

 serialize(s::SerializationState, x::ANY<:Any) at serialize.jl:468 show(io::IO, x::ANY<:Any) at show.jl:85 methods(f::ANY<:Any) at reflection.jl:258 methods(f::ANY<:Any, t::ANY<:Any) at reflection.jl:247 

So what's going on? Is this some kind of trick to get the compiler to generate specialized functions because it has JITs?

+7
generics types jit julia-lang
source share
1 answer

ANY is a hack to hint to the compiler that he should not specialize in an argument. Otherwise, the compiler will consider specialized functions for specific types of all arguments with which they are called, which in some cases can lead to a lot of unnecessary code generation. This is a kind of dirty hack, and a more general mechanism for this would be better, but it does its job.

+8
source share

All Articles