Date: Wed, 1 Dec 2021 22:17:16 +0200
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-
> explorer.com/z/TrYEYhqMK
>
> And find source code here: 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've been playing with Matus's implementation on CE, trying to see if I can
implement the Boost.Describe primitives with it. As a quick summary, Describe
has describe_enumerators<E>, describe_bases<T> and describe_members<T>,
and these return a descriptor type list, L<D1, D2, ..., Dn>, where each Di is
a struct with static constexpr members describing the element (an enumerator
in the first case, a base class in the second, a member in the third.)
Describe is, err, described at
https://www.boost.org/doc/libs/master/libs/describe/doc/html/describe.html
and the format in which it returns the reflection metadata is optimized for
usability, as simple cases typically require no more than an `mp_for_each` loop
(the Mp11 equivalent of `template for`.)
You can see examples of use here
https://www.boost.org/doc/libs/master/libs/describe/doc/html/describe.html#examples
Ordinarily, to be able to return the reflection metadata, Describe relies on macros
with which the user describes the types - BOOST_DESCRIBE_ENUM,
BOOST_DESCRIBE_STRUCT, BOOST_DESCRIBE_CLASS.
Using Matus's TS implementation, these macros are no longer necessary. Here,
for example, is how we can rig describe_enumerators to work without
BOOST_DESCRIBE_ENUM: https://compiler-explorer.com/z/4Mjx7j43a
Here is an example of describe_bases: https://compiler-explorer.com/z/xfvz9njhY
And here's a preliminary example of describe_members:
https://compiler-explorer.com/z/fYcxbx1j7
Needless to say, I'm very excited about this. If only we could get that into the
compilers tomorrow, C++ programmers would be able to do a lot of
reflectionary things. (Describe might seem limited compared to the full scope of
what's usually expected of reflection, but it in fact covers a lot of the problems
real-world programmers face.)
I know that we're supposed to not use type-based things anymore, but they are
here, and they work.
> 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-
> explorer.com/z/TrYEYhqMK
>
> And find source code here: 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've been playing with Matus's implementation on CE, trying to see if I can
implement the Boost.Describe primitives with it. As a quick summary, Describe
has describe_enumerators<E>, describe_bases<T> and describe_members<T>,
and these return a descriptor type list, L<D1, D2, ..., Dn>, where each Di is
a struct with static constexpr members describing the element (an enumerator
in the first case, a base class in the second, a member in the third.)
Describe is, err, described at
https://www.boost.org/doc/libs/master/libs/describe/doc/html/describe.html
and the format in which it returns the reflection metadata is optimized for
usability, as simple cases typically require no more than an `mp_for_each` loop
(the Mp11 equivalent of `template for`.)
You can see examples of use here
https://www.boost.org/doc/libs/master/libs/describe/doc/html/describe.html#examples
Ordinarily, to be able to return the reflection metadata, Describe relies on macros
with which the user describes the types - BOOST_DESCRIBE_ENUM,
BOOST_DESCRIBE_STRUCT, BOOST_DESCRIBE_CLASS.
Using Matus's TS implementation, these macros are no longer necessary. Here,
for example, is how we can rig describe_enumerators to work without
BOOST_DESCRIBE_ENUM: https://compiler-explorer.com/z/4Mjx7j43a
Here is an example of describe_bases: https://compiler-explorer.com/z/xfvz9njhY
And here's a preliminary example of describe_members:
https://compiler-explorer.com/z/fYcxbx1j7
Needless to say, I'm very excited about this. If only we could get that into the
compilers tomorrow, C++ programmers would be able to do a lot of
reflectionary things. (Describe might seem limited compared to the full scope of
what's usually expected of reflection, but it in fact covers a lot of the problems
real-world programmers face.)
I know that we're supposed to not use type-based things anymore, but they are
here, and they work.
Received on 2021-12-01 14:17:20