<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>+1k.9<br><br>Sent from my iPhone</div><div><br>On Dec 30, 2016, at 18:44, Austin Zheng via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8">After overpromising and underdelivering, I finally managed to sit down and draft a proposal. Sorry it took so long. You can find it here:<div class=""><br class=""></div><div class=""><a href="https://github.com/austinzheng/swift-evolution/blob/recursive-constraints/proposals/XXXX-recursive-protocol-constraints.md" class="">https://github.com/austinzheng/swift-evolution/blob/recursive-constraints/proposals/XXXX-recursive-protocol-constraints.md</a></div><div class=""><br class=""></div><div class="">It contains both a description of the change itself, as well as a list of stdlib changes that need to be made. I used the “FIXME(ABI)” comments in the codebase to compile that list of changes. I also went over parts of the stdlib myself to see if there was anything else I could find, but didn’t notice anything in particular. (I was hoping protocols like `_Integer` could go away, but I’m not sure the issue they’re working around is related to recursive constraints.)</div><div class=""><br class=""></div><div class="">One thing that needs to be done before this can enter formal review is thinking through cases where “valid” recursive constraints might break the compiler. Help on that (or any other feedback, really) would be greatly appreciated.</div><div class=""><br class=""></div><div class="">Best,</div><div class="">Austin<br class=""><div class=""><br class=""></div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 21, 2016, at 6:42 PM, Austin Zheng &lt;<a href="mailto:austinzheng@gmail.com" class="">austinzheng@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Never mind, I just saw SE-0142. I need to go back and read all the proposals again!</div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Nov 21, 2016 at 6:32 PM, Austin Zheng <span dir="ltr" class="">&lt;<a href="mailto:austinzheng@gmail.com" target="_blank" class="">austinzheng@gmail.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">I'm still working on this. When you mention where clauses on associated types, how should I handle that in the context of the proposal?<div class=""><br class=""></div><div class="">* Consider where clauses part of the proposal (so that the proposal becomes "recursive associated type constraints + where clauses on associated types")</div><div class="">* Assume that where clauses will definitely be accepted, and write the stdlib changes assuming that</div><div class="">* Assume that where clauses might not be accepted, and write the stdlib changes assuming that, but also have a section containing further stdlib changes conditional on where clauses being accepted</div><div class=""><br class=""></div><div class="">Best,</div><div class="">Austin</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, Nov 13, 2016 at 7:55 PM, Douglas Gregor <span dir="ltr" class="">&lt;<a href="mailto:dgregor@apple.com" target="_blank" class="">dgregor@apple.com</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class=""><div class=""><br class=""><br class="">Sent from my iPhone</div><span class=""><div class=""><br class="">On Nov 13, 2016, at 4:03 PM, Austin Zheng &lt;<a href="mailto:austinzheng@gmail.com" target="_blank" class="">austinzheng@gmail.com</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div dir="ltr" class="">I'd be happy to put something together, unless someone else wants to take it on.</div></div></blockquote><div class=""><br class=""></div></span>Great, thanks!<div class=""><span class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><br class=""></div><div class="">Doug, I also owe you a PR adding a minor amendment to one of the accepted proposals. I'll get to that this week.</div></div></div></blockquote><div class=""><br class=""></div></span>Sounds great.&nbsp;</div><div class=""><br class=""></div><div class="">&nbsp; - Doug</div><span class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class="">Austin</div></div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Sun, Nov 13, 2016 at 10:13 PM, Douglas Gregor via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto" class=""><div class="">Recursive protocol constraints is one small-looking feature that could greatly improve the standard library. The generics manifesto describes it this way:</div><div class=""><br class=""></div><div class=""><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px" class=""><span style="background-color:rgba(255,255,255,0)" class="">"Currently, an associated type cannot be required to conform to its enclosing protocol (or any protocol that inherits that protocol). For example, in the standard library&nbsp;<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">SubSequence</code>&nbsp;type of a&nbsp;<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Sequence</code>&nbsp;should itself be a&nbsp;<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Sequence</code>:</span></p><div class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051highlight m_-4490272875136436332m_8762435891985121735m_2981084392784924051highlight-source-swift" style="box-sizing:border-box;margin-bottom:16px"><pre style="box-sizing:border-box;word-wrap:normal;margin-top:0px;margin-bottom:0px;padding:16px;overflow:auto;line-height:1.45;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px;word-break:normal" class=""><font face="UICTFontTextStyleBody" class=""><span style="white-space:normal;background-color:rgba(255,255,255,0)" class=""><span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-k" style="box-sizing:border-box">protocol</span> <span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-en" style="box-sizing:border-box">Sequence</span> {
  <span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-k" style="box-sizing:border-box">associatedtype</span> <span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-v" style="box-sizing:border-box">Iterator</span> : <span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-e" style="box-sizing:border-box"><span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-c1" style="box-sizing:border-box">IteratorProtocol</span></span>
  ...
  <span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-k" style="box-sizing:border-box">associatedtype</span> <span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-v" style="box-sizing:border-box">SubSequence</span> : <span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-e" style="box-sizing:border-box"><span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-c1" style="box-sizing:border-box">Sequence</span>   <span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-c" style="box-sizing:border-box">// currently ill-formed, but should be possible</span></span>
<span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-e" style="box-sizing:border-box"><span class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051pl-c" style="box-sizing:border-box"></span></span>}</span></font></pre></div><p style="box-sizing:border-box;margin-top:0px;margin-bottom:16px" class=""><span style="background-color:rgba(255,255,255,0)" class="">The compiler currently rejects this protocol, which is unfortunate: it effectively pushes the&nbsp;<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">SubSequence</code>-must-be-a-<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">Sequ<wbr class="">ence</code>&nbsp;requirement into every consumer of&nbsp;<code style="box-sizing:border-box;padding:0.2em 0px;margin:0px;border-top-left-radius:3px;border-top-right-radius:3px;border-bottom-right-radius:3px;border-bottom-left-radius:3px" class="">SubSequence</code>, and does not communicate the intent of this abstraction well."</span></p><h3 style="box-sizing:border-box;margin-top:24px;margin-bottom:16px;line-height:1.25" class=""><a id="m_-4490272875136436332m_8762435891985121735m_2981084392784924051user-content-nested-generics" class="m_-4490272875136436332m_8762435891985121735m_2981084392784924051anchor" href="https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#nested-generics" style="box-sizing:border-box;text-decoration:none;float:left;padding-right:4px;line-height:1" target="_blank"><u class=""></u><u class=""></u><font size="3" class=""><span style="background-color:rgba(255,255,255,0)" class=""><u class=""></u><u class=""></u></span></font></a></h3>It's actually slightly worse than the above implies: the standard library has a pile of underscore-prefixed protocols (e.g., _Sequence) specifically to dodge this restriction. They are ugly, and we want them to go away. Many of these places are marked with an ABI FIXME in the standard library sources.&nbsp;</div><div class=""><br class=""></div><div class="">Would someone like to write up a proposal for this feature? The syntax and basic semantics are pretty direct, but a proposal should also capture the expected effects on the standard library, particularly when combined with where clauses on associated types.</div><div class=""><br class=""></div><div class="">I also have a nagging feeling that we will need some form of restrictions on this feature for implementation reasons, e.g., because some recursive constraints will form unsolvable systems.</div><div class=""><br class=""></div><div class="">For reference, we've already been implementing this feature. Some information about the compiler internal issues is captured at:</div><div class=""><br class=""></div><div class="">&nbsp;&nbsp;<a href="https://gist.github.com/DougGregor/e7c4e7bb4465d6f5fa2b59be72dbdba6" target="_blank" class="">https://gist.github.com/Doug<wbr class="">Gregor/e7c4e7bb4465d6f5fa2b59b<wbr class="">e72dbdba6</a></div><div class=""><br class=""></div><div class="">&nbsp; - Doug</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""><div class="">Sent from my iPhone</div></div></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailma<wbr class="">n/listinfo/swift-evolution</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div></span></div></blockquote></div><br class=""></div>
</div></div></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>