-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend at-specialize to force specialization of arguments #33978
Comments
Since in |
I'm not the right person to answer, but this kind of prove the point that the exact rules are not obvious to everyone (talking of me!) |
It is worth mentioning that #32817 added documentation on when a |
But I do think the intent of |
Nice, I was wondering whether it was documented somewhere, but got too lazy to check. Otherwise I agree with Tim, the current way to force specialization is too easy to miss out, and is brittle. Overrriding compiler heuristics might be hacky, but we all love to do it :D And If you think |
I agree we need a way to do this. In the last year I've noticed people start to use the static parameter trick more often, and each time I have to ask the question "Is Furthermore, we're then forced to leave a comment that this is indeed to force specialization, lest someone clean up the code later. To make matters worse, the specialization heuristics are somewhat subtle (and presumably subject to change) so I've seen people start to throw this in at the first sign of trouble in the hope that it will help. |
So looking at the code which processes function foo(@specialize(x))
body
end See Lines 554 to 558 in 52c55d7
So in principle we could steal function foo(x)
@specialize
body
end which just resets the |
A trick currently used in
Base
(and probably elsewhere) to force specialization on functions is to artificially declare a type parameter, e.g.foo(f::F) where F = f(1)
. I would bet that the majority of Julia users don't know about this and would look at this piece of code without any idea about the role ofF
, and would even fix what appears as a naive use of type parameters by simplifying it tofoo(f) = f(1)
.What about adding some explicit means to this end, for example reusing
@specialize
:foo(@specialize(f)) = f(1)
?xref: #33917 (comment)
The text was updated successfully, but these errors were encountered: