Skip to content

feat: add PHP mb_strimwidth (AOT + Magician) - #900

Closed
nahime0 wants to merge 10 commits into
mainfrom
cursor/mb-strimwidth-0d89
Closed

nahime0 wants to merge 10 commits into
mainfrom
cursor/mb-strimwidth-0d89

Conversation

@nahime0

@nahime0 nahime0 commented Sep 5, 2026

Copy link
Copy Markdown
Member

Adds PHP mb_strimwidth() for AOT and Magician/eval, matching PHP 8.5 UTF-8 display-width trim semantics. Needed for Termwind truncate/trimText.

Behavior

mb_strimwidth(string $string, int $start, int $width, string $trim_marker = "", ?string $encoding = null): string

  • Omitted/null/UTF-8/UTF8 trim by PHP 8.5 East Asian Width (width 2 in the eaw_table.h ranges, otherwise 1).
  • 8bit/binary/7bit treat every byte as width 1.
  • $start is a character offset; negative values count from the end.
  • If the remaining suffix is wider than $width, it is cut and $trim_marker is appended. When the marker is at least as wide as the budget, PHP returns the marker alone.
  • Unknown encodings and out-of-range $start/$width raise catchable ValueError.
  • Scope is only mb_strimwidth (not mb_strwidth or other mb_*).

Implementation

  • Shared catalog contract + AOT builtin! home.
  • Magician eval_builtin! with the same EAW table and trim algorithm.
  • Typed RuntimeFnId::MbStrimwidth__rt_mb_strimwidth for AArch64 and x86_64.
  • No iconv / no new runtime-feature bit: unused programs can still strip the helper.

Tests

  • Codegen: ASCII/CJK trim, encodings, first-class callable, namespaced lookup, ValueErrors.
  • Eval parity through Magician.
  • Compile-time arity and type errors.

Docs

  • docs/php/strings.md, examples/string-ops, ROADMAP.md, generated builtin pages.
Open in Web Open in Cursor 

cursoragent and others added 5 commits September 5, 2026 10:32
Declare PHP mb_strimwidth() in the builtin catalog and AOT home file,
matching the string/start/width plus optional marker and encoding surface.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Add the eval builtin, PHP 8.5 East Asian Width table, and ValueError
handling for unknown encodings and out-of-range start/width.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Emit __rt_mb_strimwidth for every supported target, including the PHP 8.5
EAW table, and lower the typed RuntimeFnId through the EIR backend.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Cover ASCII/CJK trim, encoding aliases, first-class callables, Magician
eval parity, and compile-time arity/type errors.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Add the PHP reference row, string-ops example, roadmap item, and the
generated catalog pages for the new builtin.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
@github-actions github-actions Bot added area:builtins Touches PHP builtin declarations or emitters. 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. type:feature Introduces new user-visible behavior or capabilities. labels Sep 5, 2026
Keep the AArch64 walker comments at column 81 and derive Debug so the
Magician unit tests can unwrap trim results.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
@nahime0
nahime0 marked this pull request as ready for review September 5, 2026 10:34
@greptile-apps

greptile-apps Bot commented Sep 5, 2026

Copy link
Copy Markdown

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

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

cursoragent and others added 4 commits September 5, 2026 14:45
Save the pre-decode cursor before next clobbers x9 so a rejected
character rewinds instead of reserving a huge concat size. Pad the
x86_64 helper frame and skip walker so libc calls stay 16-byte aligned.

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>
Negative width plus a non-zero start must subtract the skipped prefix
width. skip/strwidth clobber x9, so persist the running budget on the
stack like the x86_64 helper already does.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
@nahime0

nahime0 commented Sep 14, 2026

Copy link
Copy Markdown
Member Author

Superseded by #952, which centralizes the mbstring implementation across the shared contract, AOT, Magician/eval, supported targets, tests, examples, and generated documentation. Closing this standalone PR in favor of #952.

@nahime0 nahime0 closed this Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:builtins Touches PHP builtin declarations or emitters. 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. type:feature Introduces new user-visible behavior or capabilities.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants