Skip to content

php-in-php: JIT SpaceshipCompareJit — route <=> through VM compare PHP not ~1.2k-line LLVM (#1492) #9381

Description

@PurHur

Category

php-in-php | language | runtime

Problem

The spaceship operator (<=>) JIT lowering is lib/JIT/Builtin/SpaceshipCompareJit.php (~1.2k lines LLVM), ported from former lib/AOT/runtime/phpc_spaceship.c. VM semantics SSOT is PHPCompiler\VM\Variable compare/spaceship helpers in PHP.

Enum ordering regressions (#9288) and mixed-type compares must be fixed twice while LLVM tables diverge from VM. PHP-in-PHP first: compile the VM compare path for JIT/AOT instead of maintaining parallel type-switch LLVM.

php-src reference

  • Zend/zend_operators.c — compare_function, object/enumeration spaceship
  • Zend/zend_enum.c — backed enum comparison ordering

Repro

<?php
declare(strict_types=1);
enum E: int { case A = 1; case B = 2; }
var_dump(E::A <=> E::B);   // Zend: -1 (see #9288 if inverted)
var_dump(null <=> 1);      // -1
var_dump('a' <=> 'b');     // -1

Commands

./script/docker-exec.sh php bin/vm.php repro.php
./script/docker-exec.sh php bin/jit.php repro.php

Scope (this repo)

Done when (php-src-strict)

Refs: #1492, #5185, #9288

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