Skip to content

Compiler: VM/JIT comparison and equality for mixed types (routing guards) #90

Description

@PurHur

Problem

lib/VM/Variable.php throws for many equality pairs:

Equals comparison between {type} and {type} not implemented

Routers and guards frequently compare strings to literals, or mixed int/string from $_GET:

if ($_GET['page'] === 'admin') { ... }
if ($route == 1) { ... }

JIT may lack lowering for === / == on some type pairs even when VM works. Blocks #210 route tables and #270 JSON guard patterns.

Goal

Complete comparison operators (==, ===, !=, <, >, <=, >=) for web-common type pairs: string/string, string/int, int/int, bool/bool, null checks.

Implementation hints

Audit first

rg "not implemented" lib/VM/Variable.php
rg "TYPE_IS_EQUAL|TYPE_IS_IDENTICAL" lib/JIT.php lib/Compiler.php

Variable::equals() (~line 368) and compareOp() (~441) — extend switch arms before adding JIT.

VM (lib/VM/Variable.php)

  • string === string: byte-wise compare (Zend uses binary-safe; match PHP for ASCII routes)
  • string == int: PHP coercion rules — add PHPT table in test/real/cases/compare_mixed.phpt
  • null === null: already partial; ensure $_GET['missing'] undefined key behavior aligns with Runtime: Undefined array/superglobal key — Zend notice parity #273 before strict compares

JIT (lib/JIT.php)

  • Search assignop / compare lowering for Op\Expr\BinaryOp\Equal / Identical
  • Reuse string compare helpers from existing concat/strlen JIT paths
  • Order: === string/string first (routing), then loose == for query params

AOT

  • Same LLVM paths as JIT once opcode coverage lands

Tasks

Acceptance criteria

docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  ./phpc run -r 'var_export("1" === "1");'

if ($route === 'home') and if ($_GET['id'] === '1') work in VM, JIT, and AOT.

Key files

  • lib/VM/Variable.phpequals(), compareOp(), _compareOp()
  • lib/JIT.php — binary compare opcodes
  • lib/Compiler.php — expr lowering for Equal / Identical

Dependencies

Verification (local only)

./script/ci-local.sh --filter compare

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions