@rcrsr/rill 0.16.0 → 0.18.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 (97) hide show
  1. package/README.md +37 -21
  2. package/dist/ast-nodes.d.ts +14 -4
  3. package/dist/ast-unions.d.ts +1 -1
  4. package/dist/constants.d.ts +1 -1
  5. package/dist/constants.js +1 -0
  6. package/dist/error-registry.js +228 -0
  7. package/dist/ext/crypto/index.d.ts +3 -3
  8. package/dist/ext/crypto/index.js +62 -59
  9. package/dist/ext/exec/index.d.ts +3 -3
  10. package/dist/ext/exec/index.js +15 -9
  11. package/dist/ext/fetch/index.d.ts +3 -3
  12. package/dist/ext/fetch/index.js +17 -12
  13. package/dist/ext/fetch/request.js +1 -1
  14. package/dist/ext/fs/index.d.ts +3 -3
  15. package/dist/ext/fs/index.js +256 -266
  16. package/dist/ext/fs/sandbox.d.ts +18 -0
  17. package/dist/ext/fs/sandbox.js +33 -0
  18. package/dist/ext/kv/index.d.ts +3 -3
  19. package/dist/ext/kv/index.js +198 -196
  20. package/dist/ext/kv/store.d.ts +1 -1
  21. package/dist/ext/kv/store.js +2 -1
  22. package/dist/ext-parse-bridge.d.ts +10 -0
  23. package/dist/ext-parse-bridge.js +10 -0
  24. package/dist/generated/introspection-data.d.ts +1 -1
  25. package/dist/generated/introspection-data.js +385 -296
  26. package/dist/generated/version-data.d.ts +1 -1
  27. package/dist/generated/version-data.js +2 -2
  28. package/dist/highlight-map.js +1 -0
  29. package/dist/index.d.ts +1 -4
  30. package/dist/index.js +1 -5
  31. package/dist/lexer/operators.js +1 -0
  32. package/dist/parser/helpers.js +1 -0
  33. package/dist/parser/parser-expr.js +44 -5
  34. package/dist/parser/parser-literals.js +111 -4
  35. package/dist/parser/parser-shape.js +2 -2
  36. package/dist/parser/parser-types.js +12 -0
  37. package/dist/parser/parser-use.js +26 -3
  38. package/dist/parser/parser.d.ts +2 -0
  39. package/dist/parser/parser.js +2 -0
  40. package/dist/runtime/core/callable.d.ts +24 -13
  41. package/dist/runtime/core/callable.js +71 -38
  42. package/dist/runtime/core/context.d.ts +2 -13
  43. package/dist/runtime/core/context.js +80 -79
  44. package/dist/runtime/core/eval/base.d.ts +2 -2
  45. package/dist/runtime/core/eval/base.js +2 -0
  46. package/dist/runtime/core/eval/evaluator.d.ts +1 -1
  47. package/dist/runtime/core/eval/index.d.ts +3 -3
  48. package/dist/runtime/core/eval/index.js +11 -0
  49. package/dist/runtime/core/eval/mixins/closures.js +381 -41
  50. package/dist/runtime/core/eval/mixins/collections.js +81 -6
  51. package/dist/runtime/core/eval/mixins/control-flow.js +1 -1
  52. package/dist/runtime/core/eval/mixins/conversion.js +61 -115
  53. package/dist/runtime/core/eval/mixins/core.js +17 -4
  54. package/dist/runtime/core/eval/mixins/expressions.js +36 -27
  55. package/dist/runtime/core/eval/mixins/extraction.js +2 -3
  56. package/dist/runtime/core/eval/mixins/list-dispatch.js +1 -1
  57. package/dist/runtime/core/eval/mixins/literals.js +17 -6
  58. package/dist/runtime/core/eval/mixins/types.js +73 -54
  59. package/dist/runtime/core/eval/mixins/variables.js +12 -8
  60. package/dist/runtime/core/execute.d.ts +1 -1
  61. package/dist/runtime/core/field-descriptor.d.ts +3 -3
  62. package/dist/runtime/core/field-descriptor.js +2 -1
  63. package/dist/runtime/core/introspection.d.ts +2 -2
  64. package/dist/runtime/core/introspection.js +7 -6
  65. package/dist/runtime/core/resolvers.d.ts +1 -1
  66. package/dist/runtime/core/signals.d.ts +6 -1
  67. package/dist/runtime/core/signals.js +9 -0
  68. package/dist/runtime/core/types/constructors.d.ts +54 -0
  69. package/dist/runtime/core/types/constructors.js +201 -0
  70. package/dist/runtime/core/types/guards.d.ts +42 -0
  71. package/dist/runtime/core/types/guards.js +88 -0
  72. package/dist/runtime/core/types/index.d.ts +18 -0
  73. package/dist/runtime/core/types/index.js +19 -0
  74. package/dist/runtime/core/types/markers.d.ts +12 -0
  75. package/dist/runtime/core/types/markers.js +7 -0
  76. package/dist/runtime/core/types/operations.d.ts +98 -0
  77. package/dist/runtime/core/types/operations.js +804 -0
  78. package/dist/runtime/core/types/registrations.d.ts +126 -0
  79. package/dist/runtime/core/types/registrations.js +751 -0
  80. package/dist/runtime/core/{types.d.ts → types/runtime.d.ts} +22 -10
  81. package/dist/runtime/core/types/structures.d.ts +146 -0
  82. package/dist/runtime/core/types/structures.js +12 -0
  83. package/dist/runtime/core/values.d.ts +29 -209
  84. package/dist/runtime/core/values.js +56 -968
  85. package/dist/runtime/ext/builtins.js +88 -68
  86. package/dist/runtime/ext/extensions.d.ts +31 -125
  87. package/dist/runtime/ext/extensions.js +2 -94
  88. package/dist/runtime/ext/test-context.d.ts +28 -0
  89. package/dist/runtime/ext/test-context.js +155 -0
  90. package/dist/runtime/index.d.ts +12 -12
  91. package/dist/runtime/index.js +13 -5
  92. package/dist/signature-parser.d.ts +2 -2
  93. package/dist/signature-parser.js +14 -14
  94. package/dist/token-types.d.ts +1 -0
  95. package/dist/token-types.js +1 -0
  96. package/package.json +1 -1
  97. /package/dist/runtime/core/{types.js → types/runtime.js} +0 -0
@@ -0,0 +1,201 @@
1
+ /**
2
+ * Value Constructors
3
+ *
4
+ * Factory functions for creating Rill compound values (tuples, ordered,
5
+ * vectors) and collection utilities (emptyForType, copyValue).
6
+ *
7
+ * Import constraints:
8
+ * - Imports from ./structures.js and ./guards.js
9
+ * - No imports from values.ts or callable.ts
10
+ */
11
+ import { isCallable, isIterator, isOrdered, isStream, isTuple, isTypeValue, isVector, } from './guards.js';
12
+ import { callable } from '../callable.js';
13
+ import { RuntimeError } from '../../../types.js';
14
+ /**
15
+ * Create ordered from entries array (named, preserves insertion order).
16
+ * Entries may be 2-element [name, value] or 3-element [name, value, default]
17
+ * tuples; the third element carries a default value for `.^input` reflection.
18
+ */
19
+ export function createOrdered(entries) {
20
+ return Object.freeze({ __rill_ordered: true, entries: [...entries] });
21
+ }
22
+ /** Create tuple from entries array (positional, preserves order) */
23
+ export function createTuple(entries) {
24
+ return Object.freeze({ __rill_tuple: true, entries: [...entries] });
25
+ }
26
+ /**
27
+ * Create vector from Float32Array with model name.
28
+ * @throws {RuntimeError} RILL-R074 if data.length is 0 (zero-dimension vectors not allowed)
29
+ */
30
+ export function createVector(data, model) {
31
+ if (data.length === 0) {
32
+ throw new RuntimeError('RILL-R074', 'Vector data must have at least one dimension');
33
+ }
34
+ return { __rill_vector: true, data, model };
35
+ }
36
+ /**
37
+ * Create an empty collection value matching the given TypeStructure.
38
+ * Assumes the type is dict, ordered, or tuple.
39
+ */
40
+ export function emptyForType(type) {
41
+ if (type.kind === 'dict')
42
+ return {};
43
+ if (type.kind === 'ordered')
44
+ return createOrdered([]);
45
+ if (type.kind === 'tuple')
46
+ return createTuple([]);
47
+ return {};
48
+ }
49
+ /**
50
+ * Create a RillStream from an AsyncIterable of chunks and a resolve function.
51
+ *
52
+ * The stream is a linked-list of steps. Each `.next` call advances to the
53
+ * next chunk. Once exhausted, `done` becomes true and re-iteration throws
54
+ * RILL-R002. The `resolve` function is called after chunk exhaustion (or on
55
+ * direct invocation) and caches its result for idempotent access.
56
+ *
57
+ * @throws {RuntimeError} RILL-R003 if chunks is not an AsyncIterable
58
+ * @throws {RuntimeError} RILL-R003 if resolve is not a function
59
+ */
60
+ export function createRillStream(options) {
61
+ const { chunks, resolve, dispose, chunkType, retType } = options;
62
+ // Validate chunks is AsyncIterable
63
+ if (chunks === null ||
64
+ chunks === undefined ||
65
+ typeof chunks[Symbol.asyncIterator] !==
66
+ 'function') {
67
+ throw new RuntimeError('RILL-R003', 'createRillStream requires AsyncIterable chunks');
68
+ }
69
+ // Validate resolve is a function
70
+ if (typeof resolve !== 'function') {
71
+ throw new RuntimeError('RILL-R003', 'createRillStream requires resolve function');
72
+ }
73
+ const iterator = chunks[Symbol.asyncIterator]();
74
+ let exhausted = false;
75
+ let disposed = false;
76
+ let cachedResolution;
77
+ /** Idempotent resolve wrapper that caches the resolution value. */
78
+ async function resolveOnce() {
79
+ if (cachedResolution !== undefined)
80
+ return cachedResolution.value;
81
+ const value = await resolve();
82
+ cachedResolution = { value };
83
+ return value;
84
+ }
85
+ /** Build a stream step from an iterator result. */
86
+ function makeStep(iterResult) {
87
+ if (iterResult.done) {
88
+ exhausted = true;
89
+ if (!disposed && dispose) {
90
+ disposed = true;
91
+ dispose();
92
+ }
93
+ const doneStep = {
94
+ __rill_stream: true,
95
+ done: true,
96
+ next: callable(() => {
97
+ throw new RuntimeError('RILL-R002', 'Stream already consumed; cannot re-iterate');
98
+ }),
99
+ };
100
+ return doneStep;
101
+ }
102
+ let stale = false;
103
+ const step = {
104
+ __rill_stream: true,
105
+ done: false,
106
+ value: iterResult.value,
107
+ next: callable(async () => {
108
+ if (stale) {
109
+ throw new RuntimeError('RILL-R002', 'Stream already consumed; cannot re-iterate');
110
+ }
111
+ if (exhausted) {
112
+ throw new RuntimeError('RILL-R002', 'Stream already consumed; cannot re-iterate');
113
+ }
114
+ stale = true;
115
+ const next = await iterator.next();
116
+ return makeStep(next);
117
+ }),
118
+ };
119
+ return step;
120
+ }
121
+ // Build initial step: eagerly fetch the first chunk
122
+ // The stream object itself is a "pending" step that advances on first .next call
123
+ let initialized = false;
124
+ const stream = {
125
+ __rill_stream: true,
126
+ done: false,
127
+ next: callable(async () => {
128
+ if (initialized) {
129
+ throw new RuntimeError('RILL-R002', 'Stream already consumed; cannot re-iterate');
130
+ }
131
+ initialized = true;
132
+ const first = await iterator.next();
133
+ return makeStep(first);
134
+ }),
135
+ };
136
+ // Attach resolve as a hidden property for runtime access
137
+ Object.defineProperty(stream, '__rill_stream_resolve', {
138
+ value: resolveOnce,
139
+ enumerable: false,
140
+ });
141
+ if (dispose) {
142
+ Object.defineProperty(stream, '__rill_stream_dispose', {
143
+ value: () => {
144
+ if (!disposed) {
145
+ disposed = true;
146
+ dispose();
147
+ }
148
+ },
149
+ enumerable: false,
150
+ });
151
+ }
152
+ if (chunkType) {
153
+ Object.defineProperty(stream, '__rill_stream_chunk_type', {
154
+ value: chunkType,
155
+ enumerable: false,
156
+ });
157
+ }
158
+ if (retType) {
159
+ Object.defineProperty(stream, '__rill_stream_ret_type', {
160
+ value: retType,
161
+ enumerable: false,
162
+ });
163
+ }
164
+ return stream;
165
+ }
166
+ /**
167
+ * Copy a RillValue.
168
+ * Primitives and immutable compound values return the same reference.
169
+ * Mutable values (list, dict) copy recursively.
170
+ * Iterators return the same reference (not meaningfully copyable).
171
+ */
172
+ export function copyValue(value) {
173
+ if (value === null || typeof value !== 'object')
174
+ return value;
175
+ // Immutable compound types
176
+ if (isTuple(value) ||
177
+ isOrdered(value) ||
178
+ isVector(value) ||
179
+ isTypeValue(value) ||
180
+ isCallable(value))
181
+ return value;
182
+ // field_descriptor: immutable (no guard exported from guards.ts)
183
+ if ('__rill_field_descriptor' in value &&
184
+ value['__rill_field_descriptor'] === true)
185
+ return value;
186
+ // Mutable list (Array but not tuple/ordered — those were checked above)
187
+ if (Array.isArray(value))
188
+ return value.map(copyValue);
189
+ // Iterator: mutable but opaque — return same reference
190
+ if (isIterator(value))
191
+ return value;
192
+ // Stream: immutable — return same reference
193
+ if (isStream(value))
194
+ return value;
195
+ // Mutable dict
196
+ const dict = value;
197
+ const copy = {};
198
+ for (const [k, v] of Object.entries(dict))
199
+ copy[k] = copyValue(v);
200
+ return copy;
201
+ }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Type Guards
3
+ *
4
+ * Centralized type guard functions for all Rill value types.
5
+ * Extracted from values.ts and callable.ts to break the circular
6
+ * dependency between those modules.
7
+ *
8
+ * Import constraints:
9
+ * - Imports ONLY from ./markers.js and ./structures.js
10
+ * - No imports from values.ts or callable.ts
11
+ */
12
+ import type { CallableMarker } from './markers.js';
13
+ import type { RillIterator, RillOrdered, RillStream, RillTuple, RillTypeValue, RillValue, RillVector } from './structures.js';
14
+ /** Type guard for RillTuple (spread args) */
15
+ export declare function isTuple(value: RillValue): value is RillTuple;
16
+ /** Type guard for RillVector */
17
+ export declare function isVector(value: RillValue): value is RillVector;
18
+ /** Type guard for RillOrdered (named spread args) */
19
+ export declare function isOrdered(value: RillValue): value is RillOrdered;
20
+ /** Type guard for RillTypeValue */
21
+ export declare function isTypeValue(value: RillValue): value is RillTypeValue;
22
+ /** Type guard for any callable */
23
+ export declare function isCallable(value: RillValue): value is CallableMarker;
24
+ /** Type guard for dict (plain object, not array, not callable, not tuple) */
25
+ export declare function isDict(value: RillValue): value is Record<string, RillValue>;
26
+ /**
27
+ * Type guard for RillStream (async lazy sequence with resolution).
28
+ * A stream has the __rill_stream discriminator set to true.
29
+ * Must precede isIterator in dispatch order because streams
30
+ * satisfy the iterator structural shape.
31
+ */
32
+ export declare function isStream(value: RillValue): value is RillStream;
33
+ /** Public API alias for isStream */
34
+ export declare const isRillStream: (value: RillValue) => value is RillStream;
35
+ /**
36
+ * Type guard for Rill iterator (lazy sequence).
37
+ * An iterator is a dict with:
38
+ * - done: boolean - whether iteration is complete
39
+ * - next: callable - function to get next iterator
40
+ * - value: any (only required when not done) - current element
41
+ */
42
+ export declare function isIterator(value: RillValue): value is RillIterator;
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Type Guards
3
+ *
4
+ * Centralized type guard functions for all Rill value types.
5
+ * Extracted from values.ts and callable.ts to break the circular
6
+ * dependency between those modules.
7
+ *
8
+ * Import constraints:
9
+ * - Imports ONLY from ./markers.js and ./structures.js
10
+ * - No imports from values.ts or callable.ts
11
+ */
12
+ /** Type guard for RillTuple (spread args) */
13
+ export function isTuple(value) {
14
+ return (typeof value === 'object' &&
15
+ value !== null &&
16
+ '__rill_tuple' in value &&
17
+ value.__rill_tuple === true);
18
+ }
19
+ /** Type guard for RillVector */
20
+ export function isVector(value) {
21
+ return (typeof value === 'object' &&
22
+ value !== null &&
23
+ '__rill_vector' in value &&
24
+ value.__rill_vector === true);
25
+ }
26
+ /** Type guard for RillOrdered (named spread args) */
27
+ export function isOrdered(value) {
28
+ return (typeof value === 'object' &&
29
+ value !== null &&
30
+ '__rill_ordered' in value &&
31
+ value.__rill_ordered === true);
32
+ }
33
+ /** Type guard for RillTypeValue */
34
+ export function isTypeValue(value) {
35
+ return (typeof value === 'object' &&
36
+ value !== null &&
37
+ '__rill_type' in value &&
38
+ value.__rill_type === true);
39
+ }
40
+ /** Type guard for any callable */
41
+ export function isCallable(value) {
42
+ return (typeof value === 'object' &&
43
+ value !== null &&
44
+ '__type' in value &&
45
+ value.__type === 'callable');
46
+ }
47
+ /** Type guard for dict (plain object, not array, not callable, not tuple) */
48
+ export function isDict(value) {
49
+ return (typeof value === 'object' &&
50
+ value !== null &&
51
+ !Array.isArray(value) &&
52
+ !isCallable(value) &&
53
+ !isTuple(value));
54
+ }
55
+ /**
56
+ * Type guard for RillStream (async lazy sequence with resolution).
57
+ * A stream has the __rill_stream discriminator set to true.
58
+ * Must precede isIterator in dispatch order because streams
59
+ * satisfy the iterator structural shape.
60
+ */
61
+ export function isStream(value) {
62
+ return (typeof value === 'object' &&
63
+ value !== null &&
64
+ '__rill_stream' in value &&
65
+ value.__rill_stream === true);
66
+ }
67
+ /** Public API alias for isStream */
68
+ export const isRillStream = isStream;
69
+ /**
70
+ * Type guard for Rill iterator (lazy sequence).
71
+ * An iterator is a dict with:
72
+ * - done: boolean - whether iteration is complete
73
+ * - next: callable - function to get next iterator
74
+ * - value: any (only required when not done) - current element
75
+ */
76
+ export function isIterator(value) {
77
+ if (!isDict(value))
78
+ return false;
79
+ const dict = value;
80
+ if (!('done' in dict && typeof dict['done'] === 'boolean'))
81
+ return false;
82
+ if (!('next' in dict && isCallable(dict['next'])))
83
+ return false;
84
+ // 'value' field only required when not done
85
+ if (!dict['done'] && !('value' in dict))
86
+ return false;
87
+ return true;
88
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Types Module Barrel
3
+ *
4
+ * Re-exports all public symbols from the types/ sub-modules.
5
+ * Internal runtime code may import sub-modules directly;
6
+ * this barrel provides a single import path for runtime/index.ts
7
+ * and other consumers.
8
+ */
9
+ export type { RillFieldDef, RillIterator, RillOrdered, RillStream, RillTuple, RillTypeValue, RillValue, RillVector, TypeStructure, } from './structures.js';
10
+ export type { CallableMarker, FieldDescriptorMarker } from './markers.js';
11
+ export { isCallable, isDict, isIterator, isOrdered, isRillStream, isStream, isTuple, isTypeValue, isVector, } from './guards.js';
12
+ export { copyValue, createOrdered, createRillStream, createTuple, createVector, emptyForType, } from './constructors.js';
13
+ export type { DictStructure, FieldComparisonCallbacks, OrderedStructure, TupleStructure, } from './operations.js';
14
+ export { commonType, compareStructuredFields, formatRillLiteral, formatStructure, inferElementType, inferStructure, paramToFieldDef, structureEquals, structureMatches, } from './operations.js';
15
+ export type { TypeDefinition, TypeProtocol } from './registrations.js';
16
+ export { BUILT_IN_TYPES, deepEquals, deserializeValue, formatValue, inferType, populateBuiltinMethods, serializeValue, } from './registrations.js';
17
+ export type { CaptureEvent, ErrorEvent, ExecutionResult, ExecutionStepper, ExtensionEvent, FunctionReturnEvent, HostCallEvent, NativeArray, NativePlainObject, NativeValue, ObservabilityCallbacks, ResolverResult, RuntimeCallbacks, RuntimeContext, RuntimeOptions, SchemeResolver, StepEndEvent, StepResult, StepStartEvent, } from './runtime.js';
18
+ export { bindDictCallables } from './runtime.js';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Types Module Barrel
3
+ *
4
+ * Re-exports all public symbols from the types/ sub-modules.
5
+ * Internal runtime code may import sub-modules directly;
6
+ * this barrel provides a single import path for runtime/index.ts
7
+ * and other consumers.
8
+ */
9
+ // ============================================================
10
+ // GUARDS (type guard functions for all Rill value types)
11
+ // ============================================================
12
+ export { isCallable, isDict, isIterator, isOrdered, isRillStream, isStream, isTuple, isTypeValue, isVector, } from './guards.js';
13
+ // ============================================================
14
+ // CONSTRUCTORS (factory functions for compound values)
15
+ // ============================================================
16
+ export { copyValue, createOrdered, createRillStream, createTuple, createVector, emptyForType, } from './constructors.js';
17
+ export { commonType, compareStructuredFields, formatRillLiteral, formatStructure, inferElementType, inferStructure, paramToFieldDef, structureEquals, structureMatches, } from './operations.js';
18
+ export { BUILT_IN_TYPES, deepEquals, deserializeValue, formatValue, inferType, populateBuiltinMethods, serializeValue, } from './registrations.js';
19
+ export { bindDictCallables } from './runtime.js';
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Shared marker interfaces for forward declarations.
3
+ *
4
+ * These interfaces break circular dependencies between values.ts,
5
+ * type-structures.ts, and callable.ts. Actual types are defined in callable.ts.
6
+ */
7
+ export interface CallableMarker {
8
+ readonly __type: 'callable';
9
+ }
10
+ export interface FieldDescriptorMarker {
11
+ readonly __rill_field_descriptor: true;
12
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Shared marker interfaces for forward declarations.
3
+ *
4
+ * These interfaces break circular dependencies between values.ts,
5
+ * type-structures.ts, and callable.ts. Actual types are defined in callable.ts.
6
+ */
7
+ export {};
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Type Structure Operations
3
+ *
4
+ * Structural comparison, matching, inference, and formatting functions
5
+ * extracted from values.ts. Provides `compareStructuredFields()` to
6
+ * deduplicate dict/tuple/ordered dispatch across structureEquals,
7
+ * structureMatches, and formatStructure.
8
+ *
9
+ * Import constraints:
10
+ * - Imports from ./structures.js, ./guards.js, ./registrations.js
11
+ * - Circular with registrations.ts (runtime-safe: no init-time cross-calls)
12
+ */
13
+ import type { RillFieldDef, RillValue, TypeStructure } from './structures.js';
14
+ export type DictStructure = {
15
+ kind: 'dict';
16
+ fields?: Record<string, RillFieldDef>;
17
+ valueType?: TypeStructure;
18
+ };
19
+ export type TupleStructure = {
20
+ kind: 'tuple';
21
+ elements?: RillFieldDef[];
22
+ valueType?: TypeStructure;
23
+ };
24
+ export type OrderedStructure = {
25
+ kind: 'ordered';
26
+ fields?: RillFieldDef[];
27
+ valueType?: TypeStructure;
28
+ };
29
+ /**
30
+ * Callbacks for kind-specific field dispatch in dict/tuple/ordered types.
31
+ * `compareStructuredFields` handles the common valueType check and
32
+ * kind-based field extraction, then delegates to these callbacks.
33
+ */
34
+ export interface FieldComparisonCallbacks<T> {
35
+ /** Both structures carry a uniform valueType */
36
+ onValueType(aValueType: TypeStructure, bValueType: TypeStructure): T;
37
+ /** One structure has valueType, the other does not */
38
+ onValueTypeMismatch(): T;
39
+ /** Neither structure has fields/elements */
40
+ onBothEmpty(): T;
41
+ /** One structure has fields/elements, the other does not */
42
+ onFieldPresenceMismatch(): T;
43
+ /** Dict with keyed fields on both sides */
44
+ onDictFields(aFields: Record<string, RillFieldDef>, bFields: Record<string, RillFieldDef>): T;
45
+ /** Tuple with positional elements on both sides */
46
+ onTupleElements(aElements: RillFieldDef[], bElements: RillFieldDef[]): T;
47
+ /** Ordered with named positional fields on both sides */
48
+ onOrderedFields(aFields: RillFieldDef[], bFields: RillFieldDef[]): T;
49
+ }
50
+ /**
51
+ * Shared dispatch for dict/tuple/ordered field comparison.
52
+ * Handles valueType check and field iteration across
53
+ * structureEquals, structureMatches, and formatStructure.
54
+ *
55
+ * Constraints:
56
+ * - Dict: keyed fields, sorted key comparison
57
+ * - Tuple: positional elements
58
+ * - Ordered: named positional fields
59
+ * - Recurses via caller-provided callbacks
60
+ *
61
+ * Callers validate that a.kind === b.kind before calling.
62
+ * Invalid kind values fall through to the final return.
63
+ */
64
+ export declare function compareStructuredFields<T>(a: TypeStructure, b: TypeStructure, callbacks: FieldComparisonCallbacks<T>, fallback: T): T;
65
+ /** Format a RillValue as a rill literal for use in type signatures. */
66
+ export declare function formatRillLiteral(value: RillValue): string;
67
+ /** Compare two structural types for equality. */
68
+ export declare function structureEquals(a: TypeStructure, b: TypeStructure): boolean;
69
+ /**
70
+ * Check if a value matches a structural type descriptor.
71
+ * Used for runtime type checking (`:?` operator).
72
+ */
73
+ export declare function structureMatches(value: RillValue, type: TypeStructure): boolean;
74
+ /** Format a structural type descriptor as a human-readable string. */
75
+ export declare function formatStructure(type: TypeStructure): string;
76
+ /** Build a closure param field definition from name, type, and optional default. */
77
+ export declare function paramToFieldDef(name: string, type: TypeStructure, defaultValue: RillValue | undefined): RillFieldDef;
78
+ /**
79
+ * Infer the element type for a homogeneous list.
80
+ * Empty arrays return { kind: 'any' }.
81
+ * Mixed types throw RILL-R002.
82
+ */
83
+ export declare function inferElementType(elements: RillValue[]): TypeStructure;
84
+ /** Infer the structural type descriptor for any Rill value. */
85
+ export declare function inferStructure(value: RillValue): TypeStructure;
86
+ /**
87
+ * Return the most specific shared type for two TypeStructure values.
88
+ * Returns null when types are incompatible at the top level.
89
+ *
90
+ * Cascade priority:
91
+ * 1. Any-narrowing: if either side is `any`, return the other
92
+ * 2. Structural match: delegate to structureEquals; on true, return a
93
+ * 3. Recursive list: merge inner element types
94
+ * 3b. Uniform valueType: merge dict/tuple/ordered value types
95
+ * 4. Bare type fallback: same compound type but structural mismatch
96
+ * 5. Incompatible: different top-level types return null
97
+ */
98
+ export declare function commonType(a: TypeStructure, b: TypeStructure): TypeStructure | null;