From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lxmtout2.gsi.de (lxmtout2.gsi.de [140.181.3.112]) by sourceware.org (Postfix) with ESMTPS id 3BD563853820; Thu, 27 May 2021 18:54:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3BD563853820 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 lxmtout2.gsi.de (Postfix) with ESMTP id C485F2038F79; Thu, 27 May 2021 20:54:14 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at lxmtout2.gsi.de Received: from lxmtout2.gsi.de ([127.0.0.1]) by localhost (lxmtout2.gsi.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id l7QDKr1yDDnr; Thu, 27 May 2021 20:54:14 +0200 (CEST) Received: from srvex3.campus.gsi.de (unknown [10.10.4.16]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by lxmtout2.gsi.de (Postfix) with ESMTPS id A8D51202AD60; Thu, 27 May 2021 20:54:14 +0200 (CEST) Received: from excalibur.localnet (140.181.3.12) by srvex3.campus.gsi.de (10.10.4.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.10; Thu, 27 May 2021 20:54:14 +0200 From: Matthias Kretz To: , Jason Merrill CC: Subject: Re: [PATCH] Add gnu::diagnose_as attribute Date: Thu, 27 May 2021 20:54:13 +0200 Message-ID: <3483026.uDumqb6SjM@excalibur> Organization: GSI Helmholtzzentrum =?UTF-8?B?ZsO8cg==?= Schwerionenforschung In-Reply-To: <05673834-4912-e418-43cc-2dfdd45aabdf@redhat.com> References: <14205410.xuKvIAzr1H@excalibur> <91863212.B8guWdUDZo@excalibur> <05673834-4912-e418-43cc-2dfdd45aabdf@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="UTF-8" X-Originating-IP: [140.181.3.12] X-ClientProxiedBy: srvex3.Campus.gsi.de (10.10.4.16) To srvex3.campus.gsi.de (10.10.4.16) X-Spam-Status: No, score=-4.8 required=5.0 tests=BAYES_00, BODY_8BITS, KAM_DMARC_STATUS, SPF_PASS, TXREP, T_SPF_HELO_PERMERROR, URIBL_SBL, URIBL_SBL_A autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 27 May 2021 18:54:18 -0000 On Thursday, 27 May 2021 19:39:48 CEST Jason Merrill wrote: > On 5/4/21 7:13 AM, Matthias Kretz wrote: > > From: Matthias Kretz > >=20 > > 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. > >=20 > > On Tuesday, 27 April 2021 11:46:48 CEST Jonathan Wakely wrote: > >> I think it's a great idea and would like to use it for all the TS > >> implementations where there is some inline namespace that the user > >> doesn't care about. std::experimental::fundamentals_v1:: would be much > >> better as just std::experimental::, or something like std::[LFTS]::. >=20 > Hmm, how much of the benefit could we get from a flag (probably on by > default) to skip inline namespaces in diagnostics? I'd say about 20% for the TS's. Even std::experimental::simd (i.e. without = the=20 '::parallelism_v2' part) is still rather noisy. I want std=E2=82=93::simd, = std-x::simd=20 or std::[PTS2]::simd or whatever shortest shorthand Jonathan will allow. ;) =46or PR89370, the benefit would be ~2%: 'template std::__cxx11::basic_string<_CharT, _Traits,=20 _Alloc>::_If_sv<_Tp, std::__cxx11::basic_string<_CharT, _Traits, _Alloc>&>= =20 std::__cxx11::basic_string<_CharT, _Traits,=20 _Alloc>::insert(std::__cxx11::basic_string<_CharT, _Traits,=20 _Alloc>::size_type, const _Tp&, std::__cxx11::basic_string<_CharT, _Traits,= =20 _Alloc>::size_type, std::__cxx11::basic_string<_CharT, _Traits,=20 _Alloc>::size_type) [with _Tp =3D _Tp; _CharT =3D char; _Traits =3D=20 std::char_traits; _Alloc =3D std::allocator]' would then only turn into: 'template std::basic_string<_CharT, _Traits,=20 _Alloc>::_If_sv<_Tp, std::basic_string<_CharT, _Traits, _Alloc>&>=20 std::basic_string<_CharT, _Traits,=20 _Alloc>::insert(std::basic_string<_CharT, _Traits,=20 _Alloc>::size_type, const _Tp&, std::basic_string<_CharT, _Traits,=20 _Alloc>::size_type, std::basic_string<_CharT, _Traits,=20 _Alloc>::size_type) [with _Tp =3D _Tp; _CharT =3D char; _Traits =3D=20 std::char_traits; _Alloc =3D std::allocator]' instead of: 'template std::string::_If_sv<_Tp, std::string&>=20 std::string::insert<_Tp>(std::string::size_type, const _Tp&,=20 std::string::size_type, std::string::size_type)' Also hiding all inline namespace by default might make some error messages= =20 harder to understand: namespace Vir { inline namespace foo { struct A {}; } struct A {}; } using Vir::A; :7:12: error: reference to 'A' is ambiguous :3:12: note: candidates are: 'struct Vir::A' :5:10: note: 'struct Vir::A' > > With the attribute, it is possible to solve PR89370 and make > > std::__cxx11::basic_string<_CharT, _Traits, _Alloc> appear as > > std::string in diagnostic output without extra hacks to recognize the > > type. >=20 > That sounds wrong to me; std::string is the instantiation, not > the template. Your patch doesn't make it possible to apply this > attribute to class template instantiations, does it? Yes, it does. Initially, when I tried to improve the TS experience, it didn't. When Jonat= han=20 showed PR89370 to me I tried to make [[gnu::diagnose_as]] more generic &=20 useful. Since there's no obvious syntax to apply an attribute to a template= =20 instantiation, I had to be creative. This is from my pending std::string=20 patch: =2D-- a/libstdc++-v3/include/bits/c++config +++ b/libstdc++-v3/include/bits/c++config @@ -299,7 +299,8 @@ namespace std #if _GLIBCXX_USE_CXX11_ABI namespace std { =2D inline namespace __cxx11 __attribute__((__abi_tag__ ("cxx11"))) { } + inline namespace __cxx11 + __attribute__((__abi_tag__ ("cxx11"), __diagnose_as__("std"))) { } } namespace __gnu_cxx { =2D-- a/libstdc++-v3/include/bits/stringfwd.h +++ b/libstdc++-v3/include/bits/stringfwd.h @@ -76,24 +76,24 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 _GLIBCXX_END_NAMESPACE_CXX11 =20 /// A string of @c char =2D typedef basic_string string; =20 + typedef basic_string string [[__gnu__::__diagnose_as__("string")]]; =20 #ifdef _GLIBCXX_USE_WCHAR_T /// A string of @c wchar_t =2D typedef basic_string wstring; =20 + typedef basic_string wstring [[__gnu__::__diagnose_as__("wstring")]]; #endif [...] The part of my frontend patch that makes this work is in=20 handle_diagnose_as_attribute: + if (TREE_CODE (*node) =3D=3D TYPE_DECL) + { + // Apply the attribute to the type alias itself. + decl =3D *node; + tree type =3D TREE_TYPE (*node); + if (CLASS_TYPE_P (type) && CLASSTYPE_TEMPLATE_INSTANTIATION (type)) + { + if (COMPLETE_OR_OPEN_TYPE_P (type)) + warning (OPT_Wattributes, + "ignoring %qE attribute applied to template %qT after " + "instantiation", name, type); + else + { + type =3D strip_typedefs(type, nullptr, 0); + // And apply the attribute to the specialization on the RHS. + tree attributes =3D tree_cons (name, args, NULL_TREE); + decl_attributes (&type, attributes, + ATTR_FLAG_TYPE_IN_PLACE, NULL_TREE); + } + } + } =2D-=20 =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