decimal: std surface, conversions, Encode/Decode Exact and conformance programs #336
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Last step of the epic #34, after #332, #334 and #335 (all merged).
Goal
What is left of
Decimalafter the runtime, the std surface ofstd/numberand the literals landed: the encoding side and the status.EncodedValuegets the caseExact(value: Decimal)that ENCODING.md section 7 declares, JSON keeps the digits of a number it reads into aDecimal, and the docs stop saying "planned". Specification: DECIMAL.md sections 11 and 14 (slice 4), ENCODING.md section 7 and section 16 item 3, RELEASE.md 1.0 list, FIRST-PARTY.md gap 12.Already on
main(checked 2026-10-28, not part of this issue):rounded,divided,scale,normalized,unscaledText,Decimal.of,Decimal.from(Int64/UInt64),Decimal.tryFrom(String),Int64/UInt64.tryFrom(Decimal),Float64.from(Decimal),Rounding,Show,Hash, noDecimalentry leftPlannedincompiler/src/backend/c/natives.trb, the conformance programstests/conformance/decimal-arithmeticanddecimal-literals(rows of DECIMAL.md section 12 for text, equality,+ - * / %, both rounding tables, conversions).Design (decided by the loop, see the comment below)
EncodedValue.Exact(value: Decimal)is added afterFloat(order as in ENCODING.md section 7).Values.decimalcompletes it,ValueDecoder.decimalreads it (and keeps readingString,Int,Floatas today),show()/plain()print theDecimalunquoted,EncodeforEncodedValuecallstarget.decimal.ValueDecoder.float/numberaccept anExactthroughFloat64.from,intonly a whole number in range.Decimalas the number token with theshow()text (already so). JSON reading: a number token with fraction or exponent stays anEncodedValue.Floatwhen printing the parsedFloat64gives the token back, and becomesEncodedValue.Exactotherwise (19.90,0.1234567890123456789), so ordinary floats and the existing tests keep their shape and aDecimalfield never goes through a lossyFloat64. Integers keepInt/Unsigned.Decimalfrom its text (std/yaml/src/decoder.trb); only tests and, for the generic tree, the same rule as JSON (resolve.trb).Decimalis written as a string and read back from a string, exact. A TOML float token read into aDecimalgoes through its shortestFloat64text; this is documented, not changed.std/sandboxcrossing gets a tag forExact(text form). Every othermatchoverEncodedValueinstd/is made exhaustive.SqlValue.Numeric, FIRST-PARTY gap 12 is closed by this issue only for the language side),Powerand roots, locale formatting.Acceptance criteria
EncodedValue.Exactexists;Values,ValueDecoder,Show/plain,EncodeforEncodedValue, sandbox crossing,std/uriandstd/expressionhandle it;torb ir --statistics .no longer counts the threeDecimalfindings for encoding.Decimalfield exactly:Price(amount: 19.90)writes and reads back19.90(scale kept), a value of 40 digits and a negative scale (1e3) survive; JSON also reads a hand-written{"amount": 19.90}and{"amount": 0.1234567890123456789}exactly and refuses a string. Tests instd/json,std/yaml,std/tomlandstd/encoding(*.test.trb).Float64(1.5) is stillEncodedValue.Floatin JSON and YAML (existing tests unchanged).tests/conformance/decimal-encoding.trb(with.expected,.exit,.allocationslike its neighbours) with identical output in VM and native.ir --statisticsnote updated;DECIMAL.mdstatus line "built" with the slice table done;language/values-and-types/decimal.mdstatus: plannedtostablewithout the banner; ROADMAP "planned natives" and RELEASE.md/FIRST-PARTY.md Decimal rows marked done;torb docs skill docs skillsregenerated andskills/committed.Seed impact
No new native, no syntax change, no renamed std name. The compiler finds
EncodedValuecases by name (variantNamedinir/lower/quoted.trb, the casesInt,Float,Bool,String,Nothing), so an added case is additive. The implementer still checks withtorb ir --statistics .that the compiler's own program, which linksstd/encoding, builds with the published seed: if it does not, apply the two-commit rule ofCLAUDE.md"Seed and breaking changes" (teach the form, refresh the seed by Torben, then migrate); the loop does not refresh the seed.Size
One PR, two commits:
feat(encoding): EncodedValue.Exact and exact Decimal in JSON, YAML, TOML(with tests and the conformance program),docs(number): Decimal is stable(statuses, regeneratedskills/).Decimalthat computes #34[loop:torbscript] refine: slice 4 of #34, next: waiting (dependency #335)
Decimalthat computes #34Decimalthat computes #34Decimalthat computes #34[loop:torbscript] decided by the loop: refined to the part that is really open (the std surface, natives and the arithmetic conformance programs are already on
main); body rewritten with testable criteria, design forEncodedValue.Exactand JSON reading, seed impact (none expected, re-check withir --statistics .) and size (one PR, two commits). Reasoning in the comment on #34. Next: ready.Decimalthat computes #34[loop:torbscript] claim implement by session:loop-torbscript-20261028 until 2026-10-28T19:56:27Z
[loop:torbscript] implement: PR #544 open (feat(encoding) + docs, two Conventional Commits, Closes #336); fast CI checks green (commit messages, change scope, pdisc), the heavy jobs (gates, bootstrap, tiers, cross builds) still queued at handoff; worker hit its 30 min budget while waiting on CI, worktree cleaned. Worker usage: 1 run, 30 min (token count not reported). next: waiting (CI on PR and merge gate)
[loop:torbscript] claim review by session:loop-torbscript-20261028 until 2026-10-28T19:38:19Z
[loop:torbscript] review: tier A (linux-x64) was red on
d0bc3307because of a real defect in the PR, not main or a flake:Json().encode price,Yaml().encode priceandEncodedValue.Exact(..).encode builderdo not parse as command calls (receiver is a call expression), which brokecheck ., the std/example tests, the repository typing test anddoc --check std; plustorb format --checkon four new decimal tests and two stale generated indexes (docs/language/values-and-types/index.md, skills references index). Fixed: parenthesisedencode(...)calls in std/encoding/tests/decimal.test.trb and tests/conformance/decimal-encoding.trb, formatter run on the six touched test files,torb docs indexandtorb docs skillregenerated. Commits11226d86(test(encoding)) anda8228be9(docs), normal push, no rewrite. Locally only format --check and check on the two fixed files (clean), no suite. next: waiting (CI on PR #544 and merge gate)Decimalthat computes #34Decimalthat computes #34