[swift-evolution] Should we rename "class" when referring to protocol conformance?

Matthew Johnson matthew at anandabits.com
Sat May 7 23:11:40 CDT 2016


> On May 7, 2016, at 3:53 PM, Dave Abrahams <dabrahams at apple.com> wrote:
> 
> 
> on Sat May 07 2016, Matthew Johnson <matthew-AT-anandabits.com> wrote:
> 
>> Sent from my iPad
>> 
>> On May 7, 2016, at 2:21 AM, Andrew Trick via swift-evolution
>> <swift-evolution at swift.org> wrote:
>> 
>>        On May 6, 2016, at 5:48 PM, Dave Abrahams via swift-evolution
>>        <swift-evolution at swift.org> wrote:
>> 
>>                I don’t mean to imply that it is the *only* valuable
>>            property. However, it I (and many others) do believe it is an
>>            extremely valuable
>>            property in many cases. Do you disagree?
>> 
>>        I think I do. What is valuable about such a protocol? What generic
>>        algorithms could you write that work on models of PureValue but don't
>>        work just as well on Array<Int>?
>> 
>>    class Storage {
>>    var element: Int = 0
>>    }
>> 
>>    struct Value {
>>    var storage: Storage
>>    }
>> 
>>    func amIPure(v: Value) -> Int {
>>    v.storage.element = 3
>>    return v.storage.element
>>    }
>> 
>>    I (the optimizer) want to know if 'amIPure' is a pure function. The
>>    developer needs to tell me where the boundaries of the value lie. Does
>>    'storage' lie inside the Value, or outside? If it is inside, then Value is a
>>    'PureValue' and 'amIPure' is a pure function. To enforce that, the developer
>>    will need to implement CoW, or we need add some language features.
>> 
>> Thank you for this clear exposition of how PureValue relates to pure functions.
>> This is the exact intuition I have about it but you have stated it much more
>> clearly.
>> 
>> Language features to help automate CoW would be great. It would eliminate
>> boilerplate, but more importantly it would likely provide more information to
>> the compiler.
> 
> Whoa; Andy never suggested this would help automate CoW.  Are you
> suggesting that?  How would it work?

Quoting Andy:

"I (the optimizer) want to know if 'amIPure' is a pure function. The developer needs to tell me where the boundaries of the value lie. Does 'storage' lie inside the Value, or outside? If it is inside, then Value is a 'PureValue' and 'amIPure' is a pure function. To enforce that, the developer will need to implement CoW, or we need add some language features."

I was referring to new language features that eliminate the need for the developer to implement CoW manually while preserving the same semantics.  

I don’t know about the general case, but in simple cases I can imagine a feature such as “indirect struct” or Box<T: ValueType> which would contain a reference to a struct on the heap.  Any time a mutating operation was performed on a non-uniquely referenced struct it would be copied first and the internal reference updated to point to the new copy on the heap.  This is the kind of thing I had in mind when I said “automating CoW”.


> 
> -- 
> -Dave

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


More information about the swift-evolution mailing list