[swift-evolution] Specialization of functions with default parameters or discardable result

Andrew Trick atrick at apple.com
Wed Apr 27 15:33:05 CDT 2016

> On Apr 26, 2016, at 3:40 AM, 张国晔 via swift-evolution <swift-evolution at swift.org> wrote:
> Functions in Swift can have default parameters or discardable result, but without inlining, calling them could be suboptimal in performance.
> I propose a solution which compiler generates specializations of those functions, hence more optimization can be performed for specific usage.
> This can also be used to solve binary compatibility when new parameters are added to a function.
> Draft:
> https://github.com/cc941201/swift-evolution/blob/master/proposals/NNNN-function-specialization.md <https://github.com/cc941201/swift-evolution/blob/master/proposals/NNNN-function-specialization.md>

Thanks for the proposal. In the long run, we will probably have
API-level annotation for explicit specialization, as you are
proposing. But it's best to first experiment with different forms of
specialization, both automatic and annotation driven, internally
before proposing the language feature. Currently, the optimizer
performs a variety of automatic function specialization within a
module (with -whole-module-optimization). We also have an explicit
form of generic specialization (using @_specialize), which is hidden
from the Module's API. We don't yet have an explicit annotation that
allows specializing for argument values and for dead arguments and return
values since we haven't seen a compelling performance need to do that
across Module boundaries.

Exposing explicit function specialization as an API feature will
require specifying the affect on library evolution. We're deferring that
issue until other aspects of library evolution are sorted out:


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160427/a0e968bc/attachment.html>

More information about the swift-evolution mailing list