[swift-evolution] [swift-evolution-announce] [Review] SE-0189: Restrict Cross-module Struct Initializers

Slava Pestov spestov at apple.com
Mon Nov 20 22:54:21 CST 2017



> On Nov 20, 2017, at 11:14 PM, Drew Crawford <drew at sealedabstract.com> wrote:
> 
> It would improve the important clients without harming other clients to use the following implementation for our type: if the sorted accessor is used before the unsorted one, sort the underlying storage, and then serve that until the type is subsequently mutated (which important clients do not do).  This amortizes the cost of the sort across many calls to the accessor.

Sure, but it’s hard to completely encapsulate this kind of caching behavior inside the type. For example, thread safety. But yes, there are different tradeoffs with reference and value types, and it’s hard to argue that one is better for encapsulation than the other.

> > We want to be able to add new stored properties to structs, or change existing stored properties to computed properties (and vice versa) without breaking binary or source compatibility.
> 
> If CGAffineTransform, CGPoint, in_addr_t etc. are changing their members we have a problem.  There are probably structs where this makes more sense, but I can't immediately think of an example.

in_addr_t is actually mostly opaque so it’s actually not a good example.I agree that CGAffineTransform and such are trivial. But it’s easy to think of cases where you want to change the internal representation of a data type without changing it’s API, and sometimes this means stored properties become computed properties. The only place in the language where the difference between stored and computed properties can be observed is inside a non-delegating initializer of a struct, so it makes sense to prohibit them from being defined outside of the original module.

Slava

> 
> 
> On November 20, 2017 at 6:16:55 PM, Slava Pestov (spestov at apple.com <mailto:spestov at apple.com>) wrote:
> 
>> 
>> 
>>> On Nov 20, 2017, at 1:58 PM, Drew Crawford via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 
>>> I'm "weak oppose" on this proposal.
>>> 
>>> The core premise here is to increase the encapsulation of a struct around its member variables.  But I think the purview of encapsulation is more classes than structs.
>> 
>> 
>> How so? It seems that encapsulation is orthogonal to reference/value semantics.
>> 
>>>  e.g. a struct leaks information about the mutation of its member variables, even if those variables are private.
>> 
>> Can you explain what you mean by this?
>> 
>>>  Structs are the obvious implementation for a named tuple (CGPoint CGAffineTransform UIColor etc.) where there is inherently a fixed set of members that are more conveniently accessed directly.  Structs and classes have different purposes and so the argument for consistency with classes is weak.
>>> 
>>> With regard to the BalancedPair problem, I would prefer to see a "final struct" or "required init”.
>> 
>> The real reason we want to introduce this language change is to solve some problems related to resilience. We want to be able to add new stored properties to structs, or change existing stored properties to computed properties (and vice versa) without breaking binary or source compatibility. Since non-delegating initializers expose the exact set of stored properties to the client module, they break the encapsulation that we need to allow this.
>> 
>> Slava
>>> On November 14, 2017 at 1:31:25 PM, Ted Kremenek (kremenek at apple.com <mailto:kremenek at apple.com>) wrote:
>>> 
>>>> The review of "SE-0189: Restrict Cross-module Struct Initializers" begins now and runs through November 21, 2017.
>>>> 
>>>> The proposal is available here:
>>>> 
>>>> https://github.com/apple/swift-evolution/blob/master/proposals/0189-restrict-cross-module-struct-initializers.md <https://github.com/apple/swift-evolution/blob/master/proposals/0189-restrict-cross-module-struct-initializers.md>
>>>> Reviews are an important part of the Swift evolution process. All review feedback should be sent to the swift-evolution mailing list at:
>>>> 
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
>>>> or, if you would like to keep your feedback private, directly to the review manager. 
>>>> 
>>>> When replying, please try to keep the proposal link at the top of the message:
>>>> 
>>>> Proposal link: https://github.com/apple/swift-evolution/blob/master/proposals/0189-restrict-cross-module-struct-initializers.md <https://github.com/apple/swift-evolution/blob/master/proposals/0189-restrict-cross-module-struct-initializers.md>
>>>> ...
>>>> Reply text
>>>> ...
>>>> Other replies
>>>> What goes into a review of a proposal?
>>>> 
>>>> The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. 
>>>> 
>>>> When reviewing a proposal, here are some questions to consider:
>>>> 
>>>> What is your evaluation of the proposal?
>>>> 
>>>> Is the problem being addressed significant enough to warrant a change to Swift?
>>>> 
>>>> Does this proposal fit well with the feel and direction of Swift?
>>>> 
>>>> If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
>>>> 
>>>> How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
>>>> 
>>>> Thanks,
>>>> Ted Kremenek
>>>> Review Manager
>>>> _______________________________________________
>>>> swift-evolution-announce mailing list
>>>> swift-evolution-announce at swift.org <mailto:swift-evolution-announce at swift.org>
>>>> https://lists.swift.org/mailman/listinfo/swift-evolution-announce
>>> _______________________________________________
>>> swift-evolution mailing list
>>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
>>> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171120/6ce57a0e/attachment.html>


More information about the swift-evolution mailing list