<div dir="ltr">Hi All:<div><br></div><div>Just wanted to wind this up and summarize the results.</div><div><br></div><div>Although there were a few no votes, it looks like there's a consensus for adding a `isa_and_nonnull` type operator. While there were some who preferred `isa_nonnull`, it wasn't overwhelming, and since `isa_and_nonnull` is already committed, I'm going to leave it as `isa_and_nonnull` for the time being.</div><div><br></div><div>Thanks for all the comments.</div><div>don</div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 11, 2019 at 7:49 PM Don Hinton <<a href="mailto:hintonda@gmail.com">hintonda@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr">On Wed, Apr 10, 2019 at 11:37 AM David Greene <<a href="mailto:dag@cray.com" target="_blank">dag@cray.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Don Hinton via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> writes:<br>
<br>
> Used like this: isa<T,1>(v) or isa<T, true>(v)<br>
<br>
I don't think I would know what that means when I see it in code.<br></blockquote><div><br></div><div>Sorry, I was just trying to highlight a different way of doing it, and lazily used a bool. Here's something a little more realistic:</div><div><br></div><div><div>struct NulCheck : std::true_type {};</div><div><br></div><div>template <class X, class Check, class Y,</div><div> typename std::enable_if<Check::value, X>::type * = nullptr></div><div>LLVM_NODISCARD inline bool isa(const Y *Val) {</div><div> return Val && isa<X>(Val);</div><div>}</div></div><div><br></div><div>isa<foo,NulCheck>(v)<br></div><div><br></div><div>Not sure if that's better than isa_and_nonnull or isa_nonnull, but it's shorter than the first, and only slightly longer than the second.</div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
-David<br>
<br>
> On Sat, Apr 6, 2019 at 9:45 AM Mehdi AMINI via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> On Fri, Apr 5, 2019 at 5:15 AM Aaron Ballman via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
><br>
> On Thu, Apr 4, 2019 at 12:58 PM Chris Lattner <<a href="mailto:clattner@nondot.org" target="_blank">clattner@nondot.org</a>> wrote:<br>
> ><br>
> ><br>
> ><br>
> > > On Apr 4, 2019, at 5:37 AM, Don Hinton via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
> > ><br>
> > > I'd like to propose adding `isa_or_null<>` to replace the following usage pattern that's relatively common in conditionals:<br>
> > ><br>
> > > var && isa<T>(var) =>> isa_or_null<T>(var)<br>
> > ><br>
> > > And in particular when `var` is a method call which might be expensive, e.g.:<br>
> > ><br>
> > > X->foo() && isa<T>(X->foo()) =>> isa_or_null<T>(X->foo())<br>
> > ><br>
> > > The implementation could be a simple wrapper around isa<>, and while the IR produced is only slightly more efficient, the elimination of an extra<br>
> call could be worthwhile.<br>
> ><br>
> > I’d love to see this, I agree with downstream comments though that this name will be confusing. isa_and_nonnull<>. ?<br>
><br>
> tbh, I don't think the proposed name will be all that confusing --<br>
><br>
> I am with David on this, this sounds like misleading naming to me, I would expect true on null value when reading : if (isa_or_null<T>(var))<br>
><br>
> we're used to _or_null() returning "the right thing" when given null.<br>
><br>
> I think we're used to have "the right thing" because the name matches the semantic: the "_or_null()" suffix matches the semantics a conversion operator<br>
> that returns nullptr on failure.<br>
> It does not translate with isa<> IMO.<br>
><br>
> <br>
> isa_and_nonnull<> is a bit of a weird name for me, but I could<br>
> probably live with it. We could spell it nonnull_and_isa<> to reflect<br>
> the order of the operations, but that sort of hides the important part<br>
> of the API (the "isa" bit).<br>
><br>
> isa_nonnulll works fine for me, isa_and_nonnull is a bit verbose but seems OK as well.<br>
><br>
> For nonnull_and_isa<T>(val) ; it starts to look strangely close to the pattern !val && isa<T>(val) ; and I'm not sure it is really such a readability<br>
> improvement anymore?<br>
><br>
> -- <br>
> Mehdi<br>
><br>
> <br>
> <br>
> ~Aaron<br>
><br>
> ><br>
> > -Chris<br>
> ><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
><br>
> _______________________________________________<br>
> LLVM Developers mailing list<br>
> <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
> <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div></div></div>
</blockquote></div>