C++ Logo

sg7

Advanced search

Re: [SG7] TS Reflection experimental implementation in Clang available

From: David Rector <davrec_at_[hidden]>
Date: Thu, 2 Dec 2021 10:37:39 -0500
Hi Matus,

Thanks for your efforts, this sort of project requires an extraordinary amount of work.

I have not played around sufficiently with the implementation, but let’s talk about its role vis a vis Andrew et al’s proposed reflection features, under the assumption that this is/can be easily made bug-free and properly implements the Reflection TS.
(This assumption seems reasonable because, IIUC, this implementation expects the user to rely on existing template metaprogramming techniques to iterate over members, expressed as template argument packs, whereas `template for` etc. iteration techniques seems to be one of the most frustratingly difficult and buggy features to implement, particularly for type-based reflection. Correct me if I’m wrong, and describe any novel iteration features you introduce.)

The language keywords you introduce are these: https://github.com/matus-chochlik/llvm-project/blob/reflection/clang/include/clang/Basic/TokenKinds.def#L425 <https://github.com/matus-chochlik/llvm-project/blob/reflection/clang/include/clang/Basic/TokenKinds.def>.
It seems all, with the exception of `reflexpr()` (which could be easily changed to `^`), are prefixed by double underscore.
Do I understand correctly that this means the user does not *ever* need to directly use the double-underscored keywords — that they are private to the Reflection TS implementation accessed via `#include <experimental/reflect>`?

If not, please list any other keywords beyond `reflexpr` with which the user is expected to interface directly.
In particular please discuss any that differ fundamentally from the primitives introduced by Andrew et al.
Also, if there are any components of <experimental/reflect> that go beyond what the ReflectionTS specifies, please list/motivate them.

It seems to me that, given the premises that
1. everyone agrees on a few basic primitives like ^ and whatever other basic interface this implementation requires,
2. we have a ReflectionTS that at some point was an agreed-upon reflection interface (even if not the most efficient/user-friendly),
3. Matus’s implementation of the Reflection TS is solid, and
4. the status and completion time for the official reflection features is very uncertain,
this would be a very useful placeholder reflection implementation, worthy of being upstreamed to clang, to allow users to experiment with reflection and give viable feedback to guide the efforts of Andrew et al.

The eventual official reflection implementation could simply wipe out the double-underscored language keywords and implement <experimental/reflect> in terms of the official language keywords.

Perhaps we can all first discuss this a bit and clear up any confusions.

Then, Matus if you believe your implementation is indeed ready for prime time or nearly so, I think the next step would be to a) ask Andrew et al to weigh in on whether such a "placeholder implementation" would indeed help their efforts (and if not, why), b) cc Richard to get his thoughts on the viability of upstreaming this to clang.

Dave

> On Dec 2, 2021, at 1:00 AM, Matus Chochlik via SG7 <sg7_at_[hidden]> wrote:
>
> Hi,
>
> Some of the possible enum-to-string and string-to-enum implementations:
>
> https://compiler-explorer.com/z/Mdsrn6z3x <https://compiler-explorer.com/z/Mdsrn6z3x>
> https://compiler-explorer.com/z/PK5bY9q56 <https://compiler-explorer.com/z/PK5bY9q56>
>
> https://compiler-explorer.com/z/5bEab1Pxa <https://compiler-explorer.com/z/5bEab1Pxa>
>
>
>
>
> On Wed, Dec 1, 2021 at 9:41 PM Matus Chochlik <chochlik_at_[hidden] <mailto:chochlik_at_[hidden]>> wrote:
>
>
> On Wed, Dec 1, 2021 at 9:17 PM Peter Dimov via SG7 <sg7_at_[hidden] <mailto:sg7_at_[hidden]>> wrote:
> Hana Dusíková wrote:
> > Hi,
> >
> > I'm really happy that I can announce our own Matus Chochlik implemented TS
> > Reflection in his fork of Clang.
> >
> > You can experiment with it at Compiler Explorer: https://compiler- <https://compiler-/>
> > explorer.com/z/TrYEYhqMK <http://explorer.com/z/TrYEYhqMK>
> >
> > And find source code here: https://github.com/matus-chochlik/llvm-project <https://github.com/matus-chochlik/llvm-project>
> >
> > Any feedback and bug report is welcome, I think Matus hopes for upstreaming
> > it soon.
> >
> > Thanks Matus for awesome work! ❤️
>
> Seconded.
>
> I would like to thank Peter for all the useful feedback that helped a lot with the debugging!
> --
> SG7 mailing list
> SG7_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/sg7


Received on 2021-12-02 09:37:43