[swift-evolution] [Proposal] Partial initializers

Slava Pestov spestov at apple.com
Thu Jan 21 23:20:47 CST 2016


> On Jan 21, 2016, at 9:16 PM, Chris Lattner <clattner at apple.com> wrote:
> 
>> 
>> On Jan 21, 2016, at 9:13 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> 
>>> On Jan 20, 2016, at 8:51 PM, Slava Pestov via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 
>>> Adding more details…
>>> 
>>>> On Jan 20, 2016, at 8:46 PM, Slava Pestov via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>>> 
>>>>> I'm a little concerned about exposing these things publicly: there's no point if the struct or class has non-public fields (because new non-delegating initializers can't initialize the non-public fields), and by default every struct and class is allowed to add non-public fields in new versions of a library. (See the LibraryEvolution.rst doc for more info.) I can kind of see making these private vs. internal, but that has other issues (see below).
>>>>> 
>>>>> Even in the case where all fields are public and the struct promises not to change any fields, you'd also have to promise that the partial initializer never changes which properties it's initializing; that's now part of the binary interface of the file. That's unusual for something that behaves like a function; usually the body is not part of the ABI.
>>>>> 
>>>>> I'd much rather just ban 'public' and never have partial inits be part of a library's public interface. Public initializer methods would be presented as plain methods, with no hint of their initializer origins.
>>> 
>>> If we just go with @_transparent functions for partial initialization, there are no new rules to add regarding ABI resilience. :-)
>> 
>> Ignoring the fact that @_transparent isn’t a user feature, I don’t see how this helps.  Mandatory inlining of @_transparent happens after DI runs.
> 
> Sorry, I didn’t see that Jordan brought this up down-thread: He’s exactly right.  We don’t *want* mandatory inlining to run before DI (it used to, and it was a mess).

Ah, I didn’t know that it was already tried and rejected. I guess @_transparent is the wrong thing to hang this off of, then.

> I’m not sold on the notion of partial initializers in the first place, but if we were to go down this path, the approach of nailing down the exact initialization behavior and requirements of the partial initializer - and making it part of its explicitly declared interface - is the right way to go.

Fair enough. I’m also worried about the prospect of adding even more complexity — and syntax — to Swift’s initializer model. My hope is that we can map this to existing language features somehow, or combine this with some other simplification of the initializer model so that the net complexity gain is not too high. But since I don’t have any concrete suggestions at this point, I’ll stay quiet for a while ;-)

Slava


> 
> -Chris

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


More information about the swift-evolution mailing list