core icon indicating copy to clipboard operation
core copied to clipboard

Remove reflection from XP Core

Open thekid opened this issue 2 years ago • 2 comments

This pull request implements https://github.com/xp-framework/rfc/issues/338 and removes reflection from XP Core.

Continuous disintegration

  • [x] Access members (properties, methods, constants) via lang.XPClass
  • [x] Member encapsulations in lang.reflect
  • [x] Proxy and InvocationHandler classes from lang.reflect
  • [x] Annotation API in lang.XPClass
  • [x] Class details API for members
  • [ ] Dependency of lang.FunctionType on class details API
  • [ ] Remove class parser

Size

Before:

$ du -ksh src/*/php
831K    src/main/php
1019K   src/test/php

After:

$ du -ksh src/*/php
774K    src/main/php
915K    src/test/php

thekid avatar Jun 25 '23 19:06 thekid

Generics use annotations, which means we have the following options:

  1. Drop generics support (see also https://github.com/xp-framework/rfc/issues/338#issuecomment-774665621)
  2. Rewrite generics support to use PHP 8 attributes via reflection, and drop PHP 7 support (see also https://github.com/xp-framework/rfc/issues/343)
  3. Same as 2) - but create a simple annotation parser for PHP 7 which is loaded only on demand.
  4. It might be possible to fold class parser and generics creation into a single-step process

thekid avatar Jun 25 '23 19:06 thekid

Dependency of lang.FunctionType on class details API

For this to work, we need to be able to parse API doc types in FunctionType::verify(). This has the following 2 prerequisites:

  • Type::named() is more liberal about trailing comments, so we're able to parse @return self This instance. See handling in lang.reflect.ClassParser::typeIn()
  • We are somehow able to parse use statements to be able to resolve imports correctly. We already need this for running scripts, see xp.runtime.Code, the code there could be integrated with a slight refactoring.

thekid avatar Jun 27 '23 18:06 thekid