Skip to content

feat: implement PHP mb_strtoupper (AOT + Magician) - #898

Open
nahime0 wants to merge 12 commits into
mainfrom
cursor/mb-strtoupper-a3ed
Open

feat: implement PHP mb_strtoupper (AOT + Magician)#898
nahime0 wants to merge 12 commits into
mainfrom
cursor/mb-strtoupper-a3ed

Conversation

@nahime0

@nahime0 nahime0 commented Sep 5, 2026

Copy link
Copy Markdown
Member

Implements PHP mb_strtoupper(string $string, ?string $encoding = null): string for AOT and Magician/eval, following the existing mb_strlen encoding contract.

Semantics (PHP 8.5 / UTF-8)

  • Omitted/null encoding uses Unicode full case mapping (ßSS, éÉ)
  • Malformed/truncated UTF-8 bytes are copied through unchanged
  • 8bit / binary / 7bit apply ASCII-only a-zA-Z
  • Other names decode through libc iconv into UTF-32LE, uppercase, and encode back
  • Unknown encoding names raise a catchable \ValueError

Changes

  • Shared builtin contract + ICONV_MACOS requirement
  • Magician eval_builtin! implementation
  • AOT home file, RuntimeFnId::MbStrtoupper, feature-gated __rt_mb_strtoupper for AArch64 and x86_64
  • Codegen, error, eval-parity, and Magician tests
  • Example + hand docs and generated builtin registry

CI follow-up

  • AArch64 __rt_mb_strtoupper_ensure preserves LR across __rt_concat_grow
  • Catalog count gates bumped for the new contract
  • Regenerated docs/php/compatibility.md (516/2030)
  • x86_64 SysV alignment: frameless helpers pad nested calls; unknown-encoding teardown uses mov rsp, rbp / pop rbp

CI on this head is green (145 checks).

Open in Web Open in Cursor 

cursoragent and others added 5 commits September 5, 2026 10:26
Declare PHP mb_strtoupper(string, ?string $encoding = null) in the shared
builtin catalog, join Magician eval (UTF-8 full mapping, 8bit ASCII, iconv
round-trip, catchable ValueError), and register the AOT home plus RuntimeFnId
so lowering can emit a Fresh-owned helper gated by RuntimeFeatures.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Add the feature-gated __rt_mb_strtoupper helper for AArch64 and x86_64:
Unicode full-case tables, UTF-8 walker with malformed copy-through, ASCII
byte encodings, and an iconv UTF-32LE round-trip. Lower RuntimeFnId::MbStrtoupper
through the same optional-encoding ABI as mb_strlen.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Add codegen, eval-parity, Magician, and type-error tests for Unicode
mapping, encoding aliases, malformed UTF-8 copy-through, first-class
callables, and catchable unknown-encoding ValueError. Show the builtin
in the string-ops example.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Record the encoding-aware Unicode uppercase builtin next to mb_strlen,
bump the mbstring compatibility count, and note the gated runtime helper.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
The ensure/put_utf8 labels are only called from the AArch64 emitter.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
@github-actions github-actions Bot added area:codegen Touches target-aware assembly or backend lowering. area:magician Touches eval, include execution, or elephc-magician. area:runtime Touches runtime helpers, GC, ownership, or bridge runtimes. scope:multi-area Touches more compiler areas than the automatic area-label cap. size:l Large pull request. target:linux-x86_64 Contains behavior specific to the Linux x86_64 target. type:feature Introduces new user-visible behavior or capabilities. labels Sep 5, 2026
cursoragent and others added 3 commits September 5, 2026 10:36
Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
@github-actions github-actions Bot added size:xl Very large pull request that needs deliberate review planning. and removed size:l Large pull request. labels Sep 5, 2026
@nahime0
nahime0 marked this pull request as ready for review September 5, 2026 10:38
@greptile-apps

greptile-apps Bot commented Sep 5, 2026

Copy link
Copy Markdown

Too many files changed for review (286 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

cursoragent and others added 4 commits September 5, 2026 14:42
Short malformed UTF-8 inputs reserved fewer than 12 bytes, so ensure
called concat_grow and then ret'd with the clobbered x30, hanging the
walker. Save/restore the frame around that call.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Frameless ensure/free-temps helpers now pad around nested calls, and
the unknown-encoding path tears down the frame with mov/pop so the
runtime alignment audit can track rsp.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:codegen Touches target-aware assembly or backend lowering. area:magician Touches eval, include execution, or elephc-magician. area:runtime Touches runtime helpers, GC, ownership, or bridge runtimes. scope:multi-area Touches more compiler areas than the automatic area-label cap. size:xl Very large pull request that needs deliberate review planning. target:linux-x86_64 Contains behavior specific to the Linux x86_64 target. type:feature Introduces new user-visible behavior or capabilities.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants