[swift-evolution] [Proposal draft] Conditional conformances

Douglas Gregor dgregor at apple.com
Tue Sep 27 11:52:48 CDT 2016

> On Sep 26, 2016, at 5:37 PM, Robert Widmann <devteam.codafi at gmail.com> wrote:
> +1.  I have one purely bureaucratic concern that I couldn't quite find answers to on a read through:
> Orphan instances

Not sure what you mean by “orphan instances”?

> and more generally cross-module uniqueness of instances are not mentioned.  What's the policy here?  Are we locally unique with respect to imported modules or globally unique with respect to all importable modules?

Yeah, this is a painfully underspecified area of Swift’s generics system. The compiler diagnoses redundant conformances when it sees both conformances, but that’s not enough to guarantee global uniqueness. The runtime effectively depends on global uniqueness, and there are no mechanisms in the language or runtime to disambiguate if the non-unique conformances occur.

We’re not in an ideal state, although I don’t think the conditional conformances proposal is the place to try to fix it. Personally, I think we should codify the globally-unique model and provide some level of safety in the runtime to detect (lazily) when there is a run-time conflict. It’s probably worthy of a proposal, although it would be an odd sort of proposal—mostly about describing the model and the trade-offs (no private conformances, potential for run-time oddities if a conflict does occur, etc.) vs. allowing multiple conformances to co-exist (dynamic-casting complexity, the need for a disambiguation mechanism, etc.). At most, we could make it clearer in source code when you’re doing something that *could* cause a runtime conflict. For example, writing a conformance in the module that defines the type or the module that defines the protocol is guaranteed to be okay (modulo resilience!), but a retroactive conformance in a third model is potentially unsafe and might be worthy of some kind of attribute.

Anyway, some random thoughts on this issue are in the generics manifesto:


	- Doug

> ~Robert Widmann
> 2016/09/26 20:18、Douglas Gregor via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> のメッセージ:
>> Conditional conformances
>> Proposal: SE-NNNN <https://github.com/DougGregor/swift-evolution/blob/conditional-conformances/proposals/NNNN-conditional-conformances.md>
>> Author: Doug Gregor <https://github.com/DougGregor>
>> Review Manager: TBD
>> Status: Awaiting review
>> During the review process, add the following fields as needed:
>> Decision Notes: Rationale <https://lists.swift.org/pipermail/swift-evolution/>, Additional Commentary <https://lists.swift.org/pipermail/swift-evolution/>
>> Bugs: SR-NNNN <https://bugs.swift.org/browse/SR-NNNN>, SR-MMMM <https://bugs.swift.org/browse/SR-MMMM>
>> Previous Revision: 1 <https://github.com/apple/swift-evolution/blob/...commit-ID.../proposals/NNNN-filename.md>
>> Previous Proposal: SE-XXXX <https://github.com/DougGregor/swift-evolution/blob/conditional-conformances/proposals/XXXX-filename.md>
>>  <https://github.com/DougGregor/swift-evolution/tree/conditional-conformances#introduction>[snip[
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160927/f613a348/attachment.html>

More information about the swift-evolution mailing list