Skip to content

Language: Generator JIT lowering (yield opcodes) #3074

Description

@PurHur

Category

language · php-src-strict

Problem

Generators work on VM (lib/VM/GeneratorState.php, TYPE_YIELD / TYPE_YIELD_FROM) but JIT aborts with LogicException: Generators (yield) are VM-only (issue #167) in lib/JIT.php (~5574). bin/jit.php falls back to VM; there is no LLVM lowering for suspend/resume.

Blocks JIT-native compliance for generator-heavy code and self-host paths that compile lib/ with yield.

php-src reference

Repro (failure today)

<?php
function gen(): Generator {
    yield 1;
    yield 2;
}
foreach (gen() as $v) {
    echo $v;
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/jit.php -r "
function gen() { yield 1; yield 2; }
foreach (gen() as \$v) { echo \$v; }
"'
php bin/jit.php repro.php 2>&1 | head -5
Runtime Expected Actual
Zend + OPcache JIT 12 12
bin/jit.php 12 without VM fallback LogicException or VM-only deferral ❌

Scope (this repo)

Layer Path Work
JIT lib/JIT.php Remove VM-only guard; emit suspend/resume control flow
Context lib/JIT/Context.php Generator frame/stack slots
VM reference lib/VM/GeneratorState.php Mirror semantics (do not duplicate in C)
Tests test/compliance/cases/language/generator_jit.phpt
AOT out of scope #3115 / #167

PHP-in-PHP: LLVM lowering in lib/JIT/; no new runtime/*.c.

Done when

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./vendor/bin/phpunit --filter generator_jit test/compliance/JITTest.php'

Strictness

php-src-strict for user-visible generator iteration; #4599 tracks foreach-by-ref phase 2.

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-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions