Skip to content

feat(ts): emit each module in Rust source order - #27

Merged
kixelated merged 4 commits into
mainfrom
quest/m2/ts-source-order
Oct 24, 2026
Merged

kixelated merged 4 commits into
mainfrom
quest/m2/ts-source-order

Conversation

@kixelated

@kixelated kixelated commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

rust2-ts printed a class's or companion's methods, the instances of a generic item, and each file's imports in the order translation reached them. Adding a root (bench::run in #7) reordered decode.ts with no change in behaviour, so any new root churned unrelated output.

Approach

  • Every symbol sorts by one key: its source position (rustc's source map position, at the macro call for macro-made items), then name, then instance suffix, then the instance printed in full. Program::name sorts module items and each owner's methods by it, and names collisions in that order.
  • The position is now the absolute source map offset, not a per-file index assigned in reach order.
  • Imports list each module's names in that module's order, and collision-renamed bindings resolve in the same order.
  • Instances of one generic item sit together, sorted by their suffix (Pair in fmt$Pair), then by their full type arguments, which tells apart instances whose suffixes match (such as two closures). Documented in ts/README.md.
  • New source_order test: translates the codec fixture with only harness::run, then with bench::run added as the first root, and asserts every line of the first output stays in order in the second (imports split one name per line). It fails on main.
  • Snapshots are regenerated in a separate commit. Each file keeps the same lines, only reordered.

Impact

  • The translator's output order changes: items and methods follow the Rust source. Exported names and behaviour are unchanged, so this is not breaking and has no MIGRATE.md entry.
  • Consumer: moq's translated codec, whose snapshot stops churning when roots change.

Alternatives

  • Sorting by name: the maintainer chose source order on 2026-10-23, so the output reads like the Rust.
  • Ordering instances by first reach: this depends on roots, which is the bug.

Follow-ups

Closes the quest quest/m2/ts-source-order.md.

(written by Opus 5.5)

🤖 Generated with Claude Code

https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn

kixelated and others added 3 commits October 24, 2026 05:24
…em first

Sort each module's items, each class's or companion's methods, and each file's
imports by source position, then by instance suffix and the full instance, so
the order no longer depends on the order translation reaches them in. A test
translates the codec fixture with and without bench::run and checks the
first output's lines stay in order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
Only order changes: every file keeps the same lines.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated kixelated changed the title Source order in the TypeScript translator feat(ts): emit each module in Rust source order Oct 24, 2026
@kixelated
kixelated marked this pull request as ready for review October 24, 2026 12:45
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-24T14:13:37.825527Z d25b80a New commits
🔒 Security Review ✅ Completed 2026-10-24T14:14:45.511306Z d25b80a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Regenerated the lang harness.ts snapshot in source order; no logic change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated

Copy link
Copy Markdown
Collaborator Author

This emits each module's items in Rust source order. A test proves that adding a root keeps the existing items' relative order, and the snapshots were regenerated in their own commit as a pure reorder.

  • Codex re-reviewed d25b80a with no findings, and CI passed.
  • The branch contains main, and quest check passes.

Merging.

(written by Opus 5.5)

@kixelated
kixelated merged commit 3930344 into main Oct 24, 2026
1 check passed
kixelated added a commit that referenced this pull request Oct 24, 2026
Keeps both sides: iterators (#23) beside drops and async, `!` values through a
never-assigned temp (#28), and source order (#27), whose `order` now takes a span so
a hoisted generator sorts where its async body is written. An iterator that owns a
value that drops is refused, since an `rt.Iter` drops nothing it skips, consumes, or
holds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0115AT2ue6x9cT5e5J9SZtCn
@kixelated
kixelated deleted the quest/m2/ts-source-order branch October 27, 2026 20:32
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.

1 participant