Skip to content

Language: Null coalescing operator (??) in compiler pipeline #99

Description

@PurHur

Problem

Modern PHP web code relies heavily on ?? for defaults:

$name = $_GET['name'] ?? 'Guest';
$action = $_POST['action'] ?? 'index';

If Op\Expr\Coalesce (or equivalent in php-cfg) is not lowered, compilation throws Unsupported expression from lib/Compiler.php.

Goal

Support ?? in CFG → opcodes → VM → JIT.

Tasks

Acceptance criteria

bin/vm.php, bin/jit.php, and bin/compile.php compile and run scripts using ?? with same output as PHP 8.

Related

Status on master (May 2026)

Layer Status Evidence
Compiler lib/Compiler.phpcompileCoalesce(), Expr\BinaryOp\Coalesce, ??= assign
VM test/compliance/cases/language/coalesce.phpt, coalesce_assign.phpt
JIT 🚧 partial lib/JIT/CoalesceHelper.php; coalesce_assign_jit.phpt; spine requires helper
AOT ✅ fixtures test/fixtures/aot/cases/coalesce_*.phpt (MiniWebApp bisect ladder)
Lint UnsupportedRegistry no longer tracks Expr_AssignOp_Coalesce
CI gate 📋 Dedicated gate tracked in #1960

Remaining before closing #99

  1. Audit JIT gaps: superglobal ?? chains, nested ?? with side effects
  2. Land CI: COALESCE_COMPLIANCE_GATE default-on in ci-fast (audit + close #99) #1960 COALESCE_COMPLIANCE_GATE=1 in ci-fast.sh
  3. Confirm bin/jit.php + bin/compile.php parity on coalesce_get_default.phpt

Implementation hints (JIT gaps)

Case Files
Superglobal default lib/Compiler.php + SuperglobalCoalesceVmTest
Branch targets lib/JIT/CoalesceHelper.php
Assign coalesce lib/JIT.php

Verification (local / Docker only)

./script/ci-fast.sh --filter Coalesce
COALESCE_COMPLIANCE_GATE=1 ./script/ci-fast.sh --filter Coalesce   # after #1960
docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  ./script/ci-fast.sh --filter Coalesce

Dependencies (updated)

Links

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