Skip to content

Language: PHP 8 attributes reflection JIT/AOT (phase 2, post-#1354 VM) #2467

Description

@PurHur

Category

language

Problem

#1354 ✅ and #1936 ✅ delivered VM v1: attributes parse, compile-time metadata on TYPE_DECLARE_CLASS / TYPE_DECLARE_METHOD, and read-only reflection (ReflectionClass::getAttributes(), ReflectionAttribute::getName()).

docs/capabilities-syntax.md still marks attributes as JIT/AOT deferred. Native bin/jit.php / phpc build binaries used in self-host must expose the same metadata as VM or reflection returns empty arrays / stubs.

php-src reference

  • Zend/zend_compile.c — zend_compile_attributes, attachment to op_array / class_entry
  • Zend/zend_reflection.c — zim_ReflectionClass_getAttributes, ReflectionAttribute object creation
  • ext/reflection/php_reflection.c

Repro (today)

Save as test/compliance/cases/attribute_reflection_probe.php (or run inline):

<?php
#[\Attribute]
class Route {
    public function __construct(public string $path) {}
}

#[Route('/home')]
class Home {}

$r = new ReflectionClass(Home::class);
$attrs = $r->getAttributes();
echo count($attrs), "\n";
echo $attrs[0]->getName(), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "/* paste */"   # Zend: 1, Route
php bin/vm.php test/compliance/cases/attribute_reflection_probe.php 2>/dev/null || php bin/vm.php -r "..." 
php bin/jit.php -r "/* same */" 2>&1 | head -5
'

Expected Zend: 1 and Route (or fully qualified name). Gap: compare VM vs JIT vs AOT output; file fails if JIT/AOT prints 0 or fatals.

Scope (this repo)

Layer Files v1 target
Compiler lib/Compiler.php Serialize attribute class names + literal args into IR metadata
VM lib/VM.php, lib/VM/BuiltinClasses.php Already partial — extend if gaps found
JIT lib/JIT.php Emit const attribute tables into VMContext for reflection
AOT lib/AOT/ Link metadata section; bootstrap-readable
Tests test/compliance/cases/attribute_reflection_*.phpt VM + @group llvm JIT

Out of scope (v1)

Done when

  • VM compliance PHPT: getAttributes() count + getName() match Zend for class-level attribute
  • JIT compliance PHPT green when LLVM present (same output as VM)
  • AOT fixture executes reflection probe without empty attribute list
  • php script/capability-syntax.php — attributes row JIT/AOT = yes (read path)
  • php script/bootstrap-inventory.php --check clean or documented delta

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter attribute_reflection'
./script/ci-fast.sh --filter attribute_reflection

Dependencies

Links

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions