[PATCH] Add gnu::diagnose_as attribute
Matthias Kretz
m.kretz@gsi.de
Tue Jun 15 20:56:20 GMT 2021
On Tuesday, 15 June 2021 17:51:20 CEST Jason Merrill wrote:
> On 6/11/21 6:01 AM, Matthias Kretz wrote:
> > For reference I'll attach my stdx::simd diagnose_as patch.
> >
> > We could also talk about extending the feature to provide more information
> > about the diagnose_as substition. E.g. print a list of all diagnose_as
> > substitutions, which were used, at the end of the output stream. Or
> > simpler, print "note: some identifiers were simplified, use
> > -fno-diagnostics-use- aliases to see their real names".
>
> Or perhaps before the first use of a name that doesn't correspond to a
> source-level name.
Right. I guess that would be even easier to implement than printing it at the
end.
> > -struct _Scalar;
> > + struct [[__gnu__::__diagnose_as__("scalar")]] _Scalar;
> >
> > template <int _Np>
> >
> > - struct _Fixed;
> > + struct [[__gnu__::__diagnose_as__("fixed_size")]] _Fixed;
>
> Thes two could be the variant of the attribute without an explicit
> string, attached to the alias-declaration.
Agreed. (since you don't have implementation concerns...)
> > +using __sse [[__gnu__::__diagnose_as__("[SSE]")]] = _VecBuiltin<16>;
> > +using __avx [[__gnu__::__diagnose_as__("[AVX]")]] = _VecBuiltin<32>;
> > +using __avx512 [[__gnu__::__diagnose_as__("[AVX512]")]] =
> > _VecBltnBtmsk<64>; + using __odr_helper [[__gnu__::__diagnose_as__("[ODR
> > helper]")]]
> These [] names seem like minimal improvements over the __ names that you
> would get from the attribute without an explicit string.
Right. It would, however, give the user an identifier that I don't want them
to use in their code. We could argue "it has a double-underscore and it's not
a documented implementation-defined type, so you're shooting yourself in the
foot". Or we could just avoid the issue altogether. I agree this is not a huge
issue.
> > + inline namespace parallelism_v2
> > [[__gnu__::__diagnose_as__("std\u2093")]] {
> This could go on std::experimental itself, along with my proposed change
> to hide inline namespaces by default (with a note similar to the one above).
Yes, with the following consequences:
* If only the std::experimental::parallelism_v2::simd headers set the
diagnose_as attribute on std::experimental, the #inclusion of <experimental/
simd> changes the diagnostics of all other TS implementations.
* If all TS implementations set the diagnose_as attribute, then it's basically
impossible to go back to the long and scary name. Which is what we really
should do as soon as there's both a std::simd and a stdₓ::simd. Attaching the
diagnose_as attribute to the inline namespace allows for better granularity,
even if it's maybe not good enough for some TSs.
* If `namespace std { namespace experimental [[gnu::diagnose_as("foo")]] {`
turns the scope into 'foo::' and not 'std::foo::' (not sure what you intended)
then I could still attach the attribute to the inline namespace.
So, yes, I could improve stdx::simd with what you propose. IMHO it wouldn't be
as good as what I can do with the patch at hand, though.
IIUC, your main concern is that my proposed diagnose_as *can* be used to make
diagnostics worse, by replacing names with strings that are not valid
identifiers. Of course, whoever uses the attribute to that effect should have
a good reason to do so. Is your other concern that using the attribute in a
"good" way is repetitive? Would you be happier if I make the string argument
to the attribute optional for type aliases?
--
──────────────────────────────────────────────────────────────────────────
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
──────────────────────────────────────────────────────────────────────────
More information about the Libstdc++
mailing list