This is an archive of the discontinued LLVM Phabricator instance.

[ADT] Change PostOrderIterator to use NodeRef. NFC.
ClosedPublic

Authored by timshen on Aug 15 2016, 1:43 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

timshen updated this revision to Diff 68069.Aug 15 2016, 1:43 PM
timshen retitled this revision from to [ADT] Change PostOrderIterator to use NodeRef. NFC..
timshen updated this object.
timshen added a reviewer: dblaikie.
timshen added a subscriber: llvm-commits.
dblaikie added inline comments.Aug 15 2016, 2:01 PM
include/llvm/ADT/PostOrderIterator.h
93–95 ↗(On Diff #68069)

Having T == Pointer == Reference seems wrong. Could you explain how that works?

126 ↗(On Diff #68069)

Optional<T>() => None

(& in a few other places)

timshen added inline comments.Aug 15 2016, 2:16 PM
include/llvm/ADT/PostOrderIterator.h
93–95 ↗(On Diff #68069)

This is because po_iterator has "non-standard" operator*() and operator->().

Ideally, value_type should be NodeRef, reference type is NodeRef& and pointer_type is NodeRef*, but that way the current operator*() and operator->()'s returned types don't suffice.

I think it's an orthogonal issue apart from this patch.

126 ↗(On Diff #68069)

The conversion doesn't work here, because po_iterator_storage has insertEdge as a template function on NodeRef.

We can move the "template <typename NodeRef>" from insertEdge up to po_iterator_storage, but that involves other po_iterator_storage template changes as well.

dblaikie accepted this revision.Aug 15 2016, 2:24 PM
dblaikie edited edge metadata.
dblaikie added inline comments.
include/llvm/ADT/PostOrderIterator.h
126 ↗(On Diff #68069)

Alternatively you could take the first argument to insertEdge as an opaque parameter (another template parameter T) and then convert it in the implementation:

Optional<NodeRef> From = FromValue;

But that might be too weird/complicated with all the different implementations.

This revision is now accepted and ready to land.Aug 15 2016, 2:24 PM
timshen updated this revision to Diff 68081.Aug 15 2016, 2:32 PM
timshen edited edge metadata.

Make std::iterator<...> look normal again.

timshen added inline comments.Aug 15 2016, 2:34 PM
include/llvm/ADT/PostOrderIterator.h
93–95 ↗(On Diff #68081)

Hey somehow I realized that it's only operator->() that is non-standard. I make std::iterator<...> normal, leaving operator->() returning NodeRef. If NodeRef isn't a pointer and the user never calls PoIterator->..., the user code still builds.

122 ↗(On Diff #68081)

Yeah, the main reason I don't want that is it aggressively generalize the insertEdge's interface.

dblaikie added inline comments.Aug 15 2016, 2:37 PM
include/llvm/ADT/PostOrderIterator.h
122 ↗(On Diff #68081)

Not sure I follow - it doesn't really make the interface more permissive (if there were overloads then you'd need some SFINAE to promote the internal template errors out onto the interface to ensure overload resolution did the right thing is the only big wrinkle) - so far as I can see.

Anything that can be implicitly converted to Optional<NodeRef> seems to be what the function is trying to accept.

timshen added inline comments.Aug 15 2016, 2:49 PM
include/llvm/ADT/PostOrderIterator.h
122 ↗(On Diff #68081)

Assuming that the user relies on template argument deduction, then the user has to pass in an Optional<...> object, right? This limits the interface to take Optional objects, not any T that is convertible to an Optional object.

If the user doesn't rely on template argument deduction, they are the same.

This revision was automatically updated to reflect the committed changes.