Skip to content

feat(jit): closure use (&$var) by-reference lowering (#72) - #3108

Merged
PurHur merged 2 commits into
masterfrom
feat/jit-closure-use-byref-72
May 29, 2026
Merged

feat(jit): closure use (&$var) by-reference lowering (#72)#3108
PurHur merged 2 commits into
masterfrom
feat/jit-closure-use-byref-72

Conversation

@PurHur

@PurHur PurHur commented May 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Implement JIT lowering for use (&$var) closure captures, mirroring the VM bindClosureCaptures / bindClosureCallCaptures indirect path.
  • ClosureHelper::referenceCapture passes live enclosing variables through ClosureWithCaptures; compileBlock aliases by-ref capture slots to the trailing __value__* param (foreach by-ref pattern) instead of snapshotting.
  • Add closure_use_byref.phpt compliance case and extend ClosureJitCompileTest IR verify coverage.

Test plan

  • phpunit test/compliance/ClosureVMTest.php (includes closure_use_byref.phpt)
  • phpunit test/unit/ClosureJitCompileTest.php --filter testClosureModuleVerify
  • bin/jit.php -r MCJIT runtime (skipped here: probe segfaults in CI env; IR verify passes)

Limitations

  • By-ref captures alias simple enclosing locals/globals resolved at closure creation; complex lvalues (array elements, properties) are not covered yet.
  • MCJIT execute path for closures remains environment-sensitive (same as existing closure JIT); compile-time IR verification is the gate in ClosureJitCompileTest.
  • Bootstrap / self-host AOT still stubs closures to null.

Made with Cursor

PurHur and others added 2 commits May 29, 2026 15:30
Mirror VM bindClosureCaptures indirect path: referenceCapture passes live
enclosing variables through ClosureWithCaptures, and compileBlock aliases
capture slots to the __value__* param instead of snapshotting by value.

Co-authored-by: Cursor <cursoragent@cursor.com>
Wire compileBlock capture params to live __value__* storage via
valueBoxAliasPtr so by-reference use() mirrors VM bindClosureCallCaptures.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur force-pushed the feat/jit-closure-use-byref-72 branch from a7b4e73 to e523d80 Compare May 29, 2026 13:30
@PurHur
PurHur merged commit 7efd6c8 into master May 29, 2026
@PurHur
PurHur deleted the feat/jit-closure-use-byref-72 branch May 29, 2026 13:31
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