Skip to content

Stdlib JIT: similar_text() third & arg — LLVM lowering (phase 2 of #2445) #3583

Description

@PurHur

Category

stdlib

Problem

similar_text() VM supports the optional third by-reference $percent argument; JIT/AOT reject three-arg calls at compile/lowering time. Framework code and PHPT suites that capture similarity percentage cannot run under bin/jit.php or AOT.

Phase 2 of closed #2445 (two-arg VM/JIT shipped).

php-src reference

Repro

VM (passes today)

<?php
$p = 0;
similar_text('hello', 'hallo', $p);
echo $p, "\n"; // Zend + bin/vm.php: 80
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php

JIT/AOT (failure today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php repro.php'
# LogicException from ext/standard/similar_text.php:
# similar_text() JIT/AOT only supports two arguments in this compiler build; use bin/vm.php for &$percent

Two-arg calls (similar_text($a, $b)) must remain green.

Scope (this repo)

Layer Files Notes
VM ext/standard/similar_text.php Reference write to $percent (baseline — do not regress)
JIT ext/standard/similar_text.php::call(), lib/JIT/Builtin/StringSimilarText.php (or existing helper) Emit percent write-back via indirect slot / param-by-ref pattern (#3161)
AOT shared JIT builtin Same LLVM path as JIT
Tests test/compliance/cases/stdlib/similar_text_percent.phpt VM + JIT; assert $p === 80 for repro strings

Reference-arg pattern: compare preg_match $matches JIT deferrals and closure use (&$x) (#3108).

Done when

  • Three-arg repro prints 80 under bin/jit.php (native MCJIT, no VM fallback)
  • Two-arg repro unchanged on JIT/AOT
  • ./script/ci-fast.sh --filter similar_text_percent green
  • docs/capabilities.md regenerated if JIT notes change

Verification

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

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-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions