Skip to content

php-in-php: JIT EnumCasesHelper — route Enum::cases() LLVM through VmEnum PHP not inline HashTable glue (#1492) #10395

Description

@PurHur

Category

php-in-php · shrink LLVM · php-src-strict

Problem

Synthetic Enum::cases() lowering lives in lib/JIT/EnumCasesHelper.php with inline HashTableHelper::alloc + per-case LLVM stores (#3308, #4068). VM enum case lists are already specified in lib/VM/EnumSupport.php / BackedEnumFromJit territory (#10273), but EnumCasesHelper still duplicates ordering/materialization in JIT-only glue.

Route JIT/AOT through VmEnum::casesList() (or shared PHP helper) with thin ABI — same strategy as #10273 BackedEnumFromJit.

php-src reference

Repro (drift guard)

<?php
enum Color: string { case Red = 'r'; case Green = 'g'; case Blue = 'b'; }
$cases = Color::cases();
echo count($cases), ':', $cases[0]->name, ':', $cases[2]->name, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "enum Color: string { case Red=\"r\"; case Green=\"g\"; case Blue=\"b\"; } \$c=Color::cases(); echo count(\$c),\":\",\$c[0]->name,\":\",\$c[2]->name,PHP_EOL;"
php bin/vm.php -r "enum Color: string { case Red=\"r\"; case Green=\"g\"; case Blue=\"b\"; } \$c=Color::cases(); echo count(\$c),\":\",\$c[0]->name,\":\",\$c[2]->name,PHP_EOL;"
php bin/jit.php -r "enum Color: string { case Red=\"r\"; case Green=\"g\"; case Blue=\"b\"; } \$c=Color::cases(); echo count(\$c),\":\",\$c[0]->name,\":\",\$c[2]->name,PHP_EOL;" 2>/dev/null || true
'
Check VM/JIT must match
Count 3
Order declaration order (Red … Blue)
Case type enum case objects, not backing scalars

Scope (this repo)

Path Work
lib/VM/EnumSupport.php SSOT casesForClass() callable from JIT
lib/JIT/EnumCasesHelper.php shrink to trampoline
lib/JIT/BackedEnumFromJit.php share case materialization with #10273
Tests test/compliance/cases/language/enum_cases.phpt

Done when

  • Repro green on VM and JIT with identical case objects
  • EnumCasesHelper.php no longer duplicates enum order logic from VM
  • PR notes lines removed from JIT enum glue
  • ./script/ci-fast.sh --filter enum_cases green

Related

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 / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions