[swift-evolution] stored properties in extensions (was: associated objects)
Thorsten Seitz
tseitz42 at icloud.com
Thu Nov 3 10:13:58 CDT 2016
Has anybody thought about the semantic issues of out-of-module extensions with stored properties apart from the implementation issues?
Such properties could potentially wreak havoc with the semantics of the type being extended. How would these properties play nice with an existing definition of equality, for example? How can it be guaranteed that their value is consistent with the remaining state? And kept that way in case of mutability?
-Thorsten
> Am 15.10.2016 um 03:01 schrieb Paul Cantrell via swift-evolution <swift-evolution at swift.org>:
>
>
>> On Oct 9, 2016, at 3:43 PM, Charles Srstka via swift-evolution <swift-evolution at swift.org> wrote:
>>
>> Let extensions introduce stored properties, but only in the same module as the type’s definition. Then, the compiler can just take any extensions into consideration when it’s determining the size of the type, just as if the properties had been declared in the type. Declaring stored properties on an extension outside of the type’s module results in a compiler error, exactly as today. This would, without any performance drawbacks, solve one of the big problems that people are hoping to solve via stored properties in extensions—the ability to organize members by protocol conformance.
>
> Yes please! A big strong +1 to this from me. I can think of several specific chunks of problem code that this would clean up immensely.
>
> Contra Karl in another message, it’s _in-module_ stored property extensions that I want most frequently. By far.
>
> It seems to me that Charles’s idea could be introduced as its own proposal. If out-of-module stored property extensions do eventually become feasible, then Charles’s proposal is a good stepping stone. If they never do, then his proposal has done no harm.
>
> I realize this probably falls into the post-ABI stability bucket, but I’d love to help write/support the proposal when its time comes.
>
> Cheers,
>
> Paul
>
> _______________________________________________
> 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