Skip to content

feat(ts): map a tail, an argument, and what follows a call to the Rust that made them - #520

Merged
moq-bot[bot] merged 8 commits into
mainfrom
quest/m3/ts-span-precision
Nov 3, 2026
Merged

moq-bot[bot] merged 8 commits into
mainfrom
quest/m3/ts-span-precision

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Completes quest/m3/ts-span-precision.md.

Problem

When tsc rejects translated output, #376 reports the error at the last source-map token before it. The map was coarse:

  • A function's or closure's tail return mapped to the body's closing }. tsc reports a mistyped return at the return keyword.
  • Most assignments and declarations had no mapping, so an error there mapped to whatever call was printed before it.
  • A call's arguments, and the text after a nested call or closure, mapped to the last call printed. For example, rt.lt and 0 in unwrapOr(iterMax(iterMap(v, (x) => {...}), rt.lt), 0) mapped into the closure.

Approach

  • A temporary held back to fold into a later expression records the loc of the MIR statement or terminator that made it. When it folds in as a call or new, it is Located there. So an argument made by a call maps to that argument's Rust, and a tail folded into return maps to the tail expression.
  • return takes the loc of the tail it returns (held back, or folded from x = v; return x). The body's end is used only when nothing is held.
  • A flushed temporary, and an assignment or effect set_local emits, take their statement's loc.
  • The printer maps the text after a Located expression back to the node that encloses it, and replaces a mapping at the same position instead of adding a second one.
  • Printer fix the new Located nodes require: a Located expression that needed grouping was printed with two pairs of parens (((b as rt.u16)) << 8), and !, &&, and the bitwise grouping checks didn't look through Located. The only change to the .ts text is the removal of those redundant parens: 390 snapshot lines, with nothing else changed (checked by diffing each line with parens stripped).

Proof: no Rust construct still reaches a real tsc failure. #375 removed the last one, and I probed about 70 candidates (generic runs at u8, iterators, closures, dyn, async, std mappings) without finding one. So the new spans test translates reject/spans.toml, then reruns the driver with a stand-in tsc on PATH. The stand-in reports an error where tsc reports a mistyped return (the keyword) and argument (its start). Those go through check.rs unchanged, and reject/spans.txt snapshots each reported span, keyed by item, as rejected() does.

Measured on moq's codec translation (moq/ts.toml, pinned rev, release build, 5 alternating runs each):

base this PR
.ts.map bytes 161,543 164,193 (+1.6%)
.ts bytes 159,490 159,488
wall time, median 11.7 s 12.0 s (runs spread 10.8 to 14.4 s)

Impact

  • The translator's error spans for tsc failures in translated code are finer, as are the source maps. No public API change, so no MIGRATE.md entry.
  • Output text: redundant parens removed as above.

Alternatives

  • Locating every argument operand at its MIR Spanned span. This would also map a bare name or an operator argument (such as the receiver m in Meter.scaled(m, ...)) to itself. It means wrapping names and operators in Located, and several passes match on those shapes: wrapping members and binaries changed fold decisions (for example fmt's spills). Such an argument still maps to the call it is passed to (the method name), which is where tsc's signature error belongs.
  • Mapping a call to its whole expression (the receiver's start) instead of the method name. In a chain like v.iter().map(..).sum(), every call would map to v.
  • Mapping back to the enclosing node after each statement as well as each expression: +2.8% map size for little gain, since statements now carry their own loc.

Choices made without asking: the stand-in tsc test in place of reject cases from a real typing gap, since none exists; the parens fix in the printer.

Follow-ups

None.

Checks

just ci passed locally on 45354a9 (after merging origin/main at b3c1195).

Review

mechanical fix by quest land watch: merged main at 572f8256d34496ed509018e370195f7f8a2a09f1 with the quest merge driver (head 4e3408f)

(written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 5 commits November 3, 2026 02:28
…t that made them

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… snapshot

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Type errors at the Rust that made them feat(ts): map a tail, an argument, and what follows a call to the Rust that made them Nov 3, 2026
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 14:25
@coderabbitai

coderabbitai Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 31a22c1b-d452-49f8-91fe-183025d69c87
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

CodeRabbit Verify

  • Run CodeRabbit Verify to test the changes in this pull request.

@kixelated
kixelated enabled auto-merge November 3, 2026 14:32
@kixelated
kixelated added this pull request to the merge queue Nov 3, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Nov 3, 2026
@moq-bot

moq-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

quest land watch: the merge queue removed this pull request at 45354a9 because it conflicts with main (merge_conflict).

The land fixer works on it in the background, and the watcher re-enqueues it at the back of the queue once it is fixed or judged flaky, or hands it back here with what it needs.

(written by quest land watch)

@moq-bot
moq-bot Bot enabled auto-merge November 3, 2026 14:38
@moq-bot

moq-bot Bot commented Nov 3, 2026

Copy link
Copy Markdown

quest land watch: armed auto-merge on this pull request at 4e3408f, so it joins the back of the merge queue once its required checks pass, with main at 572f825 merged in by the quest merge driver.

(written by quest land watch)

@moq-bot
moq-bot Bot added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit d808a2b Nov 3, 2026
5 checks passed
@moq-bot
moq-bot Bot deleted the quest/m3/ts-span-precision branch November 3, 2026 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant