Category
php-in-php · compile pipeline · refs #1492
Problem
JIT instanceof lowering lives in lib/JIT/InstanceOfHelper.php (~217 lines) emitting bespoke LLVM for literal class names, dynamic RHS types, enum/interface checks, and invalid-RHS errors. VM already resolves instanceof via lib/VM/TypeCheck.php + InterfaceCheck — duplicate semantics in LLVM.
Risk: JIT/AOT disagree with VM on edge cases (#4339, enum units, __Stringable, trait aliases) unless every branch is mirrored twice.
php-src reference (semantics)
Repro (parity drift today)
test/repro/instanceof_jit_vm_agree.php:
<?php
declare(strict_types=1);
interface I {}
enum E: string { case A = 'x'; }
class C implements I {}
$checks = [
new C() instanceof I::class,
E::A instanceof E::class,
's' instanceof \Stringable::class,
];
foreach ($checks as $i => $v) {
echo "$i=" . ($v ? '1' : '0') . "\n";
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/instanceof_jit_vm_agree.php
php bin/jit.php test/repro/instanceof_jit_vm_agree.php'
Audit any JIT-only divergence vs VM; after migration both backends must match.
Scope (PHP-in-PHP first)
| Path |
Work |
lib/VM/TypeCheck.php / new VmInstanceOf.php |
Single PHP entry for literal + dynamic RHS |
lib/JIT/InstanceOfHelper.php |
Shrink to trampoline → compiled PHP helper (or delete branches) |
lib/JIT/Builtin/Type/Object_.php |
Stop duplicating instanceof tables in LLVM where possible |
| Tests |
Extend test/compliance/cases/language/instanceof*.phpt with JIT guard |
Done means lines removed from InstanceOfHelper.php / Object_.php LLVM, not a second copy of zend tables in C.
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter InstanceOf'
Related
Category
php-in-php· compile pipeline · refs #1492Problem
JIT
instanceoflowering lives inlib/JIT/InstanceOfHelper.php(~217 lines) emitting bespoke LLVM for literal class names, dynamic RHS types, enum/interface checks, and invalid-RHS errors. VM already resolves instanceof vialib/VM/TypeCheck.php+InterfaceCheck— duplicate semantics in LLVM.Risk: JIT/AOT disagree with VM on edge cases (#4339, enum units,
__Stringable, trait aliases) unless every branch is mirrored twice.php-src reference (semantics)
Zend/zend_execute.c—instanceof_function_slowZend/zend_interfaces.c— interface/instanceof tablesRepro (parity drift today)
test/repro/instanceof_jit_vm_agree.php:Audit any JIT-only divergence vs VM; after migration both backends must match.
Scope (PHP-in-PHP first)
lib/VM/TypeCheck.php/ newVmInstanceOf.phplib/JIT/InstanceOfHelper.phplib/JIT/Builtin/Type/Object_.phptest/compliance/cases/language/instanceof*.phptwith JIT guardDone means lines removed from
InstanceOfHelper.php/Object_.phpLLVM, not a second copy of zend tables in C.Done when
TypeErrorwith Zend message via shared PHP helperInstanceOfHelper.php≤ ~80 lines (trampoline + type dispatch only)./script/ci-fast.sh --filter instanceofgreenVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter InstanceOf'Related