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

Imports in meta information #339

Open
thekid opened this issue Jan 17, 2021 · 1 comment
Open

Imports in meta information #339

thekid opened this issue Jan 17, 2021 · 1 comment

Comments

@thekid
Copy link
Member

thekid commented Jan 17, 2021

Scope of Change

This RFC suggests storing imports in xp::$meta.

Rationale

Faster access when resolving names - instead of having to parse the code again, we can simply reuse what lang.reflect.ClassParser (or the XP Compiler) have already extracted and put there there. Imports are used when resolving types inside apidoc and inside eval keys for annotations.

Functionality

Imports will be stored under a key named "use" (matching the use statement). It contains a map of aliases to qualified names.

Example

namespace org\example;

use util\Date;
use lang\Primitive as P;
use org\example\nodes\{Node, Variable as Var};

class T { ... }

This will produce the following:

xp::$meta['org.example.T']['use']= [
  'Date' => 'util\Date',
  'P'    => 'lang\Primitive',
  'Node' => 'org\example\nodes\Node',
  'Var'  => 'org\example\nodes\Variable',
];

Security considerations

None

Speed impact

Slightly slower

Dependencies

XP Compiler may optionally be extended to track imports, speeding up reflective access. Currently, it emits use statements which can then later on be tokenized again.

Related documents

@thekid
Copy link
Member Author

thekid commented Jan 17, 2021

Should there be a public method like XPClass::usedTypes() or XPClass::containingScope() to abstract this or can we leave this as an "internal" API?

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

No branches or pull requests

1 participant