Skip to content

php-in-php: JIT HashTableHelper — route hashtable LLVM through VmHashTable PHP not ~2.6k-line monolith (#1492) #10031

Description

@PurHur

Category

php-in-php · compile/runtime shared

Problem

lib/JIT/HashTableHelper.php is a ~2.6k-line LLVM monolith that lowers PHP array/hash operations directly to hashtable pointer manipulation, type probes, and abort paths. The same semantics already exist (or should exist) on the VM side via PHPCompiler\VM\HashTable and array builtins in ext/standard/VmArray.php.

Per #1492 PHP-in-PHP strategy, hashtable behavior should live in PHP (lib/VM/, ext/) with JIT emitting thin trampolines to those helpers — not growing permanent C/LLVM tables.

Consumers today include lib/JIT/Builtin/DefineRuntime.php, lib/JIT/Builtin/Type/Object_.php, lib/JIT/Context.php, lib/JIT/ClassConstFetchHelper.php, and dozens of array builtin JIT paths.

php-src reference (semantics only)

Port semantics into PHP this repo owns; treat php-src C as reference, not a copy target.

Repro (baseline — no user-visible failure)

Migration is measured by LLVM line shrink + JIT/VM agreement on array/hash builtins:

wc -l lib/JIT/HashTableHelper.php   # ~2617 today
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
vendor/bin/phpunit --filter ArrayBuiltin
vendor/bin/phpunit --filter VMTest --filter array_
'

Pick one high-traffic slice first (e.g. setAtStringKey / alloc used by DefineRuntime).

Scope (this repo)

Path Work
lib/VM/HashTable.php Expand shared PHP helpers callable from JIT
ext/standard/VmArray.php Array mutation helpers reused by JIT
lib/JIT/HashTableHelper.php Shrink — delegate to PHP helpers via JIT trampoline
lib/JIT/Builtin/DefineRuntime.php First consumer migration
Tests Existing array compliance + JIT PHPT must stay green

Forbidden: new permanent logic in runtime/*.c or duplicate hash tables in LLVM when PHP path suffices.

Done when (v1 slice — claimable)

  • One documented consumer (DefineRuntime or ClassConstFetchHelper) routes through VmHashTable PHP helper
  • HashTableHelper.php line count reduced ≥200 lines with no compliance regression
  • PR body cites php-src zend_hash.c reference + PHP implementation path
  • ./script/ci-fast.sh --filter DefineRuntime / array builtin subset green

Related

Activity

  1. added
    phase-4:stdlibPhase 4 – stdlib for web apps
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 19, 2026
  2. PurHur commented on Jun 26, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — batch (issues #10031, #9663) — HashTableHelper v1 slice: DefineRuntime + write LLVM split.

  3. PurHur commented on Jun 26, 2026

    @PurHur
    OwnerAuthor

    Merged via #11995.

    Verification:

    wc -l lib/JIT/HashTableHelper.php  # 2051 (−602 from ~2653)
    vendor/bin/phpunit --filter HashTableHelperShrinkTest|DefineRuntimeShrink  # 9 tests OK
    make bootstrap-selfhost-vm-driver-execute-probe  # OK
    
  4. PurHur commented on Jun 28, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — batch (issues #10031 v1 slice follow-up, #10323)

  5. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Runtime → PHP — starting this run (HashTableHelper v4: move offsetIsSetDim/readDimToValueBox/offsetUnset/writableObjectKeyValueBox LLVM to Read/WriteLlvm; #10031).

  6. PurHur commented on Jul 10, 2026

    @PurHur
    OwnerAuthor

    Merged via #17755

    Shrink (v4 slice)

    • lib/JIT/HashTableHelper.php: 1788 → 1657 lines (−131)
    • Moved to HashTableReadLlvm: offsetIsSetDim, readDimToValueBox
    • Moved to HashTableWriteLlvm: offsetUnset, writableObjectKeyValueBox

    Verification

    • vendor/bin/phpunit --filter HashTableHelperShrinkTest — OK (9 tests, 36 assertions)
    • VM/JIT: boxed $a[$k] fetch, unset($a[$k]), isset($a['b']) — match
    • VM/JIT: $_GET['missing'] ?? 'd' — d
    • make bootstrap-selfhost-vm-driver-execute-probe — OK

    No new runtime/*.c logic.

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 / JITimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions