Skip to content

feat: add PHP mb_strwidth (AOT + Magician) - #895

Closed
nahime0 wants to merge 8 commits into
mainfrom
cursor/mb-strwidth-c5c4
Closed

nahime0 wants to merge 8 commits into
mainfrom
cursor/mb-strwidth-c5c4

Conversation

@nahime0

@nahime0 nahime0 commented Sep 5, 2026

Copy link
Copy Markdown
Member

Adds PHP mb_strwidth() on both AOT and Magician/eval(), matching PHP 8.5 East Asian Width for UTF-8 and the same encoding argument rules as mb_strlen().

Why

Termwind layout (Styles::getLength and related width math) needs mb_strwidth. Elephc mbstring previously exposed only mb_strlen and mb_ereg_match.

What

  • Shared PHP 8.5 mbfl_eaw_table + character_width() in elephc-builtin-contract
  • Catalog contract, AOT builtin! home, Magician eval_builtin! hook
  • __rt_mb_strwidth / __rt_mb_char_width on every supported target, gated with the existing mb_strlen runtime family
  • Encoding aliases (UTF-8/UTF8, 8bit/binary/7bit), iconv-backed names, catchable ValueError for unknown encodings
  • Codegen, eval-parity, Magician, and error tests; examples/string-ops demo
  • Generated builtin docs, docs/php/strings.md, runtime internals, and ROADMAP

Scope

Only mb_strwidth. No other mb_* functions.

Verification

Focused tests are green locally on linux-x86_64:

  • cargo test --test codegen_tests test_mb_strwidth (4 tests)
  • cargo test --test codegen_tests test_eval_mb_strwidth
  • cargo test --test error_tests test_error_mb_strwidth (3 tests)
  • Magician execute_program_dispatches_mb_strwidth_builtin
  • Shared EAW table unit test
  • function_exists('mb_strwidth') and first-class mb_strwidth(...) on AOT and eval
  • Builtin docs pipeline (extract_builtins, audit, site compat, EIR boundary, gen_php_comparison)

CI covers the full supported-target matrix.

Focused test log
AOT and eval demo

To show artifacts inline, enable in settings.

Open in Web Open in Cursor 

cursoragent and others added 5 commits September 5, 2026 10:24
Share East Asian Width ranges and character_width() in the builtin
contract so AOT and Magician cannot drift.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Reuse the strlen eval hook family and apply the shared PHP 8.5 width
table, including encoding aliases and catchable ValueError.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Lower mb_strwidth through the same encoding ABI as mb_strlen and emit
__rt_mb_strwidth plus a shared East Asian Width lookup.

Co-authored-by: Vincenzo Petrucci <nahime0@users.noreply.github.com>
Add display-width, encoding, malformed UTF-8, and function_exists
coverage, plus a string-ops example.

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 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:m Medium-sized pull request. type:feature Introduces new user-visible behavior or capabilities. labels Sep 5, 2026
cursoragent and others added 2 commits September 5, 2026 10:29
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:m Medium-sized pull request. labels Sep 5, 2026
@nahime0
nahime0 marked this pull request as ready for review September 5, 2026 10:30
@greptile-apps

greptile-apps Bot commented Sep 5, 2026

Copy link
Copy Markdown

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

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

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: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. type:feature Introduces new user-visible behavior or capabilities.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants