@quereus/quereus 4.9.0 → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/dist/src/core/database.d.ts.map +1 -1
  2. package/dist/src/core/database.js +19 -4
  3. package/dist/src/core/database.js.map +1 -1
  4. package/dist/src/core/statement.d.ts.map +1 -1
  5. package/dist/src/core/statement.js +74 -15
  6. package/dist/src/core/statement.js.map +1 -1
  7. package/dist/src/func/builtins/aggregate.d.ts.map +1 -1
  8. package/dist/src/func/builtins/aggregate.js +85 -33
  9. package/dist/src/func/builtins/aggregate.js.map +1 -1
  10. package/dist/src/func/builtins/explain.d.ts.map +1 -1
  11. package/dist/src/func/builtins/explain.js +9 -2
  12. package/dist/src/func/builtins/explain.js.map +1 -1
  13. package/dist/src/func/builtins/scalar.d.ts.map +1 -1
  14. package/dist/src/func/builtins/scalar.js +4 -2
  15. package/dist/src/func/builtins/scalar.js.map +1 -1
  16. package/dist/src/func/registration.d.ts +6 -0
  17. package/dist/src/func/registration.d.ts.map +1 -1
  18. package/dist/src/func/registration.js +1 -0
  19. package/dist/src/func/registration.js.map +1 -1
  20. package/dist/src/index.d.ts +1 -0
  21. package/dist/src/index.d.ts.map +1 -1
  22. package/dist/src/index.js +6 -0
  23. package/dist/src/index.js.map +1 -1
  24. package/dist/src/planner/building/constraint-builder.d.ts +3 -2
  25. package/dist/src/planner/building/constraint-builder.d.ts.map +1 -1
  26. package/dist/src/planner/building/constraint-builder.js +15 -24
  27. package/dist/src/planner/building/constraint-builder.js.map +1 -1
  28. package/dist/src/planner/building/delete.d.ts.map +1 -1
  29. package/dist/src/planner/building/delete.js +7 -24
  30. package/dist/src/planner/building/delete.js.map +1 -1
  31. package/dist/src/planner/building/foreign-key-builder.d.ts +3 -2
  32. package/dist/src/planner/building/foreign-key-builder.d.ts.map +1 -1
  33. package/dist/src/planner/building/foreign-key-builder.js +13 -17
  34. package/dist/src/planner/building/foreign-key-builder.js.map +1 -1
  35. package/dist/src/planner/building/insert.d.ts.map +1 -1
  36. package/dist/src/planner/building/insert.js +16 -32
  37. package/dist/src/planner/building/insert.js.map +1 -1
  38. package/dist/src/planner/building/mutation-context.d.ts +63 -0
  39. package/dist/src/planner/building/mutation-context.d.ts.map +1 -0
  40. package/dist/src/planner/building/mutation-context.js +126 -0
  41. package/dist/src/planner/building/mutation-context.js.map +1 -0
  42. package/dist/src/planner/building/update.d.ts.map +1 -1
  43. package/dist/src/planner/building/update.js +7 -24
  44. package/dist/src/planner/building/update.js.map +1 -1
  45. package/dist/src/planner/nodes/scalar.d.ts.map +1 -1
  46. package/dist/src/planner/nodes/scalar.js +13 -1
  47. package/dist/src/planner/nodes/scalar.js.map +1 -1
  48. package/dist/src/runtime/emission-context.d.ts +14 -1
  49. package/dist/src/runtime/emission-context.d.ts.map +1 -1
  50. package/dist/src/runtime/emission-context.js +17 -5
  51. package/dist/src/runtime/emission-context.js.map +1 -1
  52. package/dist/src/runtime/emit/aggregate-setup.d.ts +44 -8
  53. package/dist/src/runtime/emit/aggregate-setup.d.ts.map +1 -1
  54. package/dist/src/runtime/emit/aggregate-setup.js +79 -15
  55. package/dist/src/runtime/emit/aggregate-setup.js.map +1 -1
  56. package/dist/src/runtime/emit/aggregate.d.ts.map +1 -1
  57. package/dist/src/runtime/emit/aggregate.js +21 -106
  58. package/dist/src/runtime/emit/aggregate.js.map +1 -1
  59. package/dist/src/runtime/emit/alter-table.d.ts.map +1 -1
  60. package/dist/src/runtime/emit/alter-table.js +11 -2
  61. package/dist/src/runtime/emit/alter-table.js.map +1 -1
  62. package/dist/src/runtime/emit/asof-scan.js +1 -1
  63. package/dist/src/runtime/emit/asof-scan.js.map +1 -1
  64. package/dist/src/runtime/emit/between.d.ts +2 -0
  65. package/dist/src/runtime/emit/between.d.ts.map +1 -1
  66. package/dist/src/runtime/emit/between.js +7 -8
  67. package/dist/src/runtime/emit/between.js.map +1 -1
  68. package/dist/src/runtime/emit/binary.d.ts +27 -5
  69. package/dist/src/runtime/emit/binary.d.ts.map +1 -1
  70. package/dist/src/runtime/emit/binary.js +266 -177
  71. package/dist/src/runtime/emit/binary.js.map +1 -1
  72. package/dist/src/runtime/emit/case.d.ts +34 -0
  73. package/dist/src/runtime/emit/case.d.ts.map +1 -1
  74. package/dist/src/runtime/emit/case.js +18 -11
  75. package/dist/src/runtime/emit/case.js.map +1 -1
  76. package/dist/src/runtime/emit/cast.d.ts +2 -0
  77. package/dist/src/runtime/emit/cast.d.ts.map +1 -1
  78. package/dist/src/runtime/emit/cast.js +7 -5
  79. package/dist/src/runtime/emit/cast.js.map +1 -1
  80. package/dist/src/runtime/emit/column-reference.d.ts +3 -1
  81. package/dist/src/runtime/emit/column-reference.d.ts.map +1 -1
  82. package/dist/src/runtime/emit/column-reference.js +6 -2
  83. package/dist/src/runtime/emit/column-reference.js.map +1 -1
  84. package/dist/src/runtime/emit/constraint-check.d.ts.map +1 -1
  85. package/dist/src/runtime/emit/constraint-check.js +17 -7
  86. package/dist/src/runtime/emit/constraint-check.js.map +1 -1
  87. package/dist/src/runtime/emit/dml-executor.d.ts.map +1 -1
  88. package/dist/src/runtime/emit/dml-executor.js +26 -1
  89. package/dist/src/runtime/emit/dml-executor.js.map +1 -1
  90. package/dist/src/runtime/emit/filter.d.ts +1 -1
  91. package/dist/src/runtime/emit/filter.js +1 -1
  92. package/dist/src/runtime/emit/hash-aggregate.d.ts.map +1 -1
  93. package/dist/src/runtime/emit/hash-aggregate.js +18 -88
  94. package/dist/src/runtime/emit/hash-aggregate.js.map +1 -1
  95. package/dist/src/runtime/emit/literal.d.ts +14 -1
  96. package/dist/src/runtime/emit/literal.d.ts.map +1 -1
  97. package/dist/src/runtime/emit/literal.js +33 -7
  98. package/dist/src/runtime/emit/literal.js.map +1 -1
  99. package/dist/src/runtime/emit/materialized-view-helpers.d.ts +7 -1
  100. package/dist/src/runtime/emit/materialized-view-helpers.d.ts.map +1 -1
  101. package/dist/src/runtime/emit/materialized-view-helpers.js +121 -32
  102. package/dist/src/runtime/emit/materialized-view-helpers.js.map +1 -1
  103. package/dist/src/runtime/emit/parameter.d.ts +3 -1
  104. package/dist/src/runtime/emit/parameter.d.ts.map +1 -1
  105. package/dist/src/runtime/emit/parameter.js +7 -2
  106. package/dist/src/runtime/emit/parameter.js.map +1 -1
  107. package/dist/src/runtime/emit/scalar-function.d.ts +29 -1
  108. package/dist/src/runtime/emit/scalar-function.d.ts.map +1 -1
  109. package/dist/src/runtime/emit/scalar-function.js +66 -16
  110. package/dist/src/runtime/emit/scalar-function.js.map +1 -1
  111. package/dist/src/runtime/emit/scalar-op.d.ts +63 -0
  112. package/dist/src/runtime/emit/scalar-op.d.ts.map +1 -0
  113. package/dist/src/runtime/emit/scalar-op.js +37 -0
  114. package/dist/src/runtime/emit/scalar-op.js.map +1 -0
  115. package/dist/src/runtime/emit/scan.d.ts.map +1 -1
  116. package/dist/src/runtime/emit/scan.js +19 -1
  117. package/dist/src/runtime/emit/scan.js.map +1 -1
  118. package/dist/src/runtime/emit/temporal-arithmetic.d.ts +18 -8
  119. package/dist/src/runtime/emit/temporal-arithmetic.d.ts.map +1 -1
  120. package/dist/src/runtime/emit/temporal-arithmetic.js +29 -311
  121. package/dist/src/runtime/emit/temporal-arithmetic.js.map +1 -1
  122. package/dist/src/runtime/emit/unary.d.ts +2 -0
  123. package/dist/src/runtime/emit/unary.d.ts.map +1 -1
  124. package/dist/src/runtime/emit/unary.js +125 -53
  125. package/dist/src/runtime/emit/unary.js.map +1 -1
  126. package/dist/src/runtime/emitters.d.ts +22 -0
  127. package/dist/src/runtime/emitters.d.ts.map +1 -1
  128. package/dist/src/runtime/emitters.js +29 -0
  129. package/dist/src/runtime/emitters.js.map +1 -1
  130. package/dist/src/runtime/scalar-fusion.d.ts +47 -0
  131. package/dist/src/runtime/scalar-fusion.d.ts.map +1 -0
  132. package/dist/src/runtime/scalar-fusion.js +275 -0
  133. package/dist/src/runtime/scalar-fusion.js.map +1 -0
  134. package/dist/src/runtime/strict-flags.d.ts +9 -0
  135. package/dist/src/runtime/strict-flags.d.ts.map +1 -1
  136. package/dist/src/runtime/strict-flags.js +9 -0
  137. package/dist/src/runtime/strict-flags.js.map +1 -1
  138. package/dist/src/runtime/strict-fork.js +2 -2
  139. package/dist/src/runtime/strict-fork.js.map +1 -1
  140. package/dist/src/runtime/strict-representation.d.ts +78 -0
  141. package/dist/src/runtime/strict-representation.d.ts.map +1 -0
  142. package/dist/src/runtime/strict-representation.js +159 -0
  143. package/dist/src/runtime/strict-representation.js.map +1 -0
  144. package/dist/src/schema/catalog.d.ts +25 -2
  145. package/dist/src/schema/catalog.d.ts.map +1 -1
  146. package/dist/src/schema/catalog.js +35 -2
  147. package/dist/src/schema/catalog.js.map +1 -1
  148. package/dist/src/schema/constraint-builder.d.ts +15 -2
  149. package/dist/src/schema/constraint-builder.d.ts.map +1 -1
  150. package/dist/src/schema/constraint-builder.js +21 -5
  151. package/dist/src/schema/constraint-builder.js.map +1 -1
  152. package/dist/src/schema/function.d.ts +15 -0
  153. package/dist/src/schema/function.d.ts.map +1 -1
  154. package/dist/src/schema/function.js.map +1 -1
  155. package/dist/src/schema/manager.d.ts +13 -0
  156. package/dist/src/schema/manager.d.ts.map +1 -1
  157. package/dist/src/schema/manager.js +44 -11
  158. package/dist/src/schema/manager.js.map +1 -1
  159. package/dist/src/schema/table.d.ts +43 -0
  160. package/dist/src/schema/table.d.ts.map +1 -1
  161. package/dist/src/schema/table.js +80 -0
  162. package/dist/src/schema/table.js.map +1 -1
  163. package/dist/src/types/builtin-types.d.ts.map +1 -1
  164. package/dist/src/types/builtin-types.js +17 -8
  165. package/dist/src/types/builtin-types.js.map +1 -1
  166. package/dist/src/types/temporal-ops.d.ts +119 -0
  167. package/dist/src/types/temporal-ops.d.ts.map +1 -0
  168. package/dist/src/types/temporal-ops.js +348 -0
  169. package/dist/src/types/temporal-ops.js.map +1 -0
  170. package/dist/src/types/temporal-types.d.ts.map +1 -1
  171. package/dist/src/types/temporal-types.js +8 -3
  172. package/dist/src/types/temporal-types.js.map +1 -1
  173. package/dist/src/util/coercion.d.ts +22 -7
  174. package/dist/src/util/coercion.d.ts.map +1 -1
  175. package/dist/src/util/coercion.js +28 -15
  176. package/dist/src/util/coercion.js.map +1 -1
  177. package/dist/src/util/comparison.d.ts +25 -0
  178. package/dist/src/util/comparison.d.ts.map +1 -1
  179. package/dist/src/util/comparison.js +25 -0
  180. package/dist/src/util/comparison.js.map +1 -1
  181. package/dist/src/util/key-tuple-codec.d.ts +12 -3
  182. package/dist/src/util/key-tuple-codec.d.ts.map +1 -1
  183. package/dist/src/util/key-tuple-codec.js.map +1 -1
  184. package/dist/src/util/numeric-canonical.d.ts +26 -0
  185. package/dist/src/util/numeric-canonical.d.ts.map +1 -0
  186. package/dist/src/util/numeric-canonical.js +66 -0
  187. package/dist/src/util/numeric-canonical.js.map +1 -0
  188. package/dist/src/vtab/module.d.ts +25 -0
  189. package/dist/src/vtab/module.d.ts.map +1 -1
  190. package/package.json +4 -3
@@ -38,6 +38,28 @@ export declare function emitCall(root: Instruction): Instruction;
38
38
  /**
39
39
  * Helper function to emit a plan node and wrap it as a callable instruction.
40
40
  * This is useful for emitters that need to create sub-instructions.
41
+ *
42
+ * This is also the single front door of scalar fusion: when the emission context
43
+ * allows it, a pure synchronous scalar subtree compiles into one fused closure
44
+ * (runtime/scalar-fusion.ts) instead of a per-row sub-program. Transparent to every
45
+ * consumer — a `FusedScalar` satisfies the same `(ctx) => MaybePromise<SqlValue>`
46
+ * callback contract a sub-program does, and any plan the fusion compiler cannot
47
+ * prove pure and synchronous (relational plans, subqueries, custom-emitter or
48
+ * asynchronous function calls, async literals, over-deep trees) falls back to the
49
+ * sub-program path unchanged.
50
+ *
51
+ * A fused instruction returns the SAME closure on every invocation, where `emitCall`
52
+ * allocates a fresh arrow each time; nothing keys on sub-program function identity
53
+ * (verified across the runtime emitters), and identity per emit site is strictly
54
+ * more stable than identity per invocation.
55
+ *
56
+ * NOTE: the three *debug introspection* surfaces emit unfused, but the two *observation*
57
+ * surfaces that run a normal statement do not — `runtime_stats` metrics and a db-level
58
+ * `Database.setInstructionTracer` both see a fused subtree as one `fused(...)`
59
+ * instruction, so per-operator timings and per-operator trace events inside it are gone.
60
+ * Fine today (both are debug telemetry, and `execution_trace()` covers the per-operator
61
+ * view via `_emitUnfused`); if per-scalar-operator cost ever has to be attributed from a
62
+ * normal run, have those two paths force `fuseScalars: false` the way `_emitUnfused` does.
41
63
  */
42
64
  export declare function emitCallFromPlan(plan: PlanNode, emissionCtx: EmissionContext): Instruction;
43
65
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"emitters.d.ts","sourceRoot":"","sources":["../../../src/runtime/emitters.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAkB,MAAM,YAAY,CAAC;AAI9E,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAK7D,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,KAAK,WAAW,CAAC;AAEhF;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B,oDAAoD;IACpD,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B,+EAA+E;IAC/E,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAE5B,kEAAkE;IAClE,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B,yDAAyD;IACzD,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAYD,wBAAg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,CAAC,EAAE,OAAO,CAAC;IAE5B,yDAAyD;IACzD,eAAe,CAAC,EAAE,OAAO,CAAC;IAE1B,6DAA6D;IAC7D,aAAa,CAAC,EAAE,MAAM,CAAC;IAEvB,oCAAoC;IACpC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B,0CAA0C;IAC1C,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAYD,wBAAgB,eAAe,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,IAAI,GAAE,WAAgB,GAAG,IAAI,CAG1G;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,YAAY,GAAG,WAAW,GAAG,SAAS,CAG9E;AAgDD,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,CAW9E;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,WAAW,GAAG,WAAW,CAavD;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,eAAe,GAAG,WAAW,CAS1F;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACzC,MAAM,EAAE,WAAW,EAAE,EACrB,GAAG,EAAE,cAAc,EACnB,YAAY,EAAE,eAAe,EAC7B,IAAI,CAAC,EAAE,MAAM,GACX,WAAW,CAEb"}
@@ -3,6 +3,7 @@ import { StatusCode } from '../common/types.js';
3
3
  import { createLogger } from '../common/logger.js';
4
4
  import { Scheduler } from "./scheduler.js";
5
5
  import { isAsyncIterable } from "./utils.js";
6
+ import { tryFuseScalar } from "./scalar-fusion.js";
6
7
  const log = createLogger('emitters');
7
8
  const emitters = new Map();
8
9
  export function registerEmitter(nodeType, emitter, meta = {}) {
@@ -91,8 +92,36 @@ export function emitCall(root) {
91
92
  /**
92
93
  * Helper function to emit a plan node and wrap it as a callable instruction.
93
94
  * This is useful for emitters that need to create sub-instructions.
95
+ *
96
+ * This is also the single front door of scalar fusion: when the emission context
97
+ * allows it, a pure synchronous scalar subtree compiles into one fused closure
98
+ * (runtime/scalar-fusion.ts) instead of a per-row sub-program. Transparent to every
99
+ * consumer — a `FusedScalar` satisfies the same `(ctx) => MaybePromise<SqlValue>`
100
+ * callback contract a sub-program does, and any plan the fusion compiler cannot
101
+ * prove pure and synchronous (relational plans, subqueries, custom-emitter or
102
+ * asynchronous function calls, async literals, over-deep trees) falls back to the
103
+ * sub-program path unchanged.
104
+ *
105
+ * A fused instruction returns the SAME closure on every invocation, where `emitCall`
106
+ * allocates a fresh arrow each time; nothing keys on sub-program function identity
107
+ * (verified across the runtime emitters), and identity per emit site is strictly
108
+ * more stable than identity per invocation.
109
+ *
110
+ * NOTE: the three *debug introspection* surfaces emit unfused, but the two *observation*
111
+ * surfaces that run a normal statement do not — `runtime_stats` metrics and a db-level
112
+ * `Database.setInstructionTracer` both see a fused subtree as one `fused(...)`
113
+ * instruction, so per-operator timings and per-operator trace events inside it are gone.
114
+ * Fine today (both are debug telemetry, and `execution_trace()` covers the per-operator
115
+ * view via `_emitUnfused`); if per-scalar-operator cost ever has to be attributed from a
116
+ * normal run, have those two paths force `fuseScalars: false` the way `_emitUnfused` does.
94
117
  */
95
118
  export function emitCallFromPlan(plan, emissionCtx) {
119
+ if (emissionCtx.fuseScalars) {
120
+ const fused = tryFuseScalar(plan, emissionCtx);
121
+ if (fused) {
122
+ return { params: [], run: () => fused, note: `fused(${plan.toString()})` };
123
+ }
124
+ }
96
125
  const instruction = emitPlanNode(plan, emissionCtx);
97
126
  return emitCall(instruction);
98
127
  }
@@ -1 +1 @@
1
- {"version":3,"file":"emitters.js","sourceRoot":"","sources":["../../../src/runtime/emitters.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAInD,OAAO,EAAE,UAAU,EAAiD,MAAM,oBAAoB,CAAC;AAC/F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AE,YAAY,IAAI,CAAC,IAAI,GAAG;QAC9B,QAAQ,EAAE,CAAC,OAAO,CAAC;KACnB,CAAC;AACH,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,UAAU,gBAAgB,CAAC,IAAc,EAAE,WAA4B;IAC5E,IAAI,WAAW,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,aAAa,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC/C,IAAI,KAAK,EAAE,CAAC;YACX,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,SAAS,IAAI,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC;QAC5E,CAAC;IACF,CAAC;IACD,MAAM,WAAW,GAAG,YAAY,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;IACpD,OAAO,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,0BAA0B,CACzC,MAAqB,EACrB,GAAmB,EACnB,YAA6B,EAC7B,IAAa;IAEb,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC;AAC9B,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { type SqlValue } from '../common/types.js';
2
+ import type { PlanNode } from '../planner/nodes/plan-node.js';
3
+ import type { RuntimeContext } from './types.js';
4
+ import type { EmissionContext } from './emission-context.js';
5
+ /**
6
+ * A fused scalar expression: evaluates a whole pure, synchronous subtree with direct
7
+ * calls — no scheduler, no per-row allocation, no dynamic dispatch.
8
+ *
9
+ * The type is deliberately a strict narrowing of `SubProgram` (common/types.ts):
10
+ * every consumer of `emitCallFromPlan` invokes the result as
11
+ * `(ctx) => MaybePromise<SqlValue>`, and a fused closure satisfies that contract
12
+ * with a value that just happens to never be a Promise.
13
+ */
14
+ export type FusedScalar = (rctx: RuntimeContext) => SqlValue;
15
+ /**
16
+ * Largest fused subtree depth. Fused closures nest on the JS call stack where the
17
+ * scheduler's linearized instruction loop did not, so a pathologically deep expression
18
+ * (`a+a+a+…` thousands of terms) could overflow the stack where it works unfused.
19
+ * Past this depth the expression offered to {@link tryFuseScalar} falls back whole to the
20
+ * sub-program path — correct, just unoptimized. Fusion is still retried from depth 0 at
21
+ * every nested `emitCallFromPlan` site the fallback emission reaches (CASE branches, an
22
+ * AND/OR short-circuit right leg), so a deep tree fuses in pieces below those seams rather
23
+ * than not at all. 32 is far above any real expression's nesting.
24
+ */
25
+ export declare const MAX_FUSION_DEPTH = 32;
26
+ /**
27
+ * Compile `plan` into a single closure, or return undefined if any node in the subtree
28
+ * cannot be fused (an unsupported node type, a subquery, anything that can return a
29
+ * Promise, or a subtree deeper than {@link MAX_FUSION_DEPTH}). Undefined is the normal
30
+ * answer for most of the plan tree; the caller falls back to the sub-program path
31
+ * unchanged.
32
+ *
33
+ * Every fused body comes from the node's own {@link ScalarOpSpec} builder (or, for
34
+ * CASE, from `buildCaseMatcher`) — the same functions the instruction emitters run —
35
+ * so a fused expression and its instruction form cannot disagree on semantics, error
36
+ * messages, or evaluation counts. This compiler only changes HOW operand values reach
37
+ * those bodies: direct nested calls instead of scheduler slots.
38
+ *
39
+ * A scalar function call fuses only when it is provably synchronous — see
40
+ * {@link fuseScalarFunctionCall}. The AND/OR short-circuit form declines through
41
+ * `buildBinaryOpSpec` returning undefined, and subquery/window/aggregate/relational
42
+ * nodes decline as unknown node types — which also keeps every `emitCallFromPlan` call
43
+ * site that passes a relational plan (cache sources, join legs, view-mutation programs)
44
+ * on the sub-program path for free.
45
+ */
46
+ export declare function tryFuseScalar(plan: PlanNode, ctx: EmissionContext): FusedScalar | undefined;
47
+ //# sourceMappingURL=scalar-fusion.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar-fusion.d.ts","sourceRoot":"","sources":["../../../src/runtime/scalar-fusion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE/D,OAAO,KAAK,EAAE,QAAQ,EAAkB,MAAM,+BAA+B,CAAC;AAc9E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAa7D;;;;;;;;GAQG;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,cAAc,KAAK,QAAQ,CAAC;AAE7D;;;;;;;;;GASG;AACH,eAAO,MAAM,gBAAgB,KAAK,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,eAAe,GAAG,WAAW,GAAG,SAAS,CAE3F"}
@@ -0,0 +1,275 @@
1
+ import { StatusCode } from '../common/types.js';
2
+ import { QuereusError } from '../common/errors.js';
3
+ import { PlanNodeType } from '../planner/nodes/plan-node-type.js';
4
+ import { isScalarFunctionSchema } from '../schema/function.js';
5
+ import { assertSpecArity } from './emit/scalar-op.js';
6
+ import { buildScalarFunctionRun } from './emit/scalar-function.js';
7
+ import { buildLiteralSpec } from './emit/literal.js';
8
+ import { buildColumnReferenceSpec } from './emit/column-reference.js';
9
+ import { buildParameterSpec } from './emit/parameter.js';
10
+ import { buildCastSpec } from './emit/cast.js';
11
+ import { buildUnaryOpSpec } from './emit/unary.js';
12
+ import { buildBetweenSpec } from './emit/between.js';
13
+ import { buildBinaryOpSpec } from './emit/binary.js';
14
+ import { buildCaseMatcher } from './emit/case.js';
15
+ import { isTruthy } from '../util/comparison.js';
16
+ /**
17
+ * Largest fused subtree depth. Fused closures nest on the JS call stack where the
18
+ * scheduler's linearized instruction loop did not, so a pathologically deep expression
19
+ * (`a+a+a+…` thousands of terms) could overflow the stack where it works unfused.
20
+ * Past this depth the expression offered to {@link tryFuseScalar} falls back whole to the
21
+ * sub-program path — correct, just unoptimized. Fusion is still retried from depth 0 at
22
+ * every nested `emitCallFromPlan` site the fallback emission reaches (CASE branches, an
23
+ * AND/OR short-circuit right leg), so a deep tree fuses in pieces below those seams rather
24
+ * than not at all. 32 is far above any real expression's nesting.
25
+ */
26
+ export const MAX_FUSION_DEPTH = 32;
27
+ /**
28
+ * Compile `plan` into a single closure, or return undefined if any node in the subtree
29
+ * cannot be fused (an unsupported node type, a subquery, anything that can return a
30
+ * Promise, or a subtree deeper than {@link MAX_FUSION_DEPTH}). Undefined is the normal
31
+ * answer for most of the plan tree; the caller falls back to the sub-program path
32
+ * unchanged.
33
+ *
34
+ * Every fused body comes from the node's own {@link ScalarOpSpec} builder (or, for
35
+ * CASE, from `buildCaseMatcher`) — the same functions the instruction emitters run —
36
+ * so a fused expression and its instruction form cannot disagree on semantics, error
37
+ * messages, or evaluation counts. This compiler only changes HOW operand values reach
38
+ * those bodies: direct nested calls instead of scheduler slots.
39
+ *
40
+ * A scalar function call fuses only when it is provably synchronous — see
41
+ * {@link fuseScalarFunctionCall}. The AND/OR short-circuit form declines through
42
+ * `buildBinaryOpSpec` returning undefined, and subquery/window/aggregate/relational
43
+ * nodes decline as unknown node types — which also keeps every `emitCallFromPlan` call
44
+ * site that passes a relational plan (cache sources, join legs, view-mutation programs)
45
+ * on the sub-program path for free.
46
+ */
47
+ export function tryFuseScalar(plan, ctx) {
48
+ return fuseNode(plan, ctx, 0);
49
+ }
50
+ // NOTE: a subtree that declines partway has already built every spec above the declining
51
+ // node — resolving collations, compiling a constant LIKE matcher — and those are then
52
+ // rebuilt by the fallback `emitPlanNode`. Emit-time only, bounded by subtree size, and the
53
+ // idempotent work (collation lookups record into a Set) cannot diverge. Fine today; if emit
54
+ // latency ever shows up on function-heavy expressions, pre-walk the subtree for unfusable
55
+ // node types before building any spec.
56
+ /** Per-node dispatch. `depth` counts the closure frames already wrapping this node. */
57
+ function fuseNode(plan, ctx, depth) {
58
+ if (depth > MAX_FUSION_DEPTH)
59
+ return undefined;
60
+ switch (plan.nodeType) {
61
+ case PlanNodeType.Literal: {
62
+ // Undefined when the literal holds an unresolved async constant-fold result —
63
+ // the scheduler resolves that Promise; a fused closure could not.
64
+ const spec = buildLiteralSpec(plan);
65
+ return spec && fuseSpec(spec, ctx, depth);
66
+ }
67
+ case PlanNodeType.ColumnReference:
68
+ return fuseSpec(buildColumnReferenceSpec(plan), ctx, depth);
69
+ case PlanNodeType.ParameterReference:
70
+ return fuseSpec(buildParameterSpec(plan), ctx, depth);
71
+ case PlanNodeType.Collate:
72
+ // No runtime effect (mirrors emitCollate) — fuse straight through to the
73
+ // operand. Adds no closure frame, so depth is unchanged.
74
+ return fuseNode(plan.operand, ctx, depth);
75
+ case PlanNodeType.Cast:
76
+ return fuseSpec(buildCastSpec(plan), ctx, depth);
77
+ case PlanNodeType.UnaryOp:
78
+ return fuseSpec(buildUnaryOpSpec(plan), ctx, depth);
79
+ case PlanNodeType.Between:
80
+ return fuseSpec(buildBetweenSpec(plan, ctx), ctx, depth);
81
+ case PlanNodeType.BinaryOp: {
82
+ // Undefined for the AND/OR short-circuit form (subquery right operand),
83
+ // whose right leg is a deferred sub-program rather than a value.
84
+ const spec = buildBinaryOpSpec(plan, ctx);
85
+ return spec && fuseSpec(spec, ctx, depth);
86
+ }
87
+ case PlanNodeType.CaseExpr:
88
+ return fuseCase(plan, ctx, depth);
89
+ case PlanNodeType.ScalarFunctionCall:
90
+ return fuseScalarFunctionCall(plan, ctx, depth);
91
+ default:
92
+ return undefined;
93
+ }
94
+ }
95
+ /**
96
+ * The `AsyncFunction` constructor, which has no global binding — reachable only off an
97
+ * instance. An `async function` / `async` arrow carries `AsyncFunction.prototype` on its
98
+ * prototype chain, so `impl instanceof AsyncFunction` recognizes one.
99
+ *
100
+ * NOTE: `instanceof` is realm-local. A plugin loaded into a *different* JS realm (a worker,
101
+ * an iframe, a `node:vm` context) carries that realm's `AsyncFunction.prototype`, so its
102
+ * async implementation would not be recognized and would fall to step 4's guard — a thrown
103
+ * error with the `isAsync` remedy rather than a wrong answer. No loader in this repo crosses
104
+ * a realm (plugin-loader uses same-realm dynamic `import()`); if one ever does, widen this
105
+ * to also accept `impl[Symbol.toStringTag] === 'AsyncFunction'`, which is realm-agnostic.
106
+ */
107
+ const AsyncFunction = (async () => { }).constructor;
108
+ /**
109
+ * Fuse a scalar function call, but only when its implementation is provably
110
+ * synchronous. A fused node's contract is a plain `SqlValue`, while a `ScalarFunc` is
111
+ * typed `(...args) => MaybePromise<SqlValue>`; admitting `MaybePromise` into the fused
112
+ * contract would put a Promise check and a `.then` path on every node in the chain,
113
+ * which is the sub-program overhead this compiler exists to delete. So the decision is
114
+ * made once here, at emit time, in this order:
115
+ *
116
+ * 1. **A `customEmitter` never fuses.** It builds its own `Instruction` — possibly with
117
+ * sub-programs or async behavior — and this compiler cannot see inside it. Today that
118
+ * excludes `nullif`, `greatest`, `least`, `json_schema` and `mutation_ordinal`;
119
+ * giving custom emitters a fusion hook is parked in
120
+ * `tickets/backlog/feat-fuse-custom-emitter-scalar-functions.md`.
121
+ * 2. **`isAsync === true` never fuses** — the author's explicit declaration.
122
+ * 3. **A declared `async` implementation never fuses**, auto-detected, so the ordinary
123
+ * async UDF needs no flag.
124
+ * 4. **Otherwise fuse, with a guard**: a non-`async` implementation that returns a
125
+ * Promise anyway is invisible to step 3, so the fused body checks and throws a
126
+ * `QuereusError` naming the function and the `isAsync` remedy. One `instanceof` per
127
+ * call — negligible beside the sub-program it replaces — and it converts a silent
128
+ * wrong answer (a Promise flowing on as if it were a value, comparing as garbage)
129
+ * into a loud, actionable error.
130
+ *
131
+ * The body itself is {@link buildScalarFunctionRun}, the same one
132
+ * `emitScalarFunctionCallDefault` gives the scheduler, so a fused call and an
133
+ * instruction call cannot disagree on error text, arity checking or the `REPR_STRICT`
134
+ * return check. Operands compose by arity like every other fused node — including the
135
+ * variadic case (`numArgs === -1`, e.g. `coalesce`), which needs no special handling
136
+ * because the composition switches on `operands.length`, not on the declared arity.
137
+ */
138
+ function fuseScalarFunctionCall(plan, ctx, depth) {
139
+ const schema = plan.functionSchema;
140
+ // Not a scalar schema at all: `emitScalarFunctionCall` reports that, and the unfused
141
+ // path it falls back to still does. Decline rather than duplicate the diagnosis.
142
+ if (!isScalarFunctionSchema(schema))
143
+ return undefined;
144
+ if (schema.customEmitter)
145
+ return undefined;
146
+ if (schema.isAsync)
147
+ return undefined;
148
+ if (schema.implementation instanceof AsyncFunction)
149
+ return undefined;
150
+ const body = buildScalarFunctionRun(plan);
151
+ const functionName = plan.expression.name.toLowerCase();
152
+ const loc = plan.expression.loc?.start;
153
+ const guarded = (rctx, ...args) => {
154
+ const result = body(rctx, ...args);
155
+ if (result instanceof Promise) {
156
+ throw new QuereusError(`Function ${functionName} returned a Promise but is not declared asynchronous. `
157
+ + `Declare isAsync: true on its registration so the engine keeps it off the fused expression path.`, StatusCode.ERROR, undefined, loc?.line, loc?.column);
158
+ }
159
+ return result;
160
+ };
161
+ return composeFused(guarded, plan.operands, ctx, depth);
162
+ }
163
+ /** Check the spec's body arity, then compose it with its fused operands. */
164
+ function fuseSpec(spec, ctx, depth) {
165
+ assertSpecArity(spec);
166
+ return composeFused(spec.run, spec.operands, ctx, depth);
167
+ }
168
+ /**
169
+ * Compose a synchronous body with its fused operands, specialized by arity so the common
170
+ * cases allocate nothing per row and stay monomorphic. Closure composition only — no
171
+ * `new Function`/`eval`, which are unavailable under a Content-Security-Policy and under
172
+ * React Native.
173
+ *
174
+ * Shared by the {@link ScalarOpSpec} nodes and by {@link fuseScalarFunctionCall}, whose
175
+ * variadic body has no fixed parameter count to assert (hence the assert living in
176
+ * {@link fuseSpec}, not here). The switch is on how many operands are actually
177
+ * evaluated, so a variadic function's call site lands in whichever fixed arm matches
178
+ * its argument count.
179
+ */
180
+ function composeFused(run, operands, ctx, depth) {
181
+ switch (operands.length) {
182
+ case 0:
183
+ // The body already IS the fused closure — wrapping it would add a call frame
184
+ // per row to the two most common leaves in any query (column refs, literals).
185
+ return run;
186
+ case 1: {
187
+ const a = fuseNode(operands[0], ctx, depth + 1);
188
+ return a && ((rctx) => run(rctx, a(rctx)));
189
+ }
190
+ case 2: {
191
+ const a = fuseNode(operands[0], ctx, depth + 1);
192
+ if (!a)
193
+ return undefined;
194
+ const b = fuseNode(operands[1], ctx, depth + 1);
195
+ return b && ((rctx) => run(rctx, a(rctx), b(rctx)));
196
+ }
197
+ case 3: {
198
+ const a = fuseNode(operands[0], ctx, depth + 1);
199
+ if (!a)
200
+ return undefined;
201
+ const b = fuseNode(operands[1], ctx, depth + 1);
202
+ if (!b)
203
+ return undefined;
204
+ const c = fuseNode(operands[2], ctx, depth + 1);
205
+ return c && ((rctx) => run(rctx, a(rctx), b(rctx), c(rctx)));
206
+ }
207
+ default: {
208
+ // No spec is wider than 3 operands; a wide variadic call (`coalesce(a,b,c,d)`)
209
+ // lands here. An args array + spread is still far cheaper than a sub-program.
210
+ const fused = [];
211
+ for (const operand of operands) {
212
+ const f = fuseNode(operand, ctx, depth + 1);
213
+ if (!f)
214
+ return undefined;
215
+ fused.push(f);
216
+ }
217
+ return (rctx) => run(rctx, ...fused.map(f => f(rctx)));
218
+ }
219
+ }
220
+ }
221
+ /**
222
+ * CASE is the one covered node that is not a flat {@link ScalarOpSpec}: its branches are
223
+ * lazy. Fuse it only when the base (if any) AND every WHEN/THEN/ELSE fuse — all-or-nothing
224
+ * avoids a mixed contract where some branches are closures and some are sub-programs
225
+ * returning `MaybePromise`. The fused body keeps SQL's evaluation rules exactly as
226
+ * `emitCaseExpr` has them: WHEN clauses left to right, stop at the first match, evaluate
227
+ * ONLY the selected result, never touch a later clause. Match decisions come from
228
+ * `buildCaseMatcher`, so a fused CASE and an instruction CASE cannot disagree.
229
+ *
230
+ * Branch closures are invoked from inside the CASE closure, so their frames stack —
231
+ * they count toward the depth cap (depth + 1), same as spec operands.
232
+ */
233
+ function fuseCase(plan, ctx, depth) {
234
+ const whens = [];
235
+ const thens = [];
236
+ for (const clause of plan.whenThenClauses) {
237
+ const when = fuseNode(clause.when, ctx, depth + 1);
238
+ if (!when)
239
+ return undefined;
240
+ const then = fuseNode(clause.then, ctx, depth + 1);
241
+ if (!then)
242
+ return undefined;
243
+ whens.push(when);
244
+ thens.push(then);
245
+ }
246
+ const elseFn = plan.elseExpr ? fuseNode(plan.elseExpr, ctx, depth + 1) : undefined;
247
+ if (plan.elseExpr && !elseFn)
248
+ return undefined;
249
+ const clauseCount = whens.length;
250
+ // Simple CASE: base compared against each WHEN under the per-clause pre-resolved
251
+ // comparator (collation + type routing). A NULL base matches nothing.
252
+ if (plan.baseExpr) {
253
+ const base = fuseNode(plan.baseExpr, ctx, depth + 1);
254
+ if (!base)
255
+ return undefined;
256
+ const matcher = buildCaseMatcher(plan, ctx);
257
+ return (rctx) => {
258
+ const baseValue = base(rctx);
259
+ for (let i = 0; i < clauseCount; i++) {
260
+ if (matcher.matches(i, baseValue, whens[i](rctx)))
261
+ return thens[i](rctx);
262
+ }
263
+ return elseFn ? elseFn(rctx) : null;
264
+ };
265
+ }
266
+ // Searched CASE: first truthy WHEN selects its THEN.
267
+ return (rctx) => {
268
+ for (let i = 0; i < clauseCount; i++) {
269
+ if (isTruthy(whens[i](rctx)))
270
+ return thens[i](rctx);
271
+ }
272
+ return elseFn ? elseFn(rctx) : null;
273
+ };
274
+ }
275
+ //# sourceMappingURL=scalar-fusion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar-fusion.js","sourceRoot":"","sources":["../../../src/runtime/scalar-fusion.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAiB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAEnD,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAYlE,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAG/D,OAAO,EAAE,eAAe,EAAuC,MAAM,qBAAqB,CAAC;AAC3F,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC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,CAAC;YAC7B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;gBACtC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;oBAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;YAC1E,CAAC;YACD,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QACrC,CAAC,CAAC;IACH,CAAC;IAED,qDAAqD;IACrD,OAAO,CAAC,IAAI,EAAE,EAAE;QACf,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,EAAE,CAAC,EAAE,EAAE,CAAC;YACtC,IAAI,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACrD,CAAC;QACD,OAAO,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;IACrC,CAAC,CAAC;AACH,CAAC"}
@@ -19,4 +19,13 @@ export declare const FORK_STRICT: boolean;
19
19
  * § Invariant: source-attr contexts and child pulls.
20
20
  */
21
21
  export declare const CONTEXT_STRICT: boolean;
22
+ /**
23
+ * `QUEREUS_REPR_STRICT` — physical-representation assertions. Verifies at four
24
+ * runtime seams (vtab scan output, DML write, UDF return, statement row egress)
25
+ * that every value is in the JavaScript form its declared type promises — R1
26
+ * (canonical numeric form) and R2 (per-declared-type value space) of
27
+ * docs/types.md § Physical representation. Off, the checks are a single
28
+ * already-false branch. See strict-representation.ts.
29
+ */
30
+ export declare const REPR_STRICT: boolean;
22
31
  //# sourceMappingURL=strict-flags.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"strict-flags.d.ts","sourceRoot":"","sources":["../../../src/runtime/strict-flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,sFAAsF;AACtF,eAAO,MAAM,WAAW,SAAkC,CAAC;AAE3D;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,SAAqC,CAAC"}
1
+ {"version":3,"file":"strict-flags.d.ts","sourceRoot":"","sources":["../../../src/runtime/strict-flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAOH,sFAAsF;AACtF,eAAO,MAAM,WAAW,SAAkC,CAAC;AAE3D;;;;;;GAMG;AACH,eAAO,MAAM,cAAc,SAAqC,CAAC;AAEjE;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,SAAkC,CAAC"}
@@ -23,4 +23,13 @@ export const FORK_STRICT = readFlag('QUEREUS_FORK_STRICT');
23
23
  * § Invariant: source-attr contexts and child pulls.
24
24
  */
25
25
  export const CONTEXT_STRICT = readFlag('QUEREUS_CONTEXT_STRICT');
26
+ /**
27
+ * `QUEREUS_REPR_STRICT` — physical-representation assertions. Verifies at four
28
+ * runtime seams (vtab scan output, DML write, UDF return, statement row egress)
29
+ * that every value is in the JavaScript form its declared type promises — R1
30
+ * (canonical numeric form) and R2 (per-declared-type value space) of
31
+ * docs/types.md § Physical representation. Off, the checks are a single
32
+ * already-false branch. See strict-representation.ts.
33
+ */
34
+ export const REPR_STRICT = readFlag('QUEREUS_REPR_STRICT');
26
35
  //# sourceMappingURL=strict-flags.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"strict-flags.js","sourceRoot":"","sources":["../../../src/runtime/strict-flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,SAAS,QAAQ,CAAC,IAAY;IAC7B,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,OAAO,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,MAAM,CAAC;AAC1C,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAAC;AAE3D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC,wBAAwB,CAAC,CAAC"}
1
+ {"version":3,"file":"strict-flags.js","sourceRoot":"","sources":["../../../src/runtime/strict-flags.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,SAAS,QAAQ,CAAC,IAAY;IAC7B,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,WAAW,CAAC,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC/E,OAAO,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,MAAM,CAAC;AAC1C,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAAC;AAE3D;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,QAAQ,CAAC,wBAAwB,CAAC,CAAC;AAEjE;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,QAAQ,CAAC,qBAAqB,CAAC,CAAC"}
@@ -14,7 +14,7 @@ import { FORK_STRICT, CONTEXT_STRICT } from './strict-flags.js';
14
14
  * forks is being driven throws. State is tracked **per parent map** (not
15
15
  * globally) so concurrent unrelated drivers don't interfere, forks may mutate
16
16
  * their own fresh maps freely, and sub-forks are independently tracked.
17
- * See docs/runtime.md § Parallel runtime fork contract.
17
+ * See docs/runtime-parallel.md § Parallel runtime fork contract.
18
18
  *
19
19
  * 2. **`QUEREUS_CONTEXT_STRICT`** — stale-shadow detection. Maintains a per-
20
20
  * descriptor epoch and a per-attribute index-winner map so `assertNoShadow`
@@ -39,7 +39,7 @@ export function strictForkEnabled() {
39
39
  }
40
40
  function violation(target, count) {
41
41
  throw new QuereusError(`strict-fork: parent context mutated ${target} while ${count} fork(s) are active. ` +
42
- `This is a fork-contract violation. See docs/runtime.md § Parallel runtime fork contract.`, StatusCode.INTERNAL);
42
+ `This is a fork-contract violation. See docs/runtime-parallel.md § Parallel runtime fork contract.`, StatusCode.INTERNAL);
43
43
  }
44
44
  /**
45
45
  * Wrap a fresh `tableContexts` Map. In non-strict mode returns the input
@@ -1 +1 @@
1
- {"version":3,"file":"strict-fork.js","sourceRoot":"","sources":["../../../src/runtime/strict-fork.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAGhD,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAyB,MAAM,sBAAsB,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,iFAAiF;AACjF,0DAA0D;AAC1D,MAAM,WAAW,GAAG,WAAW,CAAC;AAOhC,iFAAiF;AACjF,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAqB,CAAC;AAE3D,+FAA+F;AAC/F,MAAM,iBAAiB,GAAG,IAAI,OAAO,EAAqB,CAAC;AAE3D,MAAM,UAAU,iBAAiB;IAChC,OAAO,WAAW,CAAC;AACpB,CAAC;AAED,SAAS,SAAS,CAAC,MAAc,EAAE,KAAa;IAC/C,MAAM,IAAI,YAAY,CACrB,uCAAuC,MAAM,UAAU,KAAK,uBAAuB;QACnF,0FAA0F,EAC1F,UAAU,CAAC,QAAQ,CACnB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CACtC,GAAsC;IAEtC,IAAI,CAAC,WAAW;QAAE,OAAO,GAAG,CAAC;IAC7B,MAAM,KAAK,GAAc,EAAE,WAAW,EAAE,C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C9F,qBAAqB,MAAM,qEAAqE;QAChG,2FAA2F,EAC3F,UAAU,CAAC,QAAQ,CACnB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,MAAc;IACvD,IAAI,CAAC,WAAW;QAAE,OAAO;IACzB,MAAM,WAAW,GAAG,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAClD,IAAI,WAAW;QAAE,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;AAC5D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAAiB;IACtD,IAAI,CAAC,WAAW;QAAE,OAAO,IAAI,CAAC;IAC9B,MAAM,KAAK,GAAG,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAC/C,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,KAAK,CAAC,WAAW,EAAE,CAAC;IACpB,OAAO,KAAK,CAAC;AACd,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,qBAAqB,CAAC,KAAuB;IAC5D,IAAI,CAAC,WAAW,IAAI,KAAK,KAAK,IAAI;QAAE,OAAO;IAC3C,KAAK,CAAC,WAAW,EAAE,CAAC;AACrB,CAAC"}
@@ -0,0 +1,78 @@
1
+ import { QuereusError } from '../common/errors.js';
2
+ import { type DeepReadonly, type Row, type SqlValue } from '../common/types.js';
3
+ import { type LogicalType } from '../types/logical-type.js';
4
+ /**
5
+ * Off-by-default physical-representation assertions (`QUEREUS_REPR_STRICT`).
6
+ *
7
+ * The engine canonicalizes every value it MINTS itself (see
8
+ * `util/numeric-canonical.ts` and docs/types.md § Physical representation). Two
9
+ * ingress boundaries are deliberately left uncoerced because coercing them costs
10
+ * per row where there is nothing to win:
11
+ *
12
+ * - rows returned by a virtual-table module's `query()`, including third-party
13
+ * modules the engine cannot vet;
14
+ * - values returned by user-defined functions.
15
+ *
16
+ * For those the contract is **declared and checked, not enforced**: a module or UDF
17
+ * is obliged to return canonical values, and this harness verifies it when the flag
18
+ * is on. Same shape as the parallel-fork (`QUEREUS_FORK_STRICT`) and stale-context
19
+ * (`QUEREUS_CONTEXT_STRICT`) harnesses in `strict-fork.ts`.
20
+ *
21
+ * The two rules checked here, restated from docs/types.md § Physical representation:
22
+ *
23
+ * - **R1 — canonical numeric form.** A `SqlValue` is a JS `bigint` only when its
24
+ * magnitude is outside the safe-integer range. Applies to every value, whatever its
25
+ * declared type, including `ANY` positions.
26
+ * - **R2 — per-declared-type value space.** A value in a position of a declared type
27
+ * inhabits that type's JS value space (INTEGER → safe-integer `number` or `bigint`,
28
+ * TEXT → `string`, BLOB → `Uint8Array`, …). Implies R1.
29
+ *
30
+ * `null` is always admissible: nullability is `not null` constraint enforcement's
31
+ * job and lives elsewhere.
32
+ *
33
+ * **No capability flag.** A `representationFidelity` declaration on
34
+ * `VirtualTableModule` was considered and rejected — nothing would BEHAVE differently
35
+ * based on it, since the engine tolerates both numeric forms everywhere and will
36
+ * continue to. The obligation lives in the module contract prose (`vtab/module.ts`)
37
+ * and is enforced here in tests.
38
+ *
39
+ * Every call site is guarded by `if (REPR_STRICT)` read from the module-level const in
40
+ * `strict-flags.ts`, so with the flag off each seam is one already-false branch and
41
+ * nothing is built at emit time on this module's behalf.
42
+ */
43
+ /**
44
+ * A declared type as this checker reads it. Only `name` and `physicalType` are
45
+ * consulted, and the parameter is `DeepReadonly` so both a raw `LogicalType` (column
46
+ * schema) and the frozen one a `ScalarType` carries are accepted without a cast.
47
+ */
48
+ export type DeclaredType = DeepReadonly<LogicalType>;
49
+ /** A violation of R1/R2. Distinct class so a seam inside a re-wrapping `catch`
50
+ * (the vtab scan) can rethrow it unchanged instead of burying it in a generic
51
+ * "error during query" message. */
52
+ export declare class RepresentationError extends QuereusError {
53
+ constructor(message: string);
54
+ }
55
+ /**
56
+ * R1 for one value: no `bigint` may hold a safe-range integer. Needs no declared type,
57
+ * so this is the check for `ANY` and untyped positions.
58
+ *
59
+ * `where` names the seam and the position (column / argument) and is quoted verbatim
60
+ * into the message — make it something a plugin author who has never read this code
61
+ * can act on, e.g. `` `module 'memory' scan of main.t column 2 (id)` ``.
62
+ */
63
+ export declare function assertCanonicalValue(value: SqlValue, where: string): void;
64
+ /**
65
+ * R2 for one value in a position of declared type `type` (implies R1).
66
+ * See {@link assertCanonicalValue} for what `where` should say.
67
+ */
68
+ export declare function assertConformsToType(value: SqlValue, type: DeclaredType, where: string): void;
69
+ /**
70
+ * Row form of {@link assertConformsToType}. `types[i]` may be `undefined` — an ANY /
71
+ * untyped position, which is normal and gets R1 only, never a reported violation.
72
+ * A cell past the end of `types` is treated the same way.
73
+ *
74
+ * `columnNames[i]`, when supplied, is folded into the `where` text so the message
75
+ * names the column a plugin author declared rather than an ordinal.
76
+ */
77
+ export declare function assertRowConforms(row: Row, types: readonly (DeclaredType | undefined)[], where: string, columnNames?: readonly (string | undefined)[]): void;
78
+ //# sourceMappingURL=strict-representation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strict-representation.d.ts","sourceRoot":"","sources":["../../../src/runtime/strict-representation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAc,KAAK,YAAY,EAAE,KAAK,GAAG,EAAE,KAAK,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC5F,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAI1E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,YAAY,CAAC,WAAW,CAAC,CAAC;AAErD;;oCAEoC;AACpC,qBAAa,mBAAoB,SAAQ,YAAY;gBACxC,OAAO,EAAE,MAAM;CAK3B;AAiGD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAOzE;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAS7F;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,SAAS,CAAC,YAAY,GAAG,SAAS,CAAC,EAAE,EAC5C,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,EAAE,GAC3C,IAAI,CAWN"}