Skip to content

Language: by-reference parameters JIT/AOT lowering (#3161) - #3169

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-3161-ref-param-jit
May 30, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-3161-ref-param-jit

Conversation

@PurHur

@PurHur PurHur commented May 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Implements JIT lowering for by-reference function parameters (function f(&$x)), closing the gap after VM work in Language: Reference assignment and by-ref parameters #140.
  • Callee formals bind to caller __value__* storage via valueBoxAliasPtr (same model as closure use (&$x) / foreach by-ref).
  • Call sites promote native scalars to boxed lvalues when needed; Helper::loadValue and assignOperand read/write through aliases.

php-src reference

  • Zend/zend_compile.czend_compile_param() by_ref
  • Zend/zend_execute.cZVAL_MAKE_REF, argument binding by reference

Verification

# VM (passes)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./vendor/bin/phpunit --filter ref_param test/compliance/VMTest.php'

# JIT compliance (added ref_param_jit.phpt)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./vendor/bin/phpunit --filter ref_param_jit test/compliance/JITTest.php'

# Repro
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "function inc(&\$n){\$n++;} \$x=1; inc(\$x); echo \$x;"'

Note: This harness Docker image currently segfaults on bin/jit.php MCJIT execute even for echo 42 (exit 139); the ref-param repro compiles without the prior Unsupported cast … __value__* / valuePtrFromVariable failures. Full JIT execute green needs the LLVM 9 dev image / make test path from script/ci-local.sh.

Test plan

  • VM compliance ref_param.phpt
  • JIT compliance case ref_param_jit.phpt added
  • docs/capabilities-syntax.md — by-ref row JIT/AOT yes
  • make test / ./script/ci-local.sh --filter ref_param on LLVM host when available

Closes #3161

Made with Cursor

Alias callee formals to caller __value__* slots (Zend zend_compile_param
by_ref), promote native call arguments to boxed lvalues, and read/write
through valueBoxAliasPtr in Helper/JIT assign paths.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 1aa440b into master May 30, 2026
@PurHur
PurHur deleted the agent/issue-3161-ref-param-jit branch May 30, 2026 05:30
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.

Language: By-reference parameters JIT/AOT lowering (phase 2 post-#140)

1 participant