Skip to content

Imports in meta information #339

@thekid

Description

@thekid

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions