Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove reflection from XP Core #332

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

thekid
Copy link
Member

@thekid thekid commented Jun 25, 2023

This pull request implements xp-framework/rfc#338 and removes reflection from XP Core.

Continuous disintegration

  • Access members (properties, methods, constants) via lang.XPClass
  • Member encapsulations in lang.reflect
  • Proxy and InvocationHandler classes from lang.reflect
  • Annotation API in lang.XPClass
  • 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
Copy link
Member Author

thekid commented Jun 25, 2023

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

  1. Drop generics support (see also Extract reflection to its own library rfc#338 (comment))
  2. Rewrite generics support to use PHP 8 attributes via reflection, and drop PHP 7 support (see also Drop PHP 7 support rfc#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 thekid added the rfc label Jun 25, 2023
thekid added a commit to xp-framework/reflection that referenced this pull request Jun 25, 2023
@thekid
Copy link
Member Author

thekid commented Jun 27, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant