Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 939
Lyndon White Avatar asked May 12 '16 08:05

Lyndon White


1 Answers

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.

like image 79
StefanKarpinski Avatar answered Sep 27 '22 22:09

StefanKarpinski