<div dir="ltr"><div dir="ltr"><div>I read `isa<T>(or_null(v))`  as "v is a T or nullptr", which does not match the implementation semantics "v is a T and not null".</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Apr 6, 2019 at 9:31 PM Zachary Turner <<a href="mailto:zturner@google.com">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">Sorry, brain isn't fully working.  I meant to call the function / type `or_null` instead of `not_null`</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, Apr 6, 2019 at 11:16 AM Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">What about a type 

not_null_impl<T> and we could write:<br></div><div dir="ltr"><div><br><div>then you could just write bool x = isa<T>(not_null(val));</div><div><br></div><div>We provide a function not_null<T> that returns a not_null_impl<T>:</div><div><br></div><div>template<typename T></div><div>not_null_impl<T> not_null(T *t) { return not_null_impl<T>{t}; }</div><div><br></div><div>and a specialization of isa that takes a not_null_impl<T></div><div><br></div><div>template<typename T, typename U></div><div>isa<T, not_null_impl<U>>(const 

not_null_impl<U> &u) {<br></div><div>  return u ? isa<T>(*u) : false;</div><div>}</div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">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></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">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></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">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 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></blockquote><div><br></div><div>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))</div><div><span class="gmail-m_-4362377878020921094gmail-m_-8671020069628501524gmail-m_7523165013818793207gmail-im"><br></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
we're used to _or_null() returning "the right thing" when given null.<br></blockquote><div><br></div><div>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 that returns nullptr on failure.</div><div>It does not translate with isa<> IMO.</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
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></blockquote><div><br></div><div>isa_nonnulll works fine for me, isa_and_nonnull is a bit verbose but seems OK as well.<br></div><div><br></div><div>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 improvement anymore?<br></div><div><div><br></div><div>-- </div><div>Mehdi</div></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">
<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>
</blockquote></div></div></div></div></div>
_______________________________________________<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>
</blockquote></div>
</blockquote></div></div></div>