> On 7 Sep 2017, at 18:53, Tony Allevato via swift-evolution 
> <[email protected]> wrote:
> 
> 
> 
> On Thu, Sep 7, 2017 at 10:39 AM Gwendal Roué <[email protected] 
> <mailto:[email protected]>> wrote:
>> Le 7 sept. 2017 à 14:45, Tony Allevato <[email protected] 
>> <mailto:[email protected]>> a écrit :
>> 
>> Right, let's make sure we're talking about the right thing here. Gwendal, 
>> your issue isn't with synthesis in the form of Codable or the new additions 
>> to Equatable/Hashable which are opt-in-by-conformance, it's with the 
>> specific case of raw value enums or enums without associated values where 
>> the synthesis is implicit with no way to opt-out. That's a big difference.
> 
> Yes.
> 
>> I can definitely see the latter being an issue if it were more widespread, 
>> and I'd be supportive of those enums being required to declare their 
>> conformance for consistency (though it would be source breaking).
> 
> Yes, unfortunately.
> 
> 
>> However, I still haven't seen a real issue that has come up because of the 
>> distinction being drawn here between default implementations vs. 
>> implementations that can access other parts of the concrete type. It sounds 
>> like this discussion is trying to protect against a hypothetical problem 
>> that hasn't happened yet and may not happen; it would be helpful to show 
>> some motivating real-world cases where this is indeed a severe problem.
> 
> Yes. I'm not talking about implementation itself. I know this has been the 
> main topic until I have tried to bring in the topic of the consequences of 
> non-avoidable synthesis (extra methods that may conflict with userland 
> methods).
> 
> If you ask me for a real-world case, then I think I gave one. Let me rephrase 
> it:
> 
> it's impossible to define a value-backed enum without getting free Equatable 
> conformance. This free conformance is sometimes unwanted, and I gave the 
> example of DSLs. Now this problem is not *severe*. It's more a blind spot in 
> the language, and finally just an unwanted side-effect of a compiler 
> convenience,
> 
> Again, this is not the issue that Haravikk is describing in this thread.
> 
> I'll clarify—your issue is specifically with the fact that enums with raw 
> values and enums without associated values receive Equatable even without 
> explicitly conforming to it, and therefore users have no way of opting out of 
> it. This predates SE-0185, and I didn't propose making any changes to the 
> conformance of those enums for source compatibility reasons, though I 
> wouldn't be opposed to it because it makes them consistent across the board.
> 
> Haravikk's argument is about synthesized conformances like Codable and 
> Equatable/Hashable in SE-0185, where the user must explicitly conform the 
> type to those protocols. His claim is that that act of opting in is not 
> sufficient and that it is still dangerous if those synthesized conformances 
> can access members that are not also declared in the protocol. That's a 
> completely separate issue to yours, and one that I hope he'll present more 
> evidence of. Right now, requiring that you not only explicitly conform to the 
> protocol but also explicitly request the synthesis feels like a solution 
> without an actual problem, and is a situation we already have today with 
> default method implementations.

The simplest real-world case is easy:

        struct Foo { var data:String }
        extension Foo : Equatable {} // This currently produces an error, in 
future it will not

I argued this point on the specific topic for Equatable/Hashable, but it was, 
both during and after review, essentially ignored and the decision to 
synthesise implicitly never sufficiently justified. The closest that I got was 
"but Codable does it" which is about as weak a justification as you could 
possibly get as I don't really agree with it in the case of Codable either. In 
the case of Equatable/Hashable specifically this is arguably a breaking change 
that has IMO been totally ignored by the core team who haven't given any 
reasonable response.


In the broader case however I still feel that synthesised behaviour should 
require explicit rather than implicit opt-in, as it allows us to distinguish 
between a developer who wants to implement requirements themselves, versus one 
who is happy to have one derived from their concrete type automatically. The 
current setup does not allow this at all. In future if the role keywords are 
adopted we will always be able to distinguish one who wants to explicitly 
implicit more than just the minimum requirements.
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to