Skip to content

php-in-php: JIT FromCallableHelper — route TYPE_FROM_CALLABLE LLVM through VmClosure PHP not ~214-line helper (#1492) #10272

Description

@PurHur

Category

php-in-php · php-src-strict · compile/runtime shared

Problem

lib/JIT/FromCallableHelper.php (~214 lines) lowers PHP 8.1 TYPE_FROM_CALLABLE (first-class callable strlen(...), [$obj,'m'](...), invokable objects) into inline LLVM via BoundMethodCallableHelper / ClosureWithBinding paths. VM implements Closure::fromCallable() semantics in lib/VM/ClosureSupport.php and ClosureFromCallable builtin.

Duplicated binding/visibility checks drift from php-src and overlap #10185 (BoundMethodCallableHelper) without a single SSOT.

php-src reference

Repro

<?php
$f = strlen(...);
echo $f('abc'), "\n";
class C { public function m(): int { return 1; } }
$g = (new C())->m(...);
echo $g(), "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php
php bin/vm.php repro.php
php bin/jit.php repro.php 2>&1
wc -l lib/JIT/FromCallableHelper.php lib/JIT/BoundMethodCallableHelper.php
'

Scope (this repo)

Shrink LLVM Grow PHP
FromCallableHelper.php string/bound/invokable LLVM Route through lib/VM/ClosureSupport.php + compiled trampoline
Overlap with BoundMethodCallableHelper Single VmCallable/VmClosure SSOT used by VM + JIT
lib/JIT/Call/ClosureWithBinding.php branches Thin ABI only when unavoidable

Do not grow runtime/*.c.

Done when

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit test/unit/JitFirstClassCallableTest.php'
make bootstrap-selfhost-vm-driver-execute-probe

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