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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With