IFTI reflection would be nice

Manu turkeyman at gmail.com
Thu Jul 30 01:51:18 UTC 2020


On Sun, Jul 26, 2020 at 11:25 PM Adam D. Ruppe via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> Another useful thing to have would be "given this argument set to
> a function, give me the function that would be called".
>
> This would do implicit function template instantiation and
> overload resolution, but yield the function instead of the return
> value.
>
> Imagine:
>
> void foo(int a) {}
> void foo(string b) {}
>
>
> I want to get the address of foo(string). How do you do that
> right now? Well, you have to loop over overloads and check the
> types. What a pain, but at least doable.
>
> But wouldn't it be cool if you could do
>
> &__functionOf(foo("foo"))
>
> Where the __functionOf is the magic.
>
>
> So far, this is kinda just a convenience, but now imagine the
> case of a template. Even if template reflection worked, you'd
> need to figure out the template arguments and that can be
> basically impossible given the conversions and specializations.
>
> Then
>
> &__functionOf(writeln("bar"))
>
> for example would give a void function(string). There you can do
> `&writeln!string`
>
>
> And in cases more complex than that, the compiler's logic need
> not be reimplemented in user cde.
>

Write a DIP! This is a very real reflection hole that I've struggled with
before too.
Trying to sample all the possibilities, and then mirror the complex logic
that the compiler uses to select a function to call internally is not a
problem that should exist in user-space, and the compiler rules are subject
to change making maintenance tricky and extremely brittle.

I'd suggest it might just be a __traits though, rather than introducing a
new magic thing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20200730/7ff9aa03/attachment.htm>


More information about the Digitalmars-d mailing list