You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
2.**No f64 for SQRT Seed:** The initial approximation for SQRT must use bit-by-bit integer sqrt. Using `f64::sqrt(x)` as a seed is FORBIDDEN — it introduces non-determinism.
1470
1472
1471
-
3.**No Iteration Short-Circuiting:** Execute ALL iterations as specified (256 for division, 226 for SQRT). Compilers must NOT elide "useless" iterations via "fast-math" flags.
1473
+
3.**No Iteration Short-Circuiting:** Execute ALL iterations as specified (128 for division, 226 for SQRT). Compilers must NOT elide "useless" iterations via "fast-math" flags.
The original RFC specified type-specific DFP opcodes (`OP_DFP_ADD/SUB/MUL/DIV`). After implementation review, the architecture uses **unified runtime dispatch** as the primary path:
1824
+
1825
+
- All generic `Op::Add/Sub/Mul/Div/Mod/Neg/Abs` route through a single `arithmetic_op()` method
1826
+
-`arithmetic_op()` performs runtime type detection (one byte comparison per operand)
1827
+
- Type-specific opcodes (`OP_DFP_ADD`, etc.) are **reserved for future JIT optimization** but not emitted by the current compiler
1828
+
1829
+
**Rationale:** Runtime detection cost (one `match` on a byte) is negligible vs disk I/O in a database VM. The DQA review proved that type-specific opcodes (7 defined for DQA) become dead code when the compiler doesn't emit them.
1830
+
1831
+
**Compiler requirement:** The expression compiler MUST ensure all generic arithmetic opcodes route through the type-aware `arithmetic_op()` dispatch. Any new arithmetic opcode added to `Op` must include Extension type handling.
**Implementation:**`as_float64()` still supports DFP for backward compatibility but the `compare()` method uses dedicated promotion paths that avoid precision loss.
1849
+
1850
+
### A3. Division Iterations: 128 (Resolves: D1)
1851
+
1852
+
The implementation uses **128 iterations** (not 256) for the long division loop. This is mathematically sufficient:
**Requirement:**`perform_cast()` MUST delegate to `Value::cast_to_type()`. `into_coerce_to_type()` MUST use `cast_to_type()` internally, only inlining the same-type fast-path (no conversion needed, return self).
1887
+
1888
+
### A6. DETERMINISTIC VIEW (Resolves: S10)
1889
+
1890
+
Deferred to a separate RFC-0110. The VM's `deterministic` flag and `arithmetic_op_deterministic()` method are reserved infrastructure. The SQL surface (`CREATE DETERMINISTIC VIEW`) requires parser grammar changes beyond the scope of this amendment.
1891
+
1892
+
### A7. Verification Requirements
1893
+
1894
+
DFP integration MUST include:
1895
+
1896
+
| Category | Tests Required | Coverage |
1897
+
|----------|---------------|----------|
1898
+
| Value API | Round-trip, Display, as_string, as_float64, coercion | Per type conversion |
1899
+
| VM Arithmetic | add/sub/mul/div/mod/neg/abs/cmp | Per opcode × per type |
1900
+
| Cross-type comparison | DFP vs Int, DFP vs Float | Per combination |
> **Status:** Accepted amendment based on code review findings
1185
+
1186
+
### B1. Unified Runtime Dispatch (Resolves: S8)
1187
+
1188
+
The original RFC specified 7 type-specific DQA opcodes (`OP_DQA_ADD/SUB/MUL/DIV/NEG/ABS/CMP`). After implementation review, the architecture uses **unified runtime dispatch** as the primary path:
1189
+
1190
+
- All generic `Op::Add/Sub/Mul/Div/Mod/Neg/Abs` route through a single `arithmetic_op()` method
1191
+
-`arithmetic_op()` performs runtime type detection via `is_quant_value()` / `is_dfp()` byte checks
1192
+
- DQA-specific opcodes (`Op::DqaAdd`, etc.) are **reserved for future JIT optimization** — dispatched correctly in the VM main loop but never emitted by the current compiler
1193
+
1194
+
**Rationale:** The 7 DQA opcodes are fully implemented and tested but the compiler emits only generic opcodes. Making the compiler type-aware would require schema inspection during compilation — a significant architectural change deferred to a future optimization pass.
1195
+
1196
+
**Compiler requirement:** The expression compiler MUST ensure all generic arithmetic opcodes route through `arithmetic_op()`. Any bypass (like the old `div_op()`/`mod_op()` static methods) risks silently returning NULL for Extension types.
| Quant | Quant | Same-type `dqa_cmp` after canonicalization |
1212
+
1213
+
**Warning:** Quant → f64 conversion for comparison is lossy for values exceeding f64 integer precision (2^53) at high scales. A query like `WHERE quant_col > 9007199254740993` may produce incorrect results for values near the precision boundary. This is documented as a known limitation — use `CAST(float_col AS DQA)` for exact comparison.
1214
+
1215
+
### B3. Single Casting Truth (Resolves: S2, S3, S4, S7)
1216
+
1217
+
Three code paths previously implemented independent type coercion for Quant:
1218
+
1.`Value::cast_to_type()` — borrowing, was a stub returning NULL
1219
+
2.`Value::into_coerce_to_type()` — consuming, was a stub returning NULL
1220
+
3.`CastExpr::perform_cast()` — was returning Error
1221
+
1222
+
**Requirement:** All three paths delegate to a single implementation in `Value::cast_to_type()`:
1223
+
-`into_coerce_to_type()` calls `cast_to_type()` internally, inlining only the same-type fast-path
1224
+
-`perform_cast()` delegates to `Value::cast_to_type()` via `Ok(value.cast_to_type(target))`
1225
+
1226
+
### B4. Validation on Extraction (Resolves: S9)
1227
+
1228
+
`extract_dqa_from_extension()` previously used `Some(Dqa { value, scale })` (direct construction), bypassing `Dqa::new()` validation. A corrupted payload with `scale > 18` would be accepted.
1229
+
1230
+
**Requirement:** All DQA extraction from byte data MUST use `Dqa::new(value, scale).ok()` or equivalent validation. Direct `Dqa { value, scale }` construction is only permitted in `Dqa::new()` itself and in the `CANONICAL_ZERO` constant.
1231
+
1232
+
### B5. Persistence Validation (Resolves: S13)
1233
+
1234
+
Wire tag 11 (generic extension) deserialization now validates DQA payloads:
**Revision:** v2.13 - Tightened MUL clamping wording, added large-value chain test, added >90% note to DQA_CMP fast-path
1184
1271
**Revision:** v2.12 - Added SQL vs canonical representation clarification, fixed division rounding wording (TARGET_SCALE precision), strengthened SIMD determinism rule, enforced canonicalization in encoding API, added control-flow to VM canonicalization rule, added power<=36 invariant, added scale alignment overflow test vector
1185
1272
**Revision:** v2.11 - Fixed DIV negative test vector (-12 not -13), added i64 range check to DQA_ASSIGN_TO_COLUMN, added CANONICALIZE to DIV return, unified scale overflow references, fixed test vector notes, added DIV canonicalization test vector, fixed MAX_I128_DIGITS to 39
0 commit comments