[RFC] Add gnu::diagnose_as attribute
Matthias Kretz
m.kretz@gsi.de
Fri Apr 23 15:16:57 GMT 2021
Hi,
before requesting comments on the implementation of this patch, I'd like to
know if there's interest in making use of it at all.
In a nutshell, this solves the problem of bad signal-to-noise ratio with TS
implementations and potentially implementation-internal types.
I've been using the diagnose_as attribute on my parallelism_v2 simd
implementation for two months now, and it significantly improved my
productivity. Like this:
namespace std _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
namespace experimental
{
inline namespace parallelism_v2 [[__gnu__::__diagnose_as__("stdₓ")]]
{
namespace simd_abi [[__gnu__::__diagnose_as__("simd_abi")]]
{
struct [[__gnu__::__diagnose_as__("scalar")]] _Scalar;
using scalar = _Scalar;
template <int _Np>
struct [[__gnu__::__diagnose_as__("fixed_size")]] _Fixed;
template <int _Np>
using fixed_size = _Fixed<_Np>;
[...]
Effects:
1. __PRETTY_FUNCTION__ in my test output:
PASS: void invoke_test(int) [with V = stdₓ::simd<double,
simd_abi::_VecBuiltin<16> >; <template-parameter-1-2> = stdₓ::simd<double,
simd_abi::_VecBuiltin<16> >]
instead of
PASS: void invoke_test(int) [with V =
std::experimental::parallelism_v2::simd<double,
std::experimental::parallelism_v2::simd_abi::_VecBuiltin<16> >; <template-
parameter-1-2> = std::experimental::parallelism_v2::simd<double,
std::experimental::parallelism_v2::simd_abi::_VecBuiltin<16> >]
2. Error messages:
required from 'static constexpr stdₓ::_SimdWrapper<_Tp, _Np>
stdₓ::_SimdImplBuiltin<_Abi, <template-parameter-1-2>
>::_S_fma(stdₓ::_SimdWrapper<_Tp, _Np>, stdₓ::_SimdWrapper<_Tp, _Np>,
stdₓ::_SimdWrapper<_Tp, _Np>) [with _Tp = double; long unsigned int _Np = 2;
_Abi = simd_abi::_VecBuiltin<16>; <template-parameter-1-2> =
stdₓ::__detail::_MachineFlagsTemplate<31, 9>]'
instead of
required from 'static constexpr
std::experimental::parallelism_v2::_SimdWrapper<_Tp, _Np>
std::experimental::parallelism_v2::_SimdImplBuiltin<_Abi, <template-
parameter-1-2> >::_S_fma(std::experimental::parallelism_v2::_SimdWrapper<_Tp,
_Np>, std::experimental::parallelism_v2::_SimdWrapper<_Tp, _Np>,
std::experimental::parallelism_v2::_SimdWrapper<_Tp, _Np>) [with _Tp = double;
long unsigned int _Np = 2; _Abi =
std::experimental::parallelism_v2::simd_abi::_VecBuiltin<16>; <template-
parameter-1-2> =
std::experimental::parallelism_v2::__detail::_MachineFlagsTemplate<31, 9>]'
Since the main user of the attribute would be the standard library (I
believe), this patch only makes sense to pursue if there's interest in using
it in libstdc++. I'd like to use it for stdₓ::simd. Would you accept such a
patch? I guess using unicode in the alias name would not be acceptable,
though?
From: Matthias Kretz <kretz@kde.org>
This attribute overrides the diagnostics output string for the entity it
appertains to. The motivation is to improve QoI for library TS
implementations, where diagnostics have a very bad signal-to-noise ratio
due to the long namespaces involved.
gcc/ChangeLog:
* doc/invoke.texi: Document -fno-diagnostics-use-aliases.
gcc/c-family/ChangeLog:
* c.opt (fdiagnostics-use-aliases): New diagnostics flag.
gcc/cp/ChangeLog:
* error.c (dump_scope): When printing the name of a namespace,
look for the diagnose_as attribute. If found, print the
associated string instead of calling dump_decl.
(dump_aggr_type): If the type has a diagnose_as attribute, print
the associated string instead of printing the original type
name.
* name-lookup.c (handle_namespace_attrs): Handle the diagnose_as
attribute. Ensure exactly one string argument. Ensure previous
diagnose_as attributes used the same name.
* tree.c (cxx_attribute_table): Add diagnose_as attribute to the
table.
(check_diagnose_as_redeclaration): New function; copied and
adjusted from check_abi_tag_redeclaration.
(handle_diagnose_as_attribute): New function; copied and
adjusted from handle_abi_tag_attribute.
---
gcc/c-family/c.opt | 4 ++
gcc/cp/error.c | 19 +++++++-
gcc/cp/name-lookup.c | 27 ++++++++++
gcc/cp/tree.c | 114 +++++++++++++++++++++++++++++++++++++++++++
gcc/doc/invoke.texi | 9 +++-
5 files changed, 170 insertions(+), 3 deletions(-)
--
──────────────────────────────────────────────────────────────────────────
Dr. Matthias Kretz https://mattkretz.github.io
GSI Helmholtz Centre for Heavy Ion Research https://gsi.de
std::experimental::simd https://github.com/VcDevel/std-simd
──────────────────────────────────────────────────────────────────────────
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-gnu-diagnose_as-attribute.patch
Type: text/x-patch
Size: 8444 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20210423/b95cb7d3/attachment-0001.bin>
More information about the Libstdc++
mailing list