[swift-dev] Initialization of default values

Joe Groff jgroff at apple.com
Thu Dec 10 10:28:25 CST 2015


> On Dec 9, 2015, at 3:28 PM, Matthew Johnson via swift-dev <swift-dev at swift.org> wrote:
> 
> I am working on a proposal for flexible memberwise initialization and would like to understand how Swift currently handles initialization of members that have a default specified in the declaration when an initializer does not explicitly initialize them.  Can someone familiar with this provide a brief summary or point me in the right direction to learn more (either documentation or compiler code).

This is under flux. Currently the compiler emits a default argument generator function for each defaulted argument, and emits a corresponding call at any call site that uses the default argument. The idea behind this was that the value of the argument could be changed without breaking ABI, but in practice this has been problematic, and constrains resilience in other undesirable ways. We're planning to move to a more C++-like model, where the default argument expression is instantiated at each call site. I think Doug and Jordan would be the best ones to discuss both the current model and our planned final design.

-Joe


More information about the swift-dev mailing list