Skip to content

Arrays: Full associative array support (string keys, holes, rehash) #66

Description

@PurHur

Problem

HashTable has packed-list fast paths; several methods throw for non-packed arrays (mergeCopy, sliceCopy, etc.). rehash() throws LogicException('Need to implement rehash') in lib/VM/HashTable.php (~L908).

Web apps use string-keyed maps ($_GET, config arrays, JSON-decoded data). Self-host M3 native emit segfaults in __hashtable__readStringKeyValue (#1514) — tracked as critical-path child #1761.

Goal

Reliable associative arrays for VM, JIT, and native AOT hashtable runtime.

Implementation hints

Layer Files Notes
VM rehash lib/VM/HashTable.php Replace throw; grow indexes/buckets MaskedArrays; preserve string + int keys
Packed → mixed same Triggers on first string key or hole
JIT lib/JIT/Builtin/ hashtable helpers String-key get/set after VM rehash
AOT runtime native __hashtable__* stubs Align with VM semantics for self-host bundle
Methods mergeCopy, sliceCopy, array_merge paths Un-skip or document assoc limits

Repro (VM)

$a = [];
for ($i = 0; $i < 20; $i++) {
    $a["key$i"] = $i;  // triggers rehash today → LogicException
}
echo $a['key19'];

Tests

  • test/compliance/cases/hashtable_rehash.phpt — insert until rehash, read back
  • test/compliance/cases/hashtable_string_keys.phpt — isset/unset on string keys
  • Optional @group llvm AOT fixture mirroring VM script

Tasks

Acceptance criteria

./phpc run -r '$config = ["db" => "localhost", "port" => "3306"]; echo $config["db"];'
# → localhost (no LogicException)

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

$config = ['db' => 'localhost', 'port' => '3306']; operations work in VM+JIT without LogicException.

Dependencies

Verification (local / Docker only)

./script/ci-fast.sh --filter hashtable
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev ./script/ci-fast.sh --filter hashtable

No GitHub Actions (#394 ✅).

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions