Date: Sat, 15 Jan 2022 21:00:44 +0100
On Sat, Jan 15, 2022 at 8:56 PM Matus Chochlik <chochlik_at_[hidden]> wrote:
> Hi David,
>
> On Sat, Jan 15, 2022 at 8:45 PM David Rector via SG7 <sg7_at_[hidden]>
> wrote:
>
>>
>> Now suppose a user decides they want to interface with reflection in an
>> object-oriented style:
>> ```
>> template<auto R>
>> struct DeclWrapper {
>> auto nextDecl() { return
>> DeclWrapper <decltype(std::meta::get_next_decl(R))>{}; }
>> auto prevDecl() {…}
>> auto getParent() { … }
>> …
>> };
>>
>> #include … // lots of stuff, big translation unit
>>
>> int foo;
>> constexpr auto foorefl = DeclWrapper <decltype(^foo)>()>();
>> ```
>>
>> What happens when `foorefl` is instantiated?
>>
>> First each member of DeclWrapper<decltype(^foo)> must be instantiated,
>> which means we have to instantiate each return type, each of which is a
>> DeclWrapper, which itself has to be instantiated, …
>>
>> The chain reaction results in instantiations of DeclWrappers for *every
>> single declaration in the translation unit*.
>>
>
> I have actually done something like that here:
>
> https://github.com/matus-chochlik/mirror/blob/develop/include/mirror/metadata.hpp
> and
>
> https://github.com/matus-chochlik/mirror/blob/develop/include/mirror/registry.hpp
>
> for debugging, in order to have a way to easily force the extraction of
> all metadata and also to see the performance of such "chain reaction".
>
To clarify a little more, in my implementation you will not get the
reflection of everything in the TU, the cascade is intentionally stopped to
prevent really excessive compile-times.
> Hi David,
>
> On Sat, Jan 15, 2022 at 8:45 PM David Rector via SG7 <sg7_at_[hidden]>
> wrote:
>
>>
>> Now suppose a user decides they want to interface with reflection in an
>> object-oriented style:
>> ```
>> template<auto R>
>> struct DeclWrapper {
>> auto nextDecl() { return
>> DeclWrapper <decltype(std::meta::get_next_decl(R))>{}; }
>> auto prevDecl() {…}
>> auto getParent() { … }
>> …
>> };
>>
>> #include … // lots of stuff, big translation unit
>>
>> int foo;
>> constexpr auto foorefl = DeclWrapper <decltype(^foo)>()>();
>> ```
>>
>> What happens when `foorefl` is instantiated?
>>
>> First each member of DeclWrapper<decltype(^foo)> must be instantiated,
>> which means we have to instantiate each return type, each of which is a
>> DeclWrapper, which itself has to be instantiated, …
>>
>> The chain reaction results in instantiations of DeclWrappers for *every
>> single declaration in the translation unit*.
>>
>
> I have actually done something like that here:
>
> https://github.com/matus-chochlik/mirror/blob/develop/include/mirror/metadata.hpp
> and
>
> https://github.com/matus-chochlik/mirror/blob/develop/include/mirror/registry.hpp
>
> for debugging, in order to have a way to easily force the extraction of
> all metadata and also to see the performance of such "chain reaction".
>
To clarify a little more, in my implementation you will not get the
reflection of everything in the TU, the cascade is intentionally stopped to
prevent really excessive compile-times.
Received on 2022-01-15 20:00:55