Frames Catherine White
Frames Catherine White

Reputation: 28212

What is `ANY`, and how does it differ from `Any` ?

In recent 0.5 nightlies of Julia I have started noticing type parameters named ANY, constrained to be subtypes of Any. Which is of-course always true, as 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 is going on? Is this some kind of trick to encourage the compiler to generate specialized functions as it JITs?

Upvotes: 7

Views: 90

Answers (1)

StefanKarpinski
StefanKarpinski

Reputation: 33259

ANY is a hack to hint to the compiler that it should not specialize on an argument. Otherwise the compiler will consider specializing functions on the specific types of all arguments they gets called with, which in some cases could end up being a lot of unnecessary code generation. It's kind of a dirty hack, and a more general mechanism for this would be better, but it gets the job done.

Upvotes: 8

Related Questions