<div dir="ltr">Protocol forwarding was discussed on-list near the end of 2015 in the thread “[swift-evolution] [Proposal Draft] automatic protocol forwarding”. Feedback was generally positive, though there were disagreements about whether the forwarder and/or forwardee should have to conform to the protocol. Also, complications regarding Self requirements were brought up.<div><br></div><div>For simplicity, if we are going to do this, I propose the following:</div><div><br></div><div><b>Direct forwarding</b></div><div>• Both the forwarder and the forwardee must conform to the protocol being forwarded.</div><div>• The forwarder’s associated types are inferred to (and must) match the forwardee’s.</div><div>• Requirements the forwarder implements take precedence and are not forwarded.</div><div><br></div><div><b>Self requirements</b></div><div>• A return type of Self cannot be forwarded.<br></div><div>• A return type of, eg. Self.Element, *can* be forwarded, since the associated types match.</div><div>• A parameter type of Self is forwarded in the natural way, by calling the forwardee’s implementation with the argument’s forwardee.</div><div><br></div><div>Example of that last point:</div><div><br></div><div><font face="monospace, monospace">protocol P { func f(_: Self) }</font></div><div><div><font face="monospace, monospace">struct Q: P { func f(_: Q){ } }</font></div><div><font face="monospace, monospace">class C: P {</font></div><div><font face="monospace, monospace">  var q: Q implements P</font></div><div><font face="monospace, monospace">  </font></div><div><font face="monospace, monospace">  // synthesized:</font></div><div><font face="monospace, monospace">  func f(_ a: C) {</font></div><div><font face="monospace, monospace">    q.f(a.q)</font></div><div><font face="monospace, monospace">  }</font></div><div><font face="monospace, monospace">}</font></div><div><br></div><div>Some of these restrictions could potentially be lifted in the future, however for the time being I think they serve an important purpose.</div><div><br></div><div>All that said, I am not yet entirely convinced that protocol forwarding carries sufficient benefits to justify its addition to the language.</div><div><br></div><div>Nevin</div></div><div><br></div></div>