Skip to content

Stdlib: is_array, is_string, is_null, is_int type guards (JIT) #148

@PurHur

Description

@PurHur

Problem

Validation before superglobal access often uses:

if (is_string($_GET['id'] ?? '')) { /* ... */ }

docs/capabilities.md lists is_array, is_string, is_null, is_int as yes in VM, but JIT may not lower them to fast type-byte checks — hot paths in routers regress to generic calls.

Goal

Ensure is_* type guards are fast in JIT (return i1, branch-friendly) and remain correct in VM/AOT for web validation patterns.

Implementation hints

Audit first

grep -R "function is_string" ext/ lib/
script/capability-matrix.php --check

Confirm whether gap is JIT-only or VM stub.

VM

  • Reuse Variable::type / existing ext/types/ implementations.
  • is_string must accept internal string representation used by superglobal values.

JIT (lib/JIT.php + ext/types/)

  • Lower to TYPE_* byte compare → i1 (same pattern as other type builtins in matrix).
  • Do not box superglobals unnecessarily before is_*.

Tests

Case Purpose
is_string($_GET['x'] ?? '') Web guard with #99 when landed
is_array($rows) Router table check
JIT PHPT group --group llvm compliance if exists

Acceptance criteria

docker run --rm -v "$(pwd):/compiler" -w /compiler php-compiler:22.04-dev \
  php bin/jit.php -r 'var_dump(is_string("a"));'

Prints bool(true) without falling back to VM interpreter for the check itself (verify via JIT compliance or dedicated unit test).

Verification (local / Docker only)

./script/ci-local.sh --filter 'is_string|is_array'

Requires LLVM (#98); use make test-docker on harness hosts.

Dependencies

Links

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions