[swift-evolution] Improved value and move semantics
Joe Groff
jgroff at apple.com
Wed Aug 3 21:57:17 CDT 2016
> On Aug 3, 2016, at 4:58 PM, Chris Lattner via swift-evolution <swift-evolution at swift.org> wrote:
>
> On Aug 3, 2016, at 6:41 AM, Matthew Johnson via swift-evolution <swift-evolution at swift.org> wrote:
>>>> Then you can just slap `indirect` on a struct whose copying is too
>>>> complicated and let Swift transparently COW it for you. (And it would
>>>> also permit recursive structs and other such niceties.)
>>>
>>> My vision for this feature is:
>>>
>>> a. We indirect automatically based on some heuristic, as an
>>> optimization.
>
> I weakly disagree with this, because it is important that we provide a predictable model. I’d rather the user get what they write, and tell people to write ‘indirect’ as a performance tuning option. “Too magic” is bad.
I think 'indirect' structs with a heuristic default are important to the way people are writing Swift in practice. We've seen many users fully invest in value semantics types, because they wants the benefits of isolated state, without appreciating the code size and performance impacts. Furthermore, implementing 'indirect' by hand is a lot of boilerplate. Putting indirectness entirely in users' hands feels to me a lot like the "value if word sized, const& if struct" heuristics C++ makes you internalize, since there are similar heuristics where 'indirect' is almost always a win in Swift too.
-Joe
>>> b. We allow you to indirect manually.
>>>
>>> c. We provide an attribute that suppresses automatic indirection to
>>> whatever depth possible given resilience boundaries.
>>
>> This all sounds great. Does any of this fit into Swift 4 (either phase 1 or phase 2)? It seems like at least the automatic part would have ABI impact.
>
> This is very low priority, because it is generally additive. After the major topics for ABI stability are figured out, we can have the philosophic discussion about the automatic part.
>
> -Chris
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
More information about the swift-evolution
mailing list