<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I'd like to let people know that I'm introducing an @_specialize(...)</div><div class="">function attribute. See <a href="https://github.com/apple/swift/pull/1725" class="">https://github.com/apple/swift/pull/1725</a>.</div><div class="">Feedback is welcome. Just keep in mind that for now this is only an</div><div class="">internal attribute. It is not yet a language change and has no impact</div><div class="">on API. The intention of this work is to provide an underlying capability</div><div class="">that we can build on in several ways (see below).</div><div class=""><br class=""></div><div class=""><snip Generics.rst></div><div class="">An internal @_specialize function attribute allows devlopers to force</div><div class="">full specialization by listing concrete type names corresonding to the</div><div class="">function's generic signature. A function's generic signature is a</div><div class="">concatenation of its generic context and the function's own generic</div><div class="">type parameters.::</div><div class=""><br class=""></div><div class=""> struct S<T> {</div><div class=""> var x: T</div><div class=""> @_specialize(Int, Float)</div><div class=""> mutating func exchangeSecond<U>(u: U, _ t: T) -> (U, T) {</div><div class=""> x = t</div><div class=""> return (u, x)</div><div class=""> }</div><div class=""> }</div><div class=""><br class=""></div><div class=""> // Substitutes: <T, U> with <Int, Float> producing:</div><div class=""> // S<Int>::exchangeSecond<Float>(u: Float, t: Int) -> (Float, Int)</div><div class=""><br class=""></div><div class="">@_specialize currently acts as a hint to the optimizer, which</div><div class="">generates type checks and code to dispatch to the specialized routine</div><div class="">without affecting the signature of the generic function. The</div><div class="">intention is to support efforts at evaluating the performance of</div><div class="">specialized code. The performance impact is not guaranteed and is</div><div class="">likely to change with the optimizer. This attribute should only be</div><div class="">used in conjunction with rigorous performance analysis. Eventually,</div><div class="">a similar attribute could be defined in the language, allowing it to be</div><div class="">exposed as part of a function's API. That would allow direct dispatch</div><div class="">to specialized code without type checks, even across modules.</div><div class=""></snip Generics.rst></div><div class=""><br class=""></div><div class="">In the future, we can build on this work in several ways:</div><div class="">- cross module dispatch directly to specialized code</div><div class="">- dynamic dispatch directly to specialized code</div><div class="">- automated specialization based on broader hints</div><div class="">- partial specialization</div><div class="">- and so on…</div><div class=""><br class=""></div><div class="">Andy</div></body></html>