Skip to content

feat(ts): format Arc as what it holds, and std's ranges with Debug - #247

Merged
kixelated merged 6 commits into
mainfrom
quest/m3/ts-fmt-wrappers
Oct 30, 2026
Merged

kixelated merged 6 commits into
mainfrom
quest/m3/ts-fmt-wrappers

Conversation

@kixelated

@kixelated kixelated commented Oct 30, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

rust2-ts refused Debug and Display of Arc<T> for every T, and Debug of std's ranges, so a crate that prints either could not translate (quest/m3/ts-fmt-wrappers.md, suggested by #177 and #179).

Approach

  • Arc<T> and Rc<T> (both rt.Arc) write .value through T's Display or Debug with the same formatter, as std's impls forward, so every option reaches T. Other traits stay refused, as std has no such impls.
  • Each range shape gets a runtime Debug (rt.fmtRange, fmtRangeInclusive, fmtRangeFrom, fmtRangeTo, fmtRangeToInclusive, fmtRangeFull) that writes each bound with the range's formatter and the unpadded .. or ..= between, as core does. RangeInclusive adds (exhausted) from its exhausted flag.
  • A .. constant now translates to undefined, as a RangeFull value already is. Before this, format!("{:?}", ..) was refused.
  • The runtime's RangeInclusive already keeps the pinned nightly's state: start steps past end and only overflow sets exhausted. core changed this after 1.98, so printing the fields matches native output.

Tests: a new fmt::wrapped case in the lang differential (native wasm32 vs translated, 50k cases) covers:

  • every range shape with width, fill and alignment, +, 0, x?/X?, #?, and a width taken from an argument
  • a range of a custom Debug that pads, so width and precision reach the bounds, and that shows #
  • ranges of Hex and of a derived Debug under {:#?}
  • inclusive ranges drained by next, at the type's top, by next_back, and by nth
  • Arc<Hex>, Arc<Arc<i32>> with sign, zero, hex, and alternate flags, Rc<String> with precision, Arc<Vec<Pair>> pretty, Arc<str>, a range of Arcs, and a derived Debug struct holding an Arc and ranges

A mutation that rewrote (exhausted) made the differential fail on 411 cases.

Impact

  • Translator output: Debug and Display of Arc/Rc, and Debug of every std range, now translate instead of being refused. A .. constant translates.
  • Runtime: new exports fmtRange, fmtRangeInclusive, fmtRangeFrom, fmtRangeTo, fmtRangeToInclusive, and fmtRangeFull. Nothing breaks.

Alternatives

  • One runtime function taking optional bound thunks for every shape. Dropped because per-shape functions type their receivers directly and read more plainly.

Choices made without asking

  • Rc formats the same as Arc, since the translator maps both to rt.Arc.
  • Added the RangeFull constant fix in this PR, because formatting .. needs it.

Follow-ups

  • Arc<dyn Debug> is still refused at construction (a std trait object behind Arc), with a span. That is trait-object work, not formatting.
  • RangeInclusive::new with operands that drop (Arc::new(a)..=Arc::new(b)) is refused with a span. The fixture uses a Range of Arcs instead.

Review

Head 8c033c389625ce9a85c20780e087f984409e724a: review skipped as a trivial merge. It merges origin/main (b29d80fd) into the reviewed head 44a7bef667bbe46f8d4a130f327d8e0ed9e1edfb, then merges the branch's own earlier base merge (b2fbaefa, #249), which leaves the tree unchanged. The conflict in ts/fixtures/lang/expected/harness.ts was resolved by regenerating snapshots with UPDATE_EXPECT=1, not by hand. The quest file stays deleted, since main only rewrote its links. The changes to ts/src, ts/runtime, and the fixture sources are identical to the reviewed head's, apart from hunk offsets. just ci passed locally on this tree.

Earlier round: Codex quest review (gpt-6.1-sol, medium effort), round 1 on 44a7bef6 against f78c588f: no findings.

Merge of main at 32f651c46d1d9381160526d5b456a5a2dcfcaf54: git merged it without conflicts; it only refreshes the base so GitHub can merge, with no change to this PR's diff since 8c033c38, so it is a recorded skip, too trivial to review.

🤖 Generated with Claude Code

(written by Claude Opus 5.5)

kixelated and others added 2 commits October 29, 2026 19:44
`Arc<T>` and `Rc<T>` write their value with `Display` and `Debug` under the same
formatter, and each std range writes its bounds with the range's options, plus
` (exhausted)` once iteration exhausts an inclusive one. A `..` constant
translates to `undefined`, as a `RangeFull` value is.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Debug and Display of Arc and ranges feat(ts): format Arc as what it holds, and std's ranges with Debug Oct 30, 2026
@kixelated
kixelated marked this pull request as ready for review October 30, 2026 03:13
@coderabbitai

coderabbitai Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

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: 0781374a-2849-43f1-8a8a-4e1045db3ea7
Commits

Reviewing files that changed from the base of the PR and between 3c4fb50 and 32f651c.

Files selected for processing: 12
  • quest/m3/README.md
  • quest/m3/ts-fmt-wrappers.md
  • ts/fixtures/lang/expected/fmt.Clip.ts
  • ts/fixtures/lang/expected/fmt.Shared.ts
  • ts/fixtures/lang/expected/fmt.ts
  • ts/fixtures/lang/expected/harness.ts
  • ts/fixtures/lang/expected/lib.ts
  • ts/fixtures/lang/src/fmt.rs
  • ts/fixtures/lang/src/harness.rs
  • ts/runtime/rt.ts
  • ts/src/lower/consts.rs
  • ts/src/lower/fmt.rs
  • 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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 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-30T04:09:49.363956Z b2fbaef New commits
🔒 Security Review ✅ Completed 2026-10-30T04:10:18.724751Z b2fbaef 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.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed commit: 44a7bef667bbe46f8d4a130f327d8e0ed9e1edfb.

No actionable bugs found in the changed formatting paths. Arc/Rc forwarding reuses the inner value and formatter without changing ownership, and the range helpers preserve bound formatting options, delimiter order, and early error returns. The inclusive suffix uses the existing exhaustion state, while RangeFull constants now match its existing runtime representation. The per-shape helpers are a reasonable, small alternative to a more general formatting abstraction.

Nonblocking coverage suggestion: add a custom bound whose Debug returns an error, and print an inclusive range exhausted through fold as well as next/next_back/nth. These exercise early termination and the runtime's separate folded exhaustion path.

Verification limits: static diff, lowering/runtime context and generated fixture review, plus an independent read-only pass. I did not execute the differential suite, mutation test, or reported local checks, and do not claim they passed.

(Written by OpenAI)

# Conflicts:
#	quest/m3/ts-fmt-wrappers.md
kixelated added a commit that referenced this pull request Oct 30, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated added a commit that referenced this pull request Oct 30, 2026
* quest: plan follow-ups of #237 and #241

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

* quest: fold #247's follow-ups into ts-dyn and ts-drop-order

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

---------

Co-authored-by: Luke Curley <432854+kixelated@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated merged commit 6c3fd5a into main Oct 30, 2026
2 checks passed
@kixelated
kixelated deleted the quest/m3/ts-fmt-wrappers branch October 30, 2026 05:43
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