Hi Larry,
On Tue, Aug 20, 2024 at 3:32 AM Larry Garfield <[email protected]> wrote:
> > In fact, generic traits (essentially statically replacing the generic
> > arguments at link-time) would be an useful feature which would remain
> > useful even if we had fully reified generics.
> > I recognize that some functionality will need support of internal
> > zend_object_handlers. But that's not a blocker, we might provide some
> > default internal traits with PHP, enabling the internal class handlers.
> > So to summarize, I would not continue on that path, but really invest
> > into monomorphizable generic traits instead.
>
> Interesting. I have no idea why Arnaud has mainly been investigating reified generics rather
> than monomorphized, but a monomorphized trait has potential, I suppose. That naturally leads to the
> question of whether monomorphized interfaces would be possible, and I have no idea there. (I still
> hold out hope that Levi will take another swing at interface-default-methods.)
>
> Though this still wouldn't be a path to full generics, as you couldn't declare the
> inner type of an object at creation time, only code time. Still, it sounds like an area worth
> considering.
Monomorphization as a solution to generic classes has a memory usage
issue (it requires duplicating the class entry, methods, props, and
also opcodes if method bodies can reference type parameters), and does
not solve all the complexity:
https://github.com/PHPGenerics/php-generics-rfc/issues/44.
This would be less a problem for traits, as there is already some
amount of duplication.
Best Regards,
Arnaud