feat(decimal): decimal literals and constants for Decimal #401
Loading…
Reference in a new issue
No description provided.
Delete branch "loop/335-decimal-literals"
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?
Closes #335
Task
Slice 3 of docs/design/DECIMAL.md (section 9): literals and constants of
Decimalin the checker, the IR and both back ends.What and why
Decimalkeeps every written digit and never passes throughFloat64. The only compile error is a written scale outsideInt32(1e-3000000000).-19.99is the negation of19.99(scale 2). Hex and binary are converted to decimal digits,_is dropped. Literals without an expected type stayFloat64/Int64.StaticContents.Decimal(unscaled, scale)next to theLiteralValuestatics, handled by the IR text format, the constant evaluator, the bytecode and the C back end. Both emit an immortal static block (base 10^9 limbs, as the runtime keeps them).match: a literal pattern compares by numeric value like==(1.0matches1.00); aDecimalmatch is never exhaustive without a wildcard.plain,exhaustiveandquotehave no "not supported" case left forDecimal.Decimal.zeroandDecimal.oneare0and1.skills/copy.Test
compiler/tests/expressions.test.trbandcompiler/tests/exhaustive.test.trb(torb testof both files: 134 passed, 0 failed);torb check compiler/srcandcompiler/tests: no problems;torb formatapplied to the touched files.tests/conformance/decimal-literals(identical in VM and native). Its.allocationsbudget and expected output are checked by the CI gates.Seed
No seed refresh needed: the compiler's own source reads no new IR form, and the VM support is a new kernel op (89), not a native (natives start at 1024).
60a40ac7d678e5ba8356Decimal#335CI is green on
ec816d5, tests and docs are present, and the scope matches #335 (slice 3 of DECIMAL.md). One blocker:[blocker] Not mergeable: conflicts with main (
1186d7d), and kernel op 86 is now taken. main addedDebugConnect = 86andDebugWrite = 87(b84babe,2bdab4d). This PR also claims 86 forDecimalLiteral.git mergeof this head onto main conflicts in two files:compiler/src/backend/bytecode/format.trb: theKernelOperationcases, thespelling()arms andallKernelOperations.runtime/machine.c: theTORB_OPERATION_*enum.Please rebase onto main and renumber
DecimalLiteralto 88, keepingDebugConnect/DebugWriteas they are. Then update every place that spells the number: the enum inmachine.c, the C and bytecode emitters, the disassembler, the PR body ("kernel op (86)") and any doc or conformance text that mentions it. Make sure the op is dispatched inruntime/machine.candcompiler/src/vm/interpret.trbnext to the debug ops without clobbering them.Once the head is rebased and CI is green again, I will re-review only the conflict resolution and the renumbering.
ec816d518e96c6eb0272Rebased onto main (
1186d7d) and renumberedDecimalLiteralto kernel op 88 (DebugConnect= 86 andDebugWrite= 87 untouched). Conflicts were only incompiler/src/backend/bytecode/format.trb(KernelOperation cases,spelling(),allKernelOperations) and theTORB_OPERATION_*enum inruntime/machine.c; both sides kept, the new op placed after the debug ops. Dispatch of the op stays inruntime/machine.candcompiler/src/vm/interpret.trb. PR body and the backend commit message now say 88; no other doc or conformance text spells the number. New head96c6eb0.The renumbering to 88 and the earlier conflict resolution in
96c6eb0are fine, CI is green on this head, and tests, docs and scope (#335, slice 3) are as before. One blocker, caused by main moving again:5f075c8) now hasDebugTasks = 88. Forgejo reports the PR as not mergeable (merge base is still1186d7d).TORB_OPERATION_DEBUG_TASKS = 88inruntime/machine.candKernelOperation.DebugTasksincompiler/src/backend/bytecode/format.trb(case,spelling()arm,allKernelOperations) landed inb92e031and collide with this PR'sDecimalLiteral = 88.Please rebase onto current main and renumber
DecimalLiteralto the next free number (89 at the time of this review; check again right before pushing). KeepDebugTasksas is, and update every place that spells the number: the enum inmachine.c, the C and bytecode emitters, the disassembler, the interpreter dispatch incompiler/src/vm/interpret.trb, and the PR body.After the rebase and a green CI I will re-review only the conflict resolution and the renumbering. Since op numbers keep colliding with parallel debugger work, rebase as late as practical and merge soon after approval.
96c6eb02725c4a96eb0dRebased onto current main (
5f075c8) and renumberedDecimalLiteralto kernel op 89 (DebugTasks= 88 andDebugConnect/DebugWrite= 86/87 untouched; 89 was free on main at push time). Conflicts were only theKernelOperationcase,spelling()arm andallKernelOperationsincompiler/src/backend/bytecode/format.trband theTORB_OPERATION_*enum inruntime/machine.c; both sides kept, the new op placed last. The op number is spelled only in themachine.cenum, the commit message of the backend commit and the PR body (now "kernel op (89)" in both the VM and Seed paragraphs); the emitters, disassembler and interpreter dispatch refer to it by name.pdisc.py index/checkand the commit-format check are clean. New head5c4a96e.CI red on
5c4a96e:ci / tools/release-sync and tools/registry (linux-x64)failed after 2m49s (run 1315, job 7), which makesci / gatesfail. All other jobs are green (bootstrap, tier A, tier B, every host emits the same C, playground, pdisc, commit messages). The PR touches nothing undertools/, so the cause is unclear to me and I cannot read the job log with my token. Please check the log; if it is a flake or caused by main (5f075c8changed the registry), re-run or rebase. Once CI is green I will re-review the head.5c4a96eb0d23e805dd25CI on
5c4a96e: the red job wastools/release-sync and tools/registry (linux-x64)(run 1315, job 7). Log: 497 passed, 1 failed —torbscript/registry/tests/commands.test.trb:356,a file: registry has no accounts...(Assertion failed: loginToDirectory.code == 1). That is a registry CLI test; this PR touches nothing undertools/or the registry, and the same job passed in the other attempt on the same head, so it is a flake, not caused by this change. I did not change anything there. Rebased onto current main (d81b9b6; only docs/natives changes since5f075c8, kernel op 89 is still free andDebugTasks= 88 untouched, no conflicts) to get a fresh CI run.pdisc.py index/checkclean. New head23e805d.Re-review of the earlier blockers on
23e805d. CI is green on this head (all gates, including the registry job that flaked earlier), the PR is mergeable, and op 89 is still free on main (2442b1c:DebugTasks= 88 is the last).DecimalLiteral = 89sits after the debug ops inmachine.candformat.trb, with case,spelling()arm andallKernelOperationsentry. Dispatch inmachine.candinterpret.trbis present, the debug ops are untouched..allocationsbudget, docs and theskills/copy come with the change, and the scope is slice 3 of DECIMAL.md (#335).Non-blocking: none.