Skip to content

JIT: lower (array)/(object)/(unset) TYPE_CAST_* opcodes (#4887) - #7618

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-4887-cast-jit-opcodes
Jun 8, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-4887-cast-jit-opcodes

Conversation

@PurHur

@PurHur PurHur commented Jun 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Add lib/JIT/CastHelper.php lowering for TYPE_CAST_ARRAY, TYPE_CAST_OBJECT, and TYPE_CAST_UNSET MCJIT opcodes (Zend zend_operators.c / CastSupport parity).
  • Extend Analyzer escape/static-array coverage for cast expr ops so MCJIT compile does not bail on (object)['x'=>1] / chained casts.
  • Fix LLVM insert-block loss when Object_::allocate() first links GcCollectCyclesRuntime (orphan phpc_gc_register IR).

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/unit/CastJitCompileTest.php'
# OK (3 tests, 7 assertions)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && export PHP_COMPILER_LLVM_PATH=/opt/llvm9 LD_LIBRARY_PATH=/opt/llvm9 && php -r "
require \"vendor/autoload.php\";
\$rt = new PHPCompiler\\Runtime();
\$block = \$rt->parseAndCompile(\"<?php echo count((array)(object)[\\\"x\\\"=>1]);\", \"cast_probe.php\");
\$rt->jitCompileBlock(\$block);
\$rt->jitEmitInPlace();
ob_start();
\$block->handler();
echo ob_get_clean();
"'
# 1

Issue repro count((array)(object)["x"=>1]) → 1 on JIT execute.

Closes #4887

Made with Cursor

Wire CastHelper for MCJIT compile of array/object/unset casts; fix LLVM insert-block loss after Object_::allocate() links GC runtime on first object allocation.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 062a1b0 into master Jun 8, 2026
@PurHur
PurHur deleted the agent/issue-4887-cast-jit-opcodes branch June 8, 2026 03:38
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: (array)/(object)/(float)/(unset) cast — JIT/AOT TYPE_CAST_* opcodes (zend_operators.c)

1 participant