Message ID | 20240228192843.188979-27-kmatsui@gcc.gnu.org |
---|---|
State | New |
Headers | show |
Series | Optimize more type traits | expand |
On Wed, 28 Feb 2024, Ken Matsui wrote: > This patch optimizes the compilation performance of > std::is_nothrow_invocable by dispatching to the new > __is_nothrow_invocable built-in trait. > > libstdc++-v3/ChangeLog: > > * include/std/type_traits (is_nothrow_invocable): Use > __is_nothrow_invocable built-in trait. > * testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc: > Handle the new error from __is_nothrow_invocable. > * testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc: > Likewise. > > Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org> > --- > libstdc++-v3/include/std/type_traits | 4 ++++ > .../20_util/is_nothrow_invocable/incomplete_args_neg.cc | 1 + > .../testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc | 1 + > 3 files changed, 6 insertions(+) > > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits > index 9af233bcc75..093d85a51a8 100644 > --- a/libstdc++-v3/include/std/type_traits > +++ b/libstdc++-v3/include/std/type_traits > @@ -3265,8 +3265,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > /// std::is_nothrow_invocable > template<typename _Fn, typename... _ArgTypes> > struct is_nothrow_invocable > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable) > + : public __bool_constant<__is_nothrow_invocable(_Fn, _ArgTypes...)> > +#else > : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>, > __call_is_nothrow_<_Fn, _ArgTypes...>>::type > +#endif > { > static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}), > "_Fn must be a complete class or an unbounded array"); > diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc > index 3c225883eaf..3f8542dd366 100644 > --- a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc > +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc > @@ -18,6 +18,7 @@ > // <http://www.gnu.org/licenses/>. > > // { dg-error "must be a complete class" "" { target *-*-* } 0 } > +// { dg-prune-output "invalid use of incomplete type" } Is the error coming somewhere from the new build_invoke function? That'd be surprising since we pass tf_none to it, which should suppress such errors. (You can probably break on cxx_incomplete_type_diagnostic to find out where it's coming from.) > > #include <type_traits> > > diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc > index 5a728bfa03b..d3bdf08448b 100644 > --- a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc > +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc > @@ -18,6 +18,7 @@ > // <http://www.gnu.org/licenses/>. > > // { dg-error "must be a complete class" "" { target *-*-* } 0 } > +// { dg-prune-output "invalid use of incomplete type" } > > #include <type_traits> > > -- > 2.44.0 > >
On Fri, Mar 8, 2024 at 9:22 AM Patrick Palka <ppalka@redhat.com> wrote: > > On Wed, 28 Feb 2024, Ken Matsui wrote: > > > This patch optimizes the compilation performance of > > std::is_nothrow_invocable by dispatching to the new > > __is_nothrow_invocable built-in trait. > > > > libstdc++-v3/ChangeLog: > > > > * include/std/type_traits (is_nothrow_invocable): Use > > __is_nothrow_invocable built-in trait. > > * testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc: > > Handle the new error from __is_nothrow_invocable. > > * testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc: > > Likewise. > > > > Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org> > > --- > > libstdc++-v3/include/std/type_traits | 4 ++++ > > .../20_util/is_nothrow_invocable/incomplete_args_neg.cc | 1 + > > .../testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc | 1 + > > 3 files changed, 6 insertions(+) > > > > diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits > > index 9af233bcc75..093d85a51a8 100644 > > --- a/libstdc++-v3/include/std/type_traits > > +++ b/libstdc++-v3/include/std/type_traits > > @@ -3265,8 +3265,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION > > /// std::is_nothrow_invocable > > template<typename _Fn, typename... _ArgTypes> > > struct is_nothrow_invocable > > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable) > > + : public __bool_constant<__is_nothrow_invocable(_Fn, _ArgTypes...)> > > +#else > > : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>, > > __call_is_nothrow_<_Fn, _ArgTypes...>>::type > > +#endif > > { > > static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}), > > "_Fn must be a complete class or an unbounded array"); > > diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc > > index 3c225883eaf..3f8542dd366 100644 > > --- a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc > > +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc > > @@ -18,6 +18,7 @@ > > // <http://www.gnu.org/licenses/>. > > > > // { dg-error "must be a complete class" "" { target *-*-* } 0 } > > +// { dg-prune-output "invalid use of incomplete type" } > > Is the error coming somewhere from the new build_invoke function? That'd > be surprising since we pass tf_none to it, which should suppress such > errors. (You can probably break on cxx_incomplete_type_diagnostic to > find out where it's coming from.) Hi Patrick, Thank you for your review! This error comes from cxx_incomplete_type_diagnostic in check_trait_type, i.e., before the new build_invoke function. As we discussed previously, it would be better if we could produce diagnostics that are in harmony with libstdc++. > > > > > #include <type_traits> > > > > diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc > > index 5a728bfa03b..d3bdf08448b 100644 > > --- a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc > > +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc > > @@ -18,6 +18,7 @@ > > // <http://www.gnu.org/licenses/>. > > > > // { dg-error "must be a complete class" "" { target *-*-* } 0 } > > +// { dg-prune-output "invalid use of incomplete type" } > > > > #include <type_traits> > > > > -- > > 2.44.0 > > > > >
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 9af233bcc75..093d85a51a8 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -3265,8 +3265,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// std::is_nothrow_invocable template<typename _Fn, typename... _ArgTypes> struct is_nothrow_invocable +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_nothrow_invocable) + : public __bool_constant<__is_nothrow_invocable(_Fn, _ArgTypes...)> +#else : __and_<__is_invocable_impl<__invoke_result<_Fn, _ArgTypes...>, void>, __call_is_nothrow_<_Fn, _ArgTypes...>>::type +#endif { static_assert(std::__is_complete_or_unbounded(__type_identity<_Fn>{}), "_Fn must be a complete class or an unbounded array"); diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc index 3c225883eaf..3f8542dd366 100644 --- a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc @@ -18,6 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include <type_traits> diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc index 5a728bfa03b..d3bdf08448b 100644 --- a/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc @@ -18,6 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include <type_traits>
This patch optimizes the compilation performance of std::is_nothrow_invocable by dispatching to the new __is_nothrow_invocable built-in trait. libstdc++-v3/ChangeLog: * include/std/type_traits (is_nothrow_invocable): Use __is_nothrow_invocable built-in trait. * testsuite/20_util/is_nothrow_invocable/incomplete_args_neg.cc: Handle the new error from __is_nothrow_invocable. * testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc: Likewise. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org> --- libstdc++-v3/include/std/type_traits | 4 ++++ .../20_util/is_nothrow_invocable/incomplete_args_neg.cc | 1 + .../testsuite/20_util/is_nothrow_invocable/incomplete_neg.cc | 1 + 3 files changed, 6 insertions(+)