Skip to content

php-in-php: JIT FiberHelper — route Fiber suspend/resume through VmFiber PHP not ~587-line LLVM (#1492) #10079

Description

@PurHur

Category

php-in-php · php-src-strict runtime · refs #1492

Problem

Fiber MCJIT lowering is a ~587-line monolith in lib/JIT/FiberHelper.php (resume-ip switch functions, suspend static sites, stack limits). VM fiber semantics already live in PHP: lib/VM/FiberSupport.php, lib/VM/FiberState.php, lib/VM/Builtin/Fiber*.php mirroring php/php-src Zend/zend_fibers.c.

Maintaining fiber edge cases twice (VM vs LLVM) blocks #3130 / #4019 parity and self-host compile of compiler sources using Fiber.

php-src reference

Repro

test/repro/fiber_jit_vm_agree.php:

<?php
declare(strict_types=1);

$fiber = new Fiber(function (): int {
    Fiber::suspend('step1');
    return 42;
});
var_export($fiber->start());
echo "\n";
var_export($fiber->resume());
echo "\n";
var_export($fiber->getReturn());
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/fiber_jit_vm_agree.php
php bin/jit.php test/repro/fiber_jit_vm_agree.php'
Step Expected (Zend)
start() 'step1'
resume() 42
getReturn() 42

Any JIT divergence from VM output is in scope for this migration.

Scope (PHP-in-PHP first)

Path Work
lib/VM/FiberSupport.php Canonical suspend/resume/throw state machine
lib/JIT/FiberHelper.php Replace resume-ip LLVM switch with calls into compiled FiberSupport helpers
lib/JIT/Call/Fiber*.php Trampoline to PHP lowering
Tests test/compliance/cases/language/fiber_jit_vm_agree.phpt

No: no new runtime/*.c — fiber stack guard may stay as thin ABI only (#4019).

Done when

Verification

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

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