Skip to content

php-in-php: JIT ArrayAccessHelper — route ArrayAccess $obj[$k] LLVM through VmArrayAccess PHP not ~301-line monolith (#1492) #10246

Description

@PurHur

Category

php-in-php · language

Problem

ArrayAccess offset syntax $obj[$key] (read/write) lowers through lib/JIT/ArrayAccessHelper.php (~301 LOC) with LLVM interface checks and indirect offsetGet/offsetSet calls. VM dispatches via PHP (lib/VM.php + user methods).

Duplicated logic risks drift vs php-src read_dimension / write_dimension on objects implementing ArrayAccess (#3331, #4012).

php-src reference

Repro

wc -l lib/JIT/ArrayAccessHelper.php
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/jit.php -r "
class C implements ArrayAccess {
  private array \$d = [];
  public function offsetExists(\$k): bool { return isset(\$this->d[\$k]); }
  public function offsetGet(\$k): mixed { return \$this->d[\$k]; }
  public function offsetSet(\$k, \$v): void { \$this->d[\$k] = \$v; }
  public function offsetUnset(\$k): void { unset(\$this->d[\$k]); }
}
\$c = new C(); \$c[\"x\"] = 1; echo \$c[\"x\"];
" 2>&1
'

Scope (PHP-in-PHP)

Path Work
lib/JIT/ArrayAccessHelper.php Replace LLVM monolith with VmArrayAccess trampoline
lib/VM/ArrayAccessDispatch.php (new or existing) SSOT for offsetGet/Set/Exists/Unset
lib/JIT/Call/RuntimeIndirectInstanceMethodCall.php Reuse where possible

Done when

  • JIT ArrayAccess read/write on repro class matches VM
  • ArrayAccessHelper.php ≤ ~50 LOC glue; monolithic LLVM removed
  • ./script/ci-fast.sh --filter ArrayAccess green (add JIT smoke if missing)

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