From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lxmtout1.gsi.de (lxmtout1.gsi.de [140.181.3.111]) by sourceware.org (Postfix) with ESMTPS id 68BDA393C85B for ; Fri, 23 Apr 2021 15:17:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 68BDA393C85B Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gsi.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=M.Kretz@gsi.de Received: from localhost (localhost [127.0.0.1]) by lxmtout1.gsi.de (Postfix) with ESMTP id 8ED852050D05 for ; Fri, 23 Apr 2021 17:16:58 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at lxmtout1.gsi.de Received: from lxmtout1.gsi.de ([127.0.0.1]) by localhost (lxmtout1.gsi.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id TSptjb3Y-n_m for ; Fri, 23 Apr 2021 17:16:58 +0200 (CEST) Received: from srvex1.campus.gsi.de (srvex1.campus.gsi.de [10.10.4.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by lxmtout1.gsi.de (Postfix) with ESMTPS id 73CE62050D02 for ; Fri, 23 Apr 2021 17:16:58 +0200 (CEST) Received: from excalibur.localnet (140.181.3.12) by srvex1.campus.gsi.de (10.10.4.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.4; Fri, 23 Apr 2021 17:16:58 +0200 From: Matthias Kretz To: Subject: [RFC] Add gnu::diagnose_as attribute Date: Fri, 23 Apr 2021 17:16:57 +0200 Message-ID: <14205410.xuKvIAzr1H@excalibur> Organization: GSI Helmholtzzentrum =?UTF-8?B?ZsO8cg==?= Schwerionenforschung MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart6135280.3DG4uv3sP2" Content-Transfer-Encoding: 7Bit X-Originating-IP: [140.181.3.12] X-ClientProxiedBy: SRVEX2.campus.gsi.de (10.10.4.15) To srvex1.campus.gsi.de (10.10.4.11) X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 23 Apr 2021 15:17:03 -0000 --nextPart6135280.3DG4uv3sP2 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" Hi, before requesting comments on the implementation of this patch, I'd like to= =20 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= =20 implementations and potentially implementation-internal types. I've been using the diagnose_as attribute on my parallelism_v2 simd=20 implementation for two months now, and it significantly improved my=20 productivity. Like this: namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION namespace experimental=20 { inline namespace parallelism_v2 [[__gnu__::__diagnose_as__("std=E2=82= =93")]]=20 { namespace simd_abi [[__gnu__::__diagnose_as__("simd_abi")]] { struct [[__gnu__::__diagnose_as__("scalar")]] _Scalar; using scalar =3D _Scalar; template struct [[__gnu__::__diagnose_as__("fixed_size")]] _Fixed; template using fixed_size =3D _Fixed<_Np>; [...] Effects: 1. __PRETTY_FUNCTION__ in my test output: PASS: void invoke_test(int) [with V =3D std=E2=82=93::simd >; =3D std=E2=82=93::sim= d >] instead of=20 =20 PASS: void invoke_test(int) [with V =3D=20 std::experimental::parallelism_v2::simd >; =3D std::experimental::parallelism_v2::simd >] 2. Error messages: required from 'static constexpr std=E2=82=93::_SimdWrapper<_Tp, _Np>=20 std=E2=82=93::_SimdImplBuiltin<_Abi, =20 >::_S_fma(std=E2=82=93::_SimdWrapper<_Tp, _Np>, std=E2=82=93::_SimdWrapper<= _Tp, _Np>,=20 std=E2=82=93::_SimdWrapper<_Tp, _Np>) [with _Tp =3D double; long unsigned i= nt _Np =3D 2;=20 _Abi =3D simd_abi::_VecBuiltin<16>; =3D=20 std=E2=82=93::__detail::_MachineFlagsTemplate<31, 9>]' instead of required from 'static constexpr=20 std::experimental::parallelism_v2::_SimdWrapper<_Tp, _Np>=20 std::experimental::parallelism_v2::_SimdImplBuiltin<_Abi, >::_S_fma(std::experimental::parallelism_v2::_SimdWrapper<_T= p,=20 _Np>, std::experimental::parallelism_v2::_SimdWrapper<_Tp, _Np>,=20 std::experimental::parallelism_v2::_SimdWrapper<_Tp, _Np>) [with _Tp =3D do= uble;=20 long unsigned int _Np =3D 2; _Abi =3D=20 std::experimental::parallelism_v2::simd_abi::_VecBuiltin<16>; =3D=20 std::experimental::parallelism_v2::__detail::_MachineFlagsTemplate<31, 9>]' Since the main user of the attribute would be the standard library (I=20 believe), this patch only makes sense to pursue if there's interest in usin= g=20 it in libstdc++. I'd like to use it for std=E2=82=93::simd. Would you accep= t such a=20 patch? I guess using unicode in the alias name would not be acceptable,=20 though? =46rom: Matthias Kretz 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. =2D-- 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(-) =2D- =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80 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 =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80= =E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2= =94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94= =80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80=E2=94=80 --nextPart6135280.3DG4uv3sP2 Content-Disposition: inline; filename="0001-Add-gnu-diagnose_as-attribute.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="0001-Add-gnu-diagnose_as-attribute.patch" diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt index 3f8b72cdc00..0cf01c6dba4 100644 --- a/gcc/c-family/c.opt +++ b/gcc/c-family/c.opt @@ -1582,6 +1582,10 @@ fdiagnostics-show-template-tree C++ ObjC++ Var(flag_diagnostics_show_template_tree) Init(0) Print hierarchical comparisons when template types are mismatched. +fdiagnostics-use-aliases +C++ Var(flag_diagnostics_use_aliases) Init(1) +Replace identifiers or scope names in diagnostics as defined by the diagnose_as attribute. + fdirectives-only C ObjC C++ ObjC++ Preprocess directives only. diff --git a/gcc/cp/error.c b/gcc/cp/error.c index c88d1749a0f..8526bb9cb35 100644 --- a/gcc/cp/error.c +++ b/gcc/cp/error.c @@ -35,6 +35,7 @@ along with GCC; see the file COPYING3. If not see #include "internal-fn.h" #include "gcc-rich-location.h" #include "cp-name-hint.h" +#include "attribs.h" #define pp_separate_with_comma(PP) pp_cxx_separate_with (PP, ',') #define pp_separate_with_semicolon(PP) pp_cxx_separate_with (PP, ';') @@ -231,7 +232,15 @@ dump_scope (cxx_pretty_printer *pp, tree scope, int flags) { if (scope != global_namespace) { - dump_decl (pp, scope, f); + tree diagnose_as + = flag_diagnostics_use_aliases + ? lookup_attribute ("diagnose_as", DECL_ATTRIBUTES (scope)) + : NULL_TREE; + if (diagnose_as) + pp_cxx_ws_string ( + pp, TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (diagnose_as)))); + else + dump_decl (pp, scope, f); pp_cxx_colon_colon (pp); } } @@ -781,7 +790,13 @@ dump_aggr_type (cxx_pretty_printer *pp, tree t, int flags) } } - if (LAMBDA_TYPE_P (t)) + tree attr = flag_diagnostics_use_aliases + ? lookup_attribute ("diagnose_as", + TYPE_ATTRIBUTES (TREE_TYPE (decl))) + : NULL_TREE; + if (attr) + pp_cxx_ws_string (pp, TREE_STRING_POINTER (TREE_VALUE (TREE_VALUE (attr)))); + else if (LAMBDA_TYPE_P (t)) { /* A lambda's "type" is essentially its signature. */ pp_string (pp, M_("