Skip to content

Language: ArrayAccess — JIT/AOT offset dispatch on user objects (phase 2 of #3331) #4012

Description

@PurHur

Category

language

Problem

#3331 closed VM dispatch for ArrayAccess$obj[$key] read/write/isset/unset calls offsetGet/Set/Exists/Unset. JIT = no, AOT = no in docs/capabilities-syntax.md.

JIT currently deopts to VM (requiresVmLowering) for TYPE_ARRAY_DIM_FETCH on non-array objects.

php-src reference

Repro (today)

<?php
class Bag implements ArrayAccess {
    private array $a = [];
    public function offsetExists(mixed $k): bool { return isset($this->a[$k]); }
    public function offsetGet(mixed $k): mixed { return $this->a[$k]; }
    public function offsetSet(mixed $k, mixed $v): void { $this->a[$k] = $v; }
    public function offsetUnset(mixed $k): void { unset($this->a[$k]); }
}
$b = new Bag();
$b['x'] = 1;
echo $b['x'], "\n";
var_export(isset($b['y']));
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro_arrayaccess.php'
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php repro_arrayaccess.php'
Runtime Expected
Zend 1 then false
VM same
JIT/AOT same without VM fallback

Scope (this repo)

Area Files
VM lib/VM.php — object dim fetch/write paths (reference)
JIT lib/JIT/Builtin/Type/Object_.php, array-dim helpers — offsetGet/offsetSet method dispatch
Tests test/compliance/cases/language/arrayaccess_offset.phpt (+ jit/aot variants)
Matrix array_access_interface row

Done when

  • JIT PHPT green for read + write + isset + unset on ArrayAccess user class
  • AOT fixture green
  • Non-ArrayAccess objects still throw Zend-parity Error (not silent wrong results)

Verification

./script/ci-fast.sh --filter arrayaccess

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