Repository navigation
feat(ts): translate the rest of format specs - #136
Conversation
Quest-Claim: a8a25f9a13039018
A precision, widths and precisions from arguments, `+`, `{:x?}` and `{:X?}`,
and `{:b}`, `{:o}`, `{:e}`, and `{:E}` now translate, byte for byte as
core::fmt writes them, proven by differential tests. Only `{:p}` is refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
kixelated
left a comment
There was a problem hiding this comment.
Automated review by review (OpenAI)
Reviewed commit: 77224d0
No actionable bugs found in the reviewed changes. The shared formatting-runtime approach is sound: precision is applied before string padding, integer Debug retains hex options through nested formatting, and decimal-string rounding avoids losing wide-integer precision. Keeping count arguments callable avoids widening every existing formatting-argument array; that complexity is justified. The differential fixtures meaningfully cover indirect counts, evaluation order, rounding ties/carries, and Duration overflow into the next whole second.
Verification limits: static inspection of lowering, runtime helpers, generated fixtures and tests only. I did not run builds, tests, or independently verify the reported differential/mutation results. Pointer formatting and the documented Formatter accessor follow-ups remain outside this change.
# Conflicts: # ts/fixtures/lang/expected/harness.ts # ts/fixtures/lang/src/harness.rs
|
Merged (Written by Claude Opus 5.5) |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Merge summary:
(Written by Claude Opus 5.5) |
Regenerate the durations and reject snapshots, and drop floats.md's link to the ts-fmt-specs quest #136 finished. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem
rust2-ts refused every format spec beyond fill, alignment, width,
#,0,x,X, and?.{:.N?}is the usual way to print aDuration(found by #125), and rust2 aims to support all of std. Closes the questquest/m3/ts-fmt-specs.md.Approach
Each spec goes in the runtime's port of
core::fmt, not into per-type special cases:src/lower/fmt.rs): reads the precision,+,{:x?}/{:X?}, and the indirect-count bits. A count from an argument (Count::Arg) becomesrt.fmtCountOf(arg)in the spec object. The-flag is decoded and dropped, because no std impl reads it.Argument::from_usizelowers tort.fmtCount(n). This panics with std'sFormatting argument out of rangepastu16::MAXand returns anrt.Count: aFmtthat carriescount. Because aCountis aFmt, an arguments array that is not built in place stays typed asrt.Fmt[].fmtPadcuts to the precision in chars before padding, asFormatter::paddoes.bool,char,str,(), the errorDisplays, and a user'sf.padall get this.fmtPadIntegralwrites+.rt/int.ts): each type getsDebug(Display, or hex under{:x?}/{:X?}),Binary,Octal,LowerExp, andUpperExp. Exp is a port ofimpl_Expthat works on decimal digit strings: it rounds half to even to the precision and carries into the exponent.Debugof an integer is nowrt.u8Debugand the like instead ofrt.u8Display.DurationDebug(rt/time.ts): a port offmt_decimal, covering precision, half-to-even rounding that carries into the whole part (up to18446744073709551616spastu64::MAX), zero-fill past 9 digits, and+.library.rs): std's impls ofOctal,Binary,LowerExp, andUpperExpnow route throughfmt::std_impl, so a user impl that forwards to its field translates.Only
{:p}is still refused. The README and the reject fixture now say so.Tests: the
langfixture adds every new spec on every integer width, strings and chars cut by a precision, derivedDebugunder{:x?},{:#X?}, and{:+.1?}, userBinary/Octal/Expimpls, counts by position, by name, and via.*, evaluation order with counts, a count at and pastu16::MAX,{:e}rounding ties and carries, andDurationprecision ties.caller.ts's existing named cases coveru64::MAXseconds with 999,999,999 nanoseconds. I mutation-checked both half-to-even rules: flipping either one fails the differential test.Impact
Debugof an integer callsrt.<int>Debug.Specgainsplus,debugHex, andprecision.rt.Count,rt.fmtCount, andrt.fmtCountOf.rt.<int>Debug,Binary,Octal,LowerExp, andUpperExpfor every integer type.Formatter::padnow honors a precision. That is a fix: it now matches std.Nothing breaks, so there is no
MIGRATE.mdentry.Choices made without asking
Fmtthat carriescount(rt.Count). The alternative was widening theArgumenttype toFmt | number, which would put casts on every array that is not built in place.{:-}is accepted and ignored, as std ignores it.Formatter::precision()andsign_plus()are not mapped because nothing needs them yet. A call to either is still refused with its span.Alternatives
Lowering std's integer formatting from core's MIR was ruled out: it uses
MaybeUninitbuffers and unsafe code, which are outside the subset.Follow-ups
Formatter::precision(),sign_plus(),fill(), andalign(), for user impls that forward options. This needs a consumer first.{:p}remains refused because JS has no addresses.Checks
just checkat the repo root: passes.just ts test: all ts tests pass, including the 50,000-caselangdifferential.ffitests were not run; this PR doesn't touchffi.(Written by Claude Opus 5.5)
🤖 Generated with Claude Code