Skip to content

Redesign String and Array APIs aligned with Rust#735

Merged
gfx merged 12 commits intomainfrom
claude/align-api-design-jD1QI
Mar 30, 2026
Merged

Redesign String and Array APIs aligned with Rust#735
gfx merged 12 commits intomainfrom
claude/align-api-design-jD1QI

Conversation

@gfx
Copy link
Copy Markdown
Member

@gfx gfx commented Mar 30, 2026

Summary

  • Redesign String and Array<T> APIs to align with Rust's String/&str and Vec<T>/&[T] APIs (excluding lifetime/ownership concepts)
  • Array: add push (rename from append), first, clear, capacity, reserve, shrink_to_fit, insert, remove, swap, reverse, extend, contains, repeat, join, windows, chunks
  • String: add push_str (rename from append), push (rename from append_char), pop, clear, capacity, reserve, shrink_to_fit, as_bytes, contains, starts_with, ends_with, find, rfind, contains_char, find_char, truncate (rename from truncate_bytes), insert, insert_str, remove, repeat, replace, replacen, split, splitn, split_whitespace, lines, char_indices
  • Old method names (append, append_char, truncate_bytes) marked as @deprecated and kept as aliases
  • All stdlib callers, compiler synthesis code, test fixtures, and docs migrated to new names
  • WEP document: docs/wep-2026-03-29-redesign-string-array-api.md

Test plan

  • All 4380 E2E tests pass
  • All stdlib module tests pass (string, array, base64, zlib, serde, collections, format)
  • Format tests pass (81 tests)
  • on-task-done completed successfully (format, clippy, golden fixtures, stdlib docs)

https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H

claude added 12 commits March 29, 2026 23:46
Design proposal to unify String and Array APIs with consistent naming
(push/extend/contains/find), add missing methods (split, join, reverse,
insert, remove, etc.), and deprecate inconsistent append/append_char.

https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
Restructure around Array↔Vec and String↔String/str mapping tables
instead of String-vs-Array comparison. Add byte-index convention,
pattern argument design, and per-type Rust method mapping.

https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
Lazy iteration is more efficient and consistent with Rust's API.
Users can .collect() when they need an Array<String>.

https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
GC manages the internal buffer (repr), not the capacity of
String/Array, so these methods are needed for users.

https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
Array: add push (rename from append), first, clear, capacity, reserve,
shrink_to_fit, insert, remove, swap, reverse, extend, contains, repeat,
join, windows, chunks. Mark append as deprecated.

String: add push_str (rename from append), push (rename from append_char),
pop, clear, capacity, reserve, shrink_to_fit, as_bytes, contains,
starts_with, ends_with, find, rfind, contains_char, find_char, truncate
(rename from truncate_bytes), insert, insert_str, remove, repeat, replace,
replacen, split, splitn, split_whitespace, lines, char_indices.
Mark append/append_char/truncate_bytes as deprecated.

Migrate all stdlib callers to use new API names. Add comprehensive tests
for all new methods. All 4380 E2E tests and stdlib tests pass.

https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
- Compiler: template.rs uses push_str instead of append for String
- Compiler: cm_binding.rs uses push instead of append for Array
- 80 test fixtures: Array.append → push, String.append → push_str
- WIR patterns updated in inline_cross_module_method and array_append_collapse
- docs/spec.md and docs/cheatsheet.md updated
- Format fixtures updated
- WASI Fields::append left unchanged (WIT-defined method)

https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
Regenerated all WIR golden fixtures reflecting the push/push_str rename.
Updated auto-generated stdlib docs (cheatsheet-stdlib-core.md, stdlib-core.md).
All tests pass.

https://claude.ai/code/session_01Fkk58ytneCpBBtEmXT6m2H
@gfx gfx merged commit 2a7152e into main Mar 30, 2026
10 checks passed
@gfx gfx deleted the claude/align-api-design-jD1QI branch March 30, 2026 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants