-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Description
Because of this current julia bug #23618 it is often needed to explicitly demand for argument specialization for types like myfunc(thisshouldspecializeontypes::Type{T}) where T. The documentation states this clearly.
However this approach makes the argument only dispatch on Types. It would be very helpful to allow for marking an argument to also specialize on types, while still staying a generic argument.
There is currently no way to do so, however the current workaround is code duplication (or the use of a macro respectively). You need to create one function clause for the ::Type{T} case and one for the generic argument. Of course, all code needs to be duplicated, which relies on the argument specialization for types.
As an alternative to this code duplication, I want to suggest adding a macro similar to @nospecialize, named e.g. @specializetype which can be simply prepended to the respective argument and makes it work like a normal argument, but with specialization on types.
On discourse, some have responded that there wouldn't be a need for a generic argument which specializes on Types. I strongly disagree. Because of the above bug, any closure which may refer to a Type needs explicit specialization as of now. The use of closures for me is generic coding and should not require a special case for types.
julia version 1.7.1