<div dir="ltr">(oops, dropped the list by accident)<br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">David Blaikie</b> <span dir="ltr"><<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>></span><br>Date: Wed, Jul 22, 2015 at 5:10 PM<br>Subject: Re: [PATCH] Add iterator for PHINode value/BB pair<br>To: "Duncan P. N. Exon Smith" <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>><br><br><br><div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jul 22, 2015 at 5:05 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
> On 2015-Jul-22, at 16:57, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Wed, Jul 22, 2015 at 4:50 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>> wrote:<br>
><br>
> > On 2015-Jul-22, at 15:07, David Blaikie <<a href="mailto:dblaikie@gmail.com" target="_blank">dblaikie@gmail.com</a>> wrote:<br>
> ><br>
> ><br>
> ><br>
> > On Wed, Jul 22, 2015 at 12:11 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>> wrote:<span class=""><br>
<span>> ><br>
> > > On 2015-Jul-21, at 21:20, Pete Cooper <<a href="mailto:peter_cooper@apple.com" target="_blank">peter_cooper@apple.com</a>> wrote:<br>
> > ><br>
> > > Thanks for all the feedback.  This is a patch which addresses all of it.<br>
> > ><br>
> > > <phinode.diff><br>
> > ><br>
> ><br>
> > > +<br>
> > > +    const PHINodeEdge operator*() const {<br>
> ><br>
> > No reason for the const in `const PHINodeEdge` here.<br>
> ><br>
> > to support operator-> you have to return a pointer, which means you need the PHINodeEdge storage inside the iterator to point to (& then you can just return a const ref from op*)<br>
><br>
> Do we need operator->()?<br>
><br>
> Seems poor form not to provide it (someone'll trip over it pretty quickly, I'd imagine)<br>
><br>
> If so, we can return a proxy object:<br>
><br>
>     struct PHINodeEdgeArrowProxy {<br>
>       const PHINodeEdge RefProxy;<br>
>     public:<br>
>       PHINodeEdgeArrowProxy(PHINodeEdge Edge) : RefProxy(Edge) {}<br>
>       const PHINodeEdge *operator->() const { return &RefProxy; }<br>
>     };<br>
><br>
>     PHINodeEdgeArrowProxy operator->() const { return operator*(); }<br>
><br>
> Then we avoid bloating the iterator, and only make the copy when we<br>
> actually need it.<br>
><br>
> Non-conforming in terms of the iterator traits, I would imagine<br>
<br>
</span>AFAICT, iterators only require that `i->m` has the same semantics as<br>
`(*i).m`.  The return type isn't specified.<br></span></blockquote><div><br></div><div>Fair enough - can't quite find the wording on what constitutes the iterators value type (as is mentioned in the iterator traits) or how it might relate, but the basic definition is as you've mentioned.</div><span class=""><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>> - but I take it that's the N1550 stuff you're talking about below? It makes these sort of proxy solutions valid?<br>
><br>
<br>
</span>IIRC, proxy solutions are always valid for InputIterator and for<br>
OutputIterator; it's ForwardIterator that prevents `operator*()`<br>
from returning a proxy.<br></blockquote></span><div><br>*nod* I don't mind violating that too much, if that's the preference.<br> </div><span class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">(This makes `std::vector<bool>::iterator` invalid.)<br></blockquote><div><br></div></span><div>Yep. Fails in so many ways.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
<span><br>
><br>
> ><br>
> ><br>
> > > +      return { *Values, *Blocks };<br>
> > > +    }<br>
> > > +  };<br>
> > > +<br>
> ><br>
> > Otherwise LGTM.  Might want to pass it through clang-format; I noticed<br>
> > some minor whitespace oddities.<br>
> ><br>
> > > *snip*<br>
</span></span><span class=""><div><div>> > >> On Jul 21, 2015, at 8:21 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>> wrote:<br>
> > >><br>
> > >><br>
> > >><br>
> > >> If you drop the requirements from `forward_iterator` to<br>
> > >> `input_iterator`, then you're allowed to return a `PHINodeEdge` by-value<br>
> > >> here instead of by-reference (unfortunately this makes it illegal to use<br>
> > >> a bunch of STL algorithms; STL iterator traits are completely broken<br>
> > >> IMO).<br>
> > > I’m fine with this.  David, Chandler, please let me know how you feel about this.<br>
> > ><br>
> > > Also, i forgot to say that I considered doing a zip iterator and inheriting this from it.  This is something I think Chandler or David mentioned a few months ago.  If there’s been any progress in the C++ committee on that then i’m happy to try implement something better.  If not, then i don’t think what I have here should be difficult to change in future.<br>
> ><br>
> > I guess a generalized version would return a<br>
> > `std::tuple<Value *const &, BasicBlock *const &>` or some such.  Not<br>
> > sure how to actually make zip iterators work well without something<br>
> > like N1550 though.<br>
> ><br>
> > What's N1550 offer to make zip work?<br>
><br>
> s/work/& well/<br>
><br>
> I think bloated iterators are bad, but without bloating them (so you<br>
> can return a T&), you can't call a zip_iterator a ForwardIterator,<br>
> which means you can't use it in a bunch of algorithms that you might<br>
> want to (such as the destination for `std::copy()`).<br>
><br>
> N1550 let's you correctly identify the type of traversal the<br>
> zip_iterator can do, without requiring a T& return from operator*().<br>
><br>
> > I wouldn't mind a slightly half-hearted version that works for basic/common cases...<br>
<br>
</div></div></span></blockquote></div><br></div></div>
</div><br></div>