Skip to content

Commit bcb2a97

Browse files
committed
feat(cli): add bounded exact decimal arithmetic and pull range
1 parent 1e82158 commit bcb2a97

24 files changed

Lines changed: 6964 additions & 61 deletions

‎Documentation/Architecture/ExtractionManifest.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,5 +209,8 @@
209209
"framework_boundary": "Conditional CoreTransferable/UniformTypeIdentifiers plus a narrow explicit main-actor Apple PDF boundary using WebKit, CoreText, CoreGraphics and AppKit/UIKit paragraph styles. Core JSON imports none of these; no new root dependency.",
210210
"rtf": "Original bounded strict-token emitter; AppKit/UIKit native decoding only in tests and qualification consumers, not generation.",
211211
"pdf": "Original invocation-owned lifecycle, finite adapter accounting and visible-range pagination using Apple SDK APIs. PDFKit is independent qualification only; no third-party renderer adapted."
212-
}
212+
},
213+
"original_notes": [
214+
"1.4 C3 decimal magnitude, rational/quantization kernel, pull range and type-directed overloads are original Apache-2.0 code. The 738-case deterministic oracle uses Python integer/Fraction arithmetic; no jq/Rhoe arithmetic implementation was copied."
215+
]
213216
}

‎Documentation/Architecture/Release1.4/Acceptance.json‎

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"schema": "swift-json-cli-acceptance/1",
33
"prepared": "2026-10-14",
4-
"implementation_status": "Foundation and pull query-core milestones; complete C0-C5 integration remains unqualified",
4+
"implementation_status": "Foundation, query core and exact arithmetic milestones; C4/C5 integration remains unqualified",
55
"requirements": [
66
{
77
"id": "CL001",
@@ -666,14 +666,18 @@
666666
"title": "Exact add/subtract/multiply",
667667
"verification": "Carry/borrow/sign/zero/large integer cases against independent exact expectations.",
668668
"obligation": "mandatory",
669-
"status": "not_run",
669+
"status": "passed",
670670
"evidence_required": true,
671671
"fixture_ids": [
672672
"Cartesian-add-order",
673673
"exact-large-integer",
674674
"exact-decimal-add",
675675
"exact-borrow",
676676
"exact-multiply"
677+
],
678+
"evidence": [
679+
"Documentation/Architecture/Release1.4/Arithmetic.md",
680+
"Documentation/Architecture/Release1.4/Qualification.md"
677681
]
678682
},
679683
{
@@ -682,20 +686,28 @@
682686
"title": "Numeric admission and lexemes",
683687
"verification": "Computed values normalized with no false originalLexeme; untouched inputs preserve spelling.",
684688
"obligation": "mandatory",
685-
"status": "not_run",
689+
"status": "passed",
686690
"evidence_required": true,
687-
"fixture_ids": []
691+
"fixture_ids": [],
692+
"evidence": [
693+
"Documentation/Architecture/Release1.4/Arithmetic.md",
694+
"Documentation/Architecture/Release1.4/Qualification.md"
695+
]
688696
},
689697
{
690698
"id": "CL047",
691699
"gate": "C3",
692700
"title": "Terminating exact division",
693701
"verification": "Reduced denominators containing only2/5, large common factors and mixed signs.",
694702
"obligation": "mandatory",
695-
"status": "not_run",
703+
"status": "passed",
696704
"evidence_required": true,
697705
"fixture_ids": [
698706
"terminating-division"
707+
],
708+
"evidence": [
709+
"Documentation/Architecture/Release1.4/Arithmetic.md",
710+
"Documentation/Architecture/Release1.4/Qualification.md"
699711
]
700712
},
701713
{
@@ -704,10 +716,14 @@
704716
"title": "Repeating division default",
705717
"verification": "1/3 and repeating values give language inexactDivision; no floating fallback.",
706718
"obligation": "mandatory",
707-
"status": "not_run",
719+
"status": "passed",
708720
"evidence_required": true,
709721
"fixture_ids": [
710722
"repeating-division-error"
723+
],
724+
"evidence": [
725+
"Documentation/Architecture/Release1.4/Arithmetic.md",
726+
"Documentation/Architecture/Release1.4/Qualification.md"
711727
]
712728
},
713729
{
@@ -716,12 +732,16 @@
716732
"title": "Explicit scale/half-even",
717733
"verification": "Required option pair, decimal places, finite caps, signed ties and report rounding counts.",
718734
"obligation": "mandatory",
719-
"status": "not_run",
735+
"status": "passed",
720736
"evidence_required": true,
721737
"fixture_ids": [
722738
"rounded-third",
723739
"half-even-ties",
724740
"scale-pair-required"
741+
],
742+
"evidence": [
743+
"Documentation/Architecture/Release1.4/Arithmetic.md",
744+
"Documentation/Architecture/Release1.4/Qualification.md"
725745
]
726746
},
727747
{
@@ -730,11 +750,15 @@
730750
"title": "Zero division and integral remainder",
731751
"verification": "Typed catchable domain errors; signed truncated remainder; fractional remainder rejected.",
732752
"obligation": "mandatory",
733-
"status": "not_run",
753+
"status": "passed",
734754
"evidence_required": true,
735755
"fixture_ids": [
736756
"negative-remainder",
737757
"fractional-remainder-rejected"
758+
],
759+
"evidence": [
760+
"Documentation/Architecture/Release1.4/Arithmetic.md",
761+
"Documentation/Architecture/Release1.4/Qualification.md"
738762
]
739763
},
740764
{
@@ -743,12 +767,16 @@
743767
"title": "Exact numeric builtins",
744768
"verification": "abs/floor/ceil/trunc/round/range/add with negative and empty/domain cases; round ties away from zero.",
745769
"obligation": "mandatory",
746-
"status": "not_run",
770+
"status": "passed",
747771
"evidence_required": true,
748772
"fixture_ids": [
749773
"round-away-from-zero",
750774
"range-negative-step",
751775
"range-zero-step"
776+
],
777+
"evidence": [
778+
"Documentation/Architecture/Release1.4/Arithmetic.md",
779+
"Documentation/Architecture/Release1.4/Qualification.md"
752780
]
753781
},
754782
{
@@ -757,10 +785,14 @@
757785
"title": "Exponent/growth preflight",
758786
"verification": "Large sparse exponent operations fail finite caps before dense allocation; exact zero shortcut allowed.",
759787
"obligation": "mandatory",
760-
"status": "not_run",
788+
"status": "passed",
761789
"evidence_required": true,
762790
"fixture_ids": [
763791
"exponent-gap-cap"
792+
],
793+
"evidence": [
794+
"Documentation/Architecture/Release1.4/Arithmetic.md",
795+
"Documentation/Architecture/Release1.4/Qualification.md"
764796
]
765797
},
766798
{
@@ -769,29 +801,41 @@
769801
"title": "Numeric work and cancellation",
770802
"verification": "Charged GCD/division/carry inner loops; boundaries and checkpoint cancellation; terminal errors not catchable.",
771803
"obligation": "mandatory",
772-
"status": "not_run",
804+
"status": "passed",
773805
"evidence_required": true,
774-
"fixture_ids": []
806+
"fixture_ids": [],
807+
"evidence": [
808+
"Documentation/Architecture/Release1.4/Arithmetic.md",
809+
"Documentation/Architecture/Release1.4/Qualification.md"
810+
]
775811
},
776812
{
777813
"id": "CL054",
778814
"gate": "C3",
779815
"title": "32-bit arithmetic safety",
780816
"verification": "No Int/UInt64 negation/narrowing/product overflow traps; wasm32 kernel tests or explicit gate blocker.",
781817
"obligation": "mandatory",
782-
"status": "not_run",
818+
"status": "partial",
783819
"evidence_required": true,
784-
"fixture_ids": []
820+
"fixture_ids": [],
821+
"evidence": [
822+
"Documentation/Architecture/Release1.4/Arithmetic.md",
823+
"Documentation/Architecture/Release1.4/Qualification.md"
824+
]
785825
},
786826
{
787827
"id": "CL055",
788828
"gate": "C3",
789829
"title": "No Decimal/Double authority",
790830
"verification": "Source audit plus precision cases prove no foreign arithmetic/fallback authority.",
791831
"obligation": "mandatory",
792-
"status": "not_run",
832+
"status": "passed",
793833
"evidence_required": true,
794-
"fixture_ids": []
834+
"fixture_ids": [],
835+
"evidence": [
836+
"Documentation/Architecture/Release1.4/Arithmetic.md",
837+
"Documentation/Architecture/Release1.4/Qualification.md"
838+
]
795839
},
796840
{
797841
"id": "CL056",
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Exact filter arithmetic
2+
3+
C3 builds on query core 6e8f145 / draft PR #24. Original private code implements
4+
base-ten unsigned working magnitudes plus native sign/coefficient/exponent values.
5+
No Double, Float or Foundation Decimal is an arithmetic authority. Numeric binary
6+
operators clear originalLexeme and normalize computed zero. Untouched selected
7+
values preserve their admitted spelling; null's identity overload selects a value.
8+
9+
Addition bounds exponent alignment before dense storage. Schoolbook multiplication
10+
uses UInt16: digit product + stored digit + carry <=99; addition <=19. Subtraction
11+
fits Int16. Long division maintains r<divisor before consuming the next digit, so
12+
a quotient digit is <=9. GCD reduces exact rationals; only 2/5 denominator factors
13+
produce a default finite decimal. Repeating division raises catchable inexactDivision;
14+
zero division and fractional remainder are distinct catchable domain errors.
15+
All loops spend numeric work, including normalization, factor removal and carries.
16+
17+
Normalized coefficient drafts retain their buffer lease through full result admission;
18+
withExtendedLifetime prevents an optimized-away lease from refunding a still-live
19+
number alias. Working storage has invocation leases and a checked 2*numberDigits+2 scratch
20+
bound; that is a derived storage bound, not an iteration guard. Result digits,
21+
exponent and normalized token bytes retain independent native limits. Host-index
22+
narrowing is checked before allocation. A 1e1000000+1 probe fails before dense
23+
storage; multiplication by zero uses exact sparse computation. Numeric work and
24+
retention cap/cap-minus-one checks exercise actual operations. A 300-digit product
25+
is cancelled after 5,000 charged units inside its nested multiply loop and reclaims
26+
all scratch while retaining terminal health. wasm32 execution is still a gate.
27+
28+
`--division-scale N --rounding half-even` is an explicit pair. It quantizes every
29+
numeric division, including finite values; reports count nonzero discarded
30+
remainders. Builtin round instead uses ties away from zero. The cumulative report
31+
uses totalInputBytes/totalOutputBytes/totalWorkUnits and preserves completed versus
32+
terminal failure. Diagnostics carry metric/limit/attemptedUsage/overflow and source
33+
byte offsets when known. Version 1 limits files may omit the version field.
34+
35+
String/array/object operator overloads preserve exact scalar/key identity, bounded
36+
collection ownership and insertion order. Recursive object merge uses an explicit
37+
stack. Range yields one exact step at a time with end-exclusive comparison and a
38+
nonzero step; it does not allocate a complete output array or impose a hidden
39+
10,000-step cap. All arguments/replays and resulting collectors remain finite.
40+
41+
Independent fixture generator: Python integers/fractions.Fraction, seed 0x140C3,
42+
738 cases, SHA-256 57b2affc52c872fdbc9e6cb25168bdd8b5999db6d8e5d8a988ff99cbf2c7accb.
43+
Ten arithmetic tests and 17 authored C3 subprocess vectors pass. Full native,
44+
safety and DocC refresh passed on the corrected handoff source; see Qualification.md.
45+
The authored fixture bytes remain unchanged. Vector invocation adds the documented
46+
`--` terminator so negative-leading filters are operands, keeping unknown flags
47+
strict. The initial two argv failures are retained, not counted as successes.
48+
49+
Review corrected a prototype probe expecting 2*D+2 overflow for D<Int.max:
50+
on 64-bit that expression still fits UInt64. The final test instead proves a small
51+
allocation under a large finite D works, then rejects Int.max at the actual host
52+
allocation boundary; no configuration or test was weakened to hide a real overflow.
53+
54+
Release-mode integration caught an actual domain-handoff issue after coefficient
55+
leases were extended: output's scratch baseline included queued refunds, then an
56+
inner checkpoint drained them. The job domain handoff now drains refunds before
57+
new-stage baselines. A regression verifies the live result remains charged while
58+
dead drafts disappear and work never refunds. The failed native receipt/vectors
59+
remain retained; refreshed lanes are required after this correction.

‎Documentation/Architecture/Release1.4/Progress.json‎

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"target_release": "1.4.0",
44
"renderer_base": "3c1e8a1a1bc8d03699665b8ab98f5ece7962aff7",
55
"main_at_orientation": "25fb04f747e583209b4c4511abf39e11ef5b4f80",
6-
"branch": "codex/1.4-json-cli-query-core",
7-
"status": "Native pull query-core milestone qualified; complete C0-C5 integration remains open",
6+
"branch": "codex/1.4-json-cli-exact-arithmetic",
7+
"status": "Native exact-arithmetic milestone qualified; wasm32 arithmetic and complete C4/C5 remain pending",
88
"gates": {
99
"C0": "partial",
1010
"C1": "partial",
1111
"C2": "partial",
12-
"C3": "not_run",
12+
"C3": "partial",
1313
"C4": "not_run",
1414
"C5": "not_run"
1515
},
@@ -21,9 +21,9 @@
2121
"core_metrics": 49,
2222
"cli_metrics": 16,
2323
"publication_performed": false,
24-
"root_test_functions": 256,
24+
"root_test_functions": 266,
2525
"root_parameter_cases": 199,
26-
"native_source_manifest_sha256": "c8f09d2eaa6cf14f3efb11e8a2645796075c54274fa6b8af9db464fe27b173aa",
26+
"native_source_manifest_sha256": "33439f5716ac7e33e01e477db4cb018547618fa7b74885867bb2b290ba43d7e0",
2727
"qualified_lanes": [
2828
"native",
2929
"safety",
@@ -53,10 +53,32 @@
5353
"root_test_functions": 232,
5454
"root_parameter_cases": 177,
5555
"native_source_manifest_sha256": "864d9b3dd8e1d79a0a6cbec862476843ddca2ff8a1582471b80fba54b863459e"
56+
},
57+
{
58+
"branch": "codex/1.4-json-cli-query-core",
59+
"status": "Native pull query-core milestone qualified; complete C0-C5 integration remains open",
60+
"gates": {
61+
"C0": "partial",
62+
"C1": "partial",
63+
"C2": "partial",
64+
"C3": "partial",
65+
"C4": "not_run",
66+
"C5": "not_run"
67+
},
68+
"root_test_functions": 256,
69+
"root_parameter_cases": 199,
70+
"native_source_manifest_sha256": "c8f09d2eaa6cf14f3efb11e8a2645796075c54274fa6b8af9db464fe27b173aa"
5671
}
5772
],
5873
"query_functions": 24,
5974
"query_parameter_cases": 22,
6075
"query_vectors": 38,
61-
"query_vectors_passed": 38
76+
"query_vectors_passed": 38,
77+
"arithmetic_functions": 10,
78+
"arithmetic_oracle_cases": 738,
79+
"arithmetic_oracle_sha256": "57b2affc52c872fdbc9e6cb25168bdd8b5999db6d8e5d8a988ff99cbf2c7accb",
80+
"arithmetic_vectors": 17,
81+
"arithmetic_vectors_passed": 17,
82+
"cli_site_checks": 18,
83+
"cli_site_metrics": 16
6284
}

‎Documentation/Architecture/Release1.4/Qualification.md‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,35 @@ FileHandle.standardError. No unsafe annotation/flag or library behavior changed.
8989
Failed run 38593758299 and its actual compiler log are retained; a fresh hosted
9090
run is required before Linux closure. Local comparator rebuild and all 38 C2
9191
vectors verify the diagnostic-only fix on the supported Mac.
92+
93+
94+
## Exact arithmetic milestone
95+
96+
Branch `codex/1.4-json-cli-exact-arithmetic` starts at query core 6e8f145
97+
(draft PR #24). Native/safety/docs passed on the same unchanged source manifest
98+
`33439f5716ac7e33e01e477db4cb018547618fa7b74885867bb2b290ba43d7e0`.
99+
Native: 22 actual commands, exits 0; debug/release 266 root functions and 199
100+
parameter cases. Safety: ASan same counts, eight TSan shared functions and clean
101+
strict memory safety/warnings-as-errors build. DocC: five catalogs. Receipts are
102+
`.build/ci/cli-c3-handoff-{native,safety,docs}`; the CLI lane additionally passed
103+
46 functions, 53 historical foundation subprocesses, 38 C2 vectors, 17 C3 vectors,
104+
and 18 operation-site/report checks covering all sixteen CLI metrics.
105+
The ten arithmetic functions evaluate the 738 independent integer/Fraction cases,
106+
actual digit/exponent/token/work/retention boundaries, host narrowing and inner-loop
107+
cancellation. Original suite/cap/exclusion/downstream counts are preserved.
108+
109+
Failed predecessor receipts are retained: negative-leading vector argv lacked `--`;
110+
a release integration exposed queued coefficient refunds crossing output's scratch
111+
baseline. The corrected domain handoff drains refunds before a new stage. Tests keep
112+
live result reservations, reclaim dead scratch and preserve cumulative work/health.
113+
No tests or accepted output expectations were lowered. The initial host-width probe
114+
was mathematically wrong about 2*D+2 overflow for D<Int.max and was corrected to
115+
exercise the actual Int.max allocation/narrowing boundary.
116+
117+
The pinned Swift 6.4 WASI SDK is installed (swift sdk list exits 0), but this milestone
118+
has not executed its arithmetic kernel on wasm32. Native macOS evidence does not
119+
close that row. The final C5 candidate still requires precise matching compiler/host,
120+
selected mobile library consumers, CLI installation/reproduction/performance and
121+
all inherited corpus dispositions. Provider helpers are not advertised or inferred.
122+
These receipts precede only this milestone ledger/prose update; runtime, tests and
123+
harness are unchanged. Final integration must refresh the affected final-source checks.

‎README.md‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,11 @@ This feature train adds `swift-json` beside the five libraries. Its compiling
481481
foundation provides strict formatting, validation, Pointer selection, staged
482482
Patch and qualified HTML/text/Markdown rendering. See the [CLI plan](Documentation/Architecture/Release1.4/Plan.md)
483483
and [foundation contract](Documentation/Architecture/Release1.4/Foundation.md)
484-
for command semantics, cumulative budgets and qualification boundaries. Query and
485-
provider commands are advertised only after their separate gates pass.
484+
for command semantics, cumulative budgets and qualification boundaries. The pull
485+
query increment adds navigation, generators, control, bindings and exact decimal
486+
arithmetic; see the [query](Documentation/Architecture/Release1.4/QueryCore.md) and
487+
[arithmetic](Documentation/Architecture/Release1.4/Arithmetic.md) contracts. Complete
488+
advanced-filter/platform/provider qualification remains open before a 1.4 release.
486489

487490
```sh
488491
swift build -c release --product swift-json

0 commit comments

Comments
 (0)