> On Aug 19, 2024, at 7:37 PM, Rob Landers <rob@bottled.codes> wrote:
> As an experiment, awhile ago, I went a different route for reified generics 
> by 'hacking' type aliases (which I was also experimenting with). Such that a 
> generic becomes compiled into a concrete implementation with a dangling type 
> alias:
> 
> class Box<T> {
>   function __construct(T $thing) {}
> }
> 
> is essentially compiled to
> 
> class Box {
>   use alias __Box_T => ???;
> 
>   function __construct(__Box_T $thing) {}
> }
> 
> This just gets a T type alias (empty-ish, with a mangled name) that gets 
> filled in during runtime (every instance gets its own type alias table, and 
> uses that along with the file alias table). There shouldn't be any 
> performance impact this way (or at least, as bad as using type aliases, in 
> general; which is also an oft-requested feature).

From what I understand this is essentially how Go implements Generics.  So +1 
for considering this approach.

> FYI though, people seemed really turned off by file-level type aliases (at 
> least exposed to user-land, so I never actually pursued it).

Shame. Type aliases are super useful in practice in other languages, with many 
used for single-file scope in my experience.

-Mike

Reply via email to