Skip to content

php-in-php: JIT InstanceOfHelper — route instanceof through VmTypeCheck PHP not ~217-line LLVM (#1492) #10078

Description

@PurHur

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

  • Repro byte-identical on VM + JIT + AOT (where instanceof is JIT-supported)
  • Invalid RHS (array/int) throws TypeError with Zend message via shared PHP helper
  • InstanceOfHelper.php ≤ ~80 lines (trampoline + type dispatch only)
  • ./script/ci-fast.sh --filter instanceof green

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter InstanceOf'

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-0:FoundationPhase 0 – foundation & DevExphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions