[llvm-dev] [RFC] Should we add isa_or_null<>?
Justin Bogner via llvm-dev
llvm-dev at lists.llvm.org
Mon Apr 8 16:15:09 PDT 2019
David Greene via llvm-dev <llvm-dev at lists.llvm.org> writes:
> Bruno Ricci via llvm-dev <llvm-dev at lists.llvm.org> writes:
>
>> On 07/04/2019 14:13, via llvm-dev wrote:
>>> I have to say `not_null(v)` reads more like an assertion than a
>>> predicate, in which case `isa<T>(not_null(v))` reads like it has the
>>> exact same semantics that `isa<T>(v)` has currently—asserts that `v`
>>> is not null.
>>>
>>> I don't dispute that you can *make* it have the desired semantics,
>>> it just won't *look* that way.
>>>
>>>
>>>
>>> maybe `isaT_or_null<Foo>(v)` ? Still looks awkward but maybe less
>>> naively misleading.
>>>
>>
>> ... or we keep using "v && isa<T>(v)" (which is not even longer!),
>> which is unambiguous for everyone. In the rare special case where
>> the pattern "someExpensiveCall() && isa<T>(someExpensiveCall())" is
>> used, just assign the result of "someExpensiveCall()" to a variable.
>
> +1.
+1. Both "if (v && isa<T>(v)) ..." and "if (dyn_cast_or_null<T>(v)) ..."
are easier to understand than any of the suggested isa_foo_bar options.
Why add another way to accomplish something that already has two ways to
do it?
More information about the llvm-dev
mailing list