Skip to content

feat(lang): WeakReference / WeakMap VM stub (#1366)#1478

Merged
PurHur merged 2 commits into
masterfrom
feat/lang-1366-weakref
May 24, 2026
Merged

feat(lang): WeakReference / WeakMap VM stub (#1366)#1478
PurHur merged 2 commits into
masterfrom
feat/lang-1366-weakref

Conversation

@PurHur
Copy link
Copy Markdown
Owner

@PurHur PurHur commented May 24, 2026

Summary

  • Register VM builtin classes WeakReference and WeakMap so scripts no longer fatal with "class not found".
  • WeakReference::create($obj) / get() use an indirect target slot: get() returns the object while alive and null after unset($obj) on the last strong variable (not cycle-collecting GC weak refs).
  • WeakMap stub: offsetSet / offsetGet / offsetExists / offsetUnset / count with object-id string keys; JIT external class registration for compile-only references.
  • Syntax matrix row Language: WeakReference and WeakMap #1366 marked VM yes / JIT no (partial stub).

Test plan

  • php vendor/bin/phpunit test/unit/WeakReferenceWeakMapTest.php
  • ./script/ci-local.sh (if available in CI environment)

Made with Cursor

Register builtin WeakReference and WeakMap on the VM with create/get and
ArrayAccess-style methods. WeakReference tracks targets via indirect slots so
unset() clears get(); documented as partial until real GC weak refs exist.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur PurHur force-pushed the feat/lang-1366-weakref branch from 1af4e35 to 5b4dd01 Compare May 24, 2026 15:09
@PurHur
Copy link
Copy Markdown
Owner Author

PurHur commented May 24, 2026

Rebased onto current origin/master (1588301) via cherry-pick + manual conflict resolution (rewrite approach).

Conflicts (4): docs/capabilities-syntax.md, docs/roadmap-wave3.md, lib/VM/ClassEntry.php, script/capability-syntax-lib.php — kept master's roadmap-wave3.md (already lists #1366 open); merged ClassEntry with ?Func constructor for VM builtins; capability matrix regenerated.

Tests: vendor/bin/phpunit test/unit/WeakReferenceWeakMapTest.php — OK (6 tests).

Branch force-pushed: feat/lang-1366-weakref @ 5b4dd01.

Merge readonly ClassEntry (Func ctor + readonly flag) and both capability rows.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant