[swift-evolution] Should Swift apply "statement scope" for ARC

John Holdsworth mac at johnholdsworth.com
Thu Sep 22 19:13:36 CDT 2016


> On 22 Sep 2016, at 23:57, Michael Gottesman <mgottesman at apple.com> wrote:
> 
>> As a result the following transfer of a Java instance always worked:
>> 
>>     init(imageProducer:ImageProducer) {
>>         let supr = CanvasBase()
>>         super.init( javaObject: supr.javaObject )
>>         image = createImage(imageProducer)
>>     }
>> 
>> But the following only worked for debug compiles:
>> 
>>     init(imageProducer:ImageProducer) {
>>         super.init( javaObject: CanvasBase().javaObject )
>>         image = createImage(imageProducer)
>>     }
>> 
>> Felt like a bit of a bear trap is all. Statement scope would avoid problems like this.
> 
> You are thinking about this the inverse way. That the first case works is an artifact of the optimizer failing to do a good enough job. Future improved ARC optimization can cause both to fail.

Were this the case I think it would be a step in the wrong direction. Swift is getting
very eager at deallocating objects hence all the "withXYZ()" methods of late which
seem like noise to me. Certainly, having something perform differently from debug
to release builds was not a feature! Viva la Statement Scope which solves all this.

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


More information about the swift-evolution mailing list