Reimplementing the bulk of std.meta iteratively

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sun Sep 27 02:38:46 UTC 2020


On 9/26/20 10:30 PM, Steven Schveighoffer wrote:
> On 9/26/20 6:48 PM, Andrei Alexandrescu wrote:
>> A possibly angle here is to save that information in runtime format, 
>> i.e. reify the inheritance/convertibility relationship.
> 
> thinking it through...
> 
> All basic types have well-defined relationships that can be figured out 
> using a big statically generated switch thing.
> 
> Enums can be converted to their bases, and whatever they can convert to.

*nod*

> Structs can be converted to their alias-this parameter.

*nod* but how is that detectable for a given type T?

> Classes can also have an alias this, AND a set of base types.

yes... https://gist.github.com/andralex/0d85df38be2d9ffbe89cf1fb51c44213 
has the base classes part as a proof of concept (no interfaces and no 
alias this).

> Arrays and pointers can convert in certain cases to base types.

*nod* these would be detectable with relative eash

> And, multiply all this by mutability changes (convert to const for 
> things with references, and convert to anything for value types).
> 
> So for each type, you could generate a list of types that it can convert 
> to. Then on each comparison, search for the target type in the list, and 
> if you find it, return true.
> 
> I can't imagine this is going to be efficient.

In the words of a guy I heard at a panel: "I'm not sure I understood 
what the problem is, but it seems the solution is a hashtable". :o)

> We might be able to 
> factor out the const changes. But it still leaves a big list of things. 
> Honestly, I don't know if the compiler does it in a more efficient way 
> than searching through a list.
> 
> So it's definitely doable, I just don't know if we would want to do it, 
> or if the complication of the resulting code is worth it. is(a : b) is 
> just soooo much easier! And I think this is one aspect that type 
> functions allow.

It's part of the introspection game: gather the information typically 
present in the innards of the compiler, in programmatically-available 
form. I mean you would expect to grab access to implicit conversion 
targets in a language that has introspection.

> If there were a way to go back to type-land in the middle of 
> runtime-at-ctfe-land, even if you had to define it in a restrictive way, 
> then it might be much more palatable.

I'd be very interested too! (My experience with reification is now 
measured in hours.) This is the kind of stuff Timon would know.



More information about the Digitalmars-d mailing list