Skip to main content

bynk_check/
kernel_op.rs

1//! The typed built-in method operation (#3164).
2//!
3//! A built-in method call is resolved by the checker to a [`KernelOp`] and
4//! carried in [`crate::checker::Callee::Kernel`], so the emitter and the editor
5//! tooling match on a resolved enum rather than re-deriving the operation from
6//! the method's spelling. One enum per receiver kind, declared once here with
7//! each operation's source spelling and display signature; the completion
8//! tables in [`crate::kernel_methods`] are generated from the same declaration.
9
10/// One built-in kernel method: its name and a display signature.
11#[derive(Debug, Clone, Copy)]
12pub struct KernelMethod {
13    pub name: &'static str,
14    pub signature: &'static str,
15}
16
17/// Declare the per-receiver operation enums. Each operation names its source
18/// spelling and display signature; an `@hidden` operation is dispatched by the
19/// checker but kept out of the completion table (it is not a general method).
20macro_rules! kernel_ops {
21    ($(
22        $(#[$meta:meta])*
23        $Enum:ident {
24            $( $(#[$vmeta:meta])* $Var:ident = $name:literal, $sig:literal; )*
25            $( @hidden $( $(#[$hmeta:meta])* $HVar:ident = $hname:literal; )* )?
26        }
27    )*) => {
28        $(
29            $(#[$meta])*
30            #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
31            pub enum $Enum {
32                $( $(#[$vmeta])* $Var, )*
33                $($( $(#[$hmeta])* $HVar, )*)?
34            }
35
36            impl $Enum {
37                /// Every operation, in declaration order.
38                pub const ALL: &'static [$Enum] = &[
39                    $( $Enum::$Var, )* $($( $Enum::$HVar, )*)?
40                ];
41                /// The completion table for this receiver kind (no hidden operations).
42                pub const TABLE: &'static [KernelMethod] =
43                    &[ $( KernelMethod { name: $name, signature: $sig }, )* ];
44
45                /// The operation spelt `name` on this receiver kind, if any.
46                pub fn from_name(name: &str) -> Option<Self> {
47                    match name {
48                        $( $name => Some($Enum::$Var), )*
49                        $($( $hname => Some($Enum::$HVar), )*)?
50                        _ => None,
51                    }
52                }
53
54                /// The method's source spelling.
55                pub const fn name(self) -> &'static str {
56                    match self {
57                        $( $Enum::$Var => $name, )*
58                        $($( $Enum::$HVar => $hname, )*)?
59                    }
60                }
61            }
62        )*
63    };
64}
65
66kernel_ops! {
67/// `List[T]` (v0.20b; v0.88 adds the ADR 0116 query/collection vocabulary).
68    ListOp {
69        Length = "length", "length() -> Int";
70        Get = "get", "get(index: Int) -> Option[T]";
71        Prepend = "prepend", "prepend(item: T) -> List[T]";
72        // #1889: the end-of-list counterparts of `prepend`.
73        Append = "append", "append(item: T) -> List[T]";
74        Concat = "concat", "concat(other: List[T]) -> List[T]";
75        Fold = "fold", "fold(init: U, step: (U, T) -> U) -> U";
76        FoldEff = "foldEff", "foldEff(init: U, step: (U, T) -> Effect[U]) -> Effect[U]";
77        // v0.146 (ADR 0170): run an effectful step for each element, in order.
78        ForEach = "forEach", "forEach(f: T -> Effect[()]) -> Effect[()]";
79        // v0.147 (ADR 0171): run an effectful step for every element concurrently.
80        // #3967: named `parForEach`, so `parTraverse` can return the values.
81        ParForEach = "parForEach", "parForEach(f: T -> Effect[()]) -> Effect[()]";
82        ParTraverse = "parTraverse", "parTraverse(f: T -> Effect[U]) -> Effect[List[U]]";
83        // v0.148 (ADR 0172): collect every outcome (no short-circuit), sequential
84        // and concurrent.
85        TraverseAll = "traverseAll", "traverseAll(f: T -> Effect[Result[U, E]]) -> Effect[List[Result[U, E]]]";
86        ParTraverseAll = "parTraverseAll", "parTraverseAll(f: T -> Effect[Result[U, E]]) -> Effect[List[Result[U, E]]]";
87        // v0.150 (ADR 0174): short-circuit collect — stop at the first `Err`.
88        TraverseTry = "traverseTry", "traverseTry(f: T -> Effect[Result[U, E]]) -> Effect[Result[List[U], E]]";
89        ParTraverseTry = "parTraverseTry", "parTraverseTry(f: T -> Effect[Result[U, E]]) -> Effect[Result[List[U], E]]";
90        // #2806: pure `Result` accumulation over a `List[Result[T, E]]` receiver.
91        SequenceAll = "sequenceAll", "sequenceAll() -> Result[List[T], List[E]]";
92        SequenceTry = "sequenceTry", "sequenceTry() -> Result[List[T], E]";
93        // v0.88 (ADR 0116): eager in-memory builders + terminals.
94        Map = "map", "map(f: T -> U) -> List[U]";
95        Filter = "filter", "filter(p: T -> Bool) -> List[T]";
96        FlatMap = "flatMap", "flatMap(f: T -> List[U]) -> List[U]";
97        SortBy = "sortBy", "sortBy(key: T -> K) -> List[T]";
98        SortByDescending = "sortByDescending", "sortByDescending(key: T -> K) -> List[T]";
99        Take = "take", "take(n: Int) -> List[T]";
100        Skip = "skip", "skip(n: Int) -> List[T]";
101        Distinct = "distinct", "distinct() -> List[T]";
102        DistinctBy = "distinctBy", "distinctBy(key: T -> K) -> List[T]";
103        Count = "count", "count() -> Int";
104        Any = "any", "any(p: T -> Bool) -> Bool";
105        All = "all", "all(p: T -> Bool) -> Bool";
106        First = "first", "first() -> Option[T]";
107        FirstOrElse = "firstOrElse", "firstOrElse(default: T) -> T";
108        // #3962 (with #3828): the rest of `bynk.list`'s vocabulary, and the three
109        // everyday methods that existed nowhere.
110        Reverse = "reverse", "reverse() -> List[T]";
111        Find = "find", "find(p: T -> Bool) -> Option[T]";
112        Contains = "contains", "contains(item: T) -> Bool";
113        Last = "last", "last() -> Option[T]";
114        LastOrElse = "lastOrElse", "lastOrElse(default: T) -> T";
115        IsEmpty = "isEmpty", "isEmpty() -> Bool";
116        Sort = "sort", "sort() -> List[T]";
117        Traverse = "traverse", "traverse(f: T -> Effect[U]) -> Effect[List[U]]";
118        Sum = "sum", "sum(key: T -> K) -> K";
119        Min = "min", "min(key: T -> K) -> Option[K], or min() -> Option[T] for an Ord element";
120        Max = "max", "max(key: T -> K) -> Option[K], or max() -> Option[T] for an Ord element";
121        Average = "average", "average(key: T -> K) -> Option[Float]";
122        // v0.94 (ADR 0116/0120): joins & grouping, combiner form (eager — mirrors
123        // QUERY_METHODS' lazy `Query[V]` forms below, but returns `List[V]`).
124        JoinOn = "joinOn", "joinOn(other: List[U], left: T -> K, right: U -> K, into: (T, U) -> V) -> List[V]";
125        LeftJoin = "leftJoin", "leftJoin(other: List[U], left: T -> K, right: U -> K, into: (T, Option[U]) -> V) -> List[V]";
126        Join = "join", "join(other: List[U], on: (T, U) -> Bool, into: (T, U) -> V) -> List[V]";
127        GroupBy = "groupBy", "groupBy(key: T -> K, into: (K, List[T]) -> V) -> List[V]";
128        @hidden
129        // v0.119 (ADR 0155): `run.upTo(step)` on a synthesised history `Step`
130        // list only; it never leaks onto ordinary lists.
131        UpTo = "upTo";
132    }
133/// The `Set` kernel (K6a, #2596): what Bynk cannot write over a list. The
134/// combinators (`union`, `intersect`, …) are the `bynk.set` commons.
135    SetOp {
136        Length = "length", "length() -> Int";
137        Contains = "contains", "contains(item: T) -> Bool";
138        Insert = "insert", "insert(item: T) -> Set[T]";
139        Remove = "remove", "remove(item: T) -> Set[T]";
140        ToList = "toList", "toList() -> List[T]";
141        // #3961: the set algebra and the `List`-shaped vocabulary, as methods.
142        Union = "union", "union(other: Set[T]) -> Set[T]";
143        Intersect = "intersect", "intersect(other: Set[T]) -> Set[T]";
144        Difference = "difference", "difference(other: Set[T]) -> Set[T]";
145        IsSubsetOf = "isSubsetOf", "isSubsetOf(other: Set[T]) -> Bool";
146        IsEmpty = "isEmpty", "isEmpty() -> Bool";
147        Filter = "filter", "filter(p: T -> Bool) -> Set[T]";
148        Map = "map", "map(f: T -> U) -> Set[U]";
149        Fold = "fold", "fold(init: U, step: (U, T) -> U) -> U";
150    }
151/// `Map[K, V]` (v0.20b).
152    MapOp {
153        Length = "length", "length() -> Int";
154        Keys = "keys", "keys() -> List[K]";
155        Values = "values", "values() -> List[V]";
156        Get = "get", "get(key: K) -> Option[V]";
157        Insert = "insert", "insert(key: K, value: V) -> Map[K, V]";
158        // #3961: removal, membership, entry access and the `List`-shaped vocabulary.
159        Remove = "remove", "remove(key: K) -> Map[K, V]";
160        Contains = "contains", "contains(key: K) -> Bool";
161        GetOrElse = "getOrElse", "getOrElse(key: K, default: V) -> V";
162        IsEmpty = "isEmpty", "isEmpty() -> Bool";
163        Entries = "entries", "entries() -> List[MapEntry[K, V]]";
164        Filter = "filter", "filter(p: (K, V) -> Bool) -> Map[K, V]";
165        MapValues = "mapValues", "mapValues(f: V -> U) -> Map[K, U]";
166        Fold = "fold", "fold(init: U, step: (U, K, V) -> U) -> U";
167    }
168/// `Query[T]` (v0.91, ADR 0115; joins/grouping v0.94, ADR 0116/0120) — the lazy
169/// storage-query vocabulary a `store` collection lifts into (a `store Map`'s
170/// `.entries`/`.keys`/`.values`, a `store Log`'s time-window roots, or a bare
171/// `store Map` used as a value). Builders stay lazy (`Query[U]`); terminals
172/// fold into the agent's storage capability (`Effect[T]`). Mirrors
173/// [`ListOp`]'s eager vocabulary; dispatched in
174/// `crate::checker::kernels::check_query_kernel_method`, which matches on it
175/// exhaustively.
176    QueryOp {
177        Map = "map", "map(f: T -> U) -> Query[U]";
178        Filter = "filter", "filter(p: T -> Bool) -> Query[T]";
179        FlatMap = "flatMap", "flatMap(f: T -> Query[U]) -> Query[U]";
180        SortBy = "sortBy", "sortBy(key: T -> K) -> Query[T]";
181        SortByDescending = "sortByDescending", "sortByDescending(key: T -> K) -> Query[T]";
182        Take = "take", "take(n: Int) -> Query[T]";
183        Skip = "skip", "skip(n: Int) -> Query[T]";
184        Distinct = "distinct", "distinct() -> Query[T]";
185        DistinctBy = "distinctBy", "distinctBy(key: T -> K) -> Query[T]";
186        JoinOn = "joinOn", "joinOn(other: Query[U], left: T -> K, right: U -> K, into: (T, U) -> V) -> Query[V]";
187        LeftJoin = "leftJoin", "leftJoin(other: Query[U], left: T -> K, right: U -> K, into: (T, Option[U]) -> V) -> Query[V]";
188        Join = "join", "join(other: Query[U], on: (T, U) -> Bool, into: (T, U) -> V) -> Query[V]";
189        GroupBy = "groupBy", "groupBy(key: T -> K, into: (K, Query[T]) -> V) -> Query[V]";
190        Collect = "collect", "collect() -> Effect[List[T]]";
191        First = "first", "first() -> Effect[Option[T]]";
192        FirstOrElse = "firstOrElse", "firstOrElse(default: T) -> Effect[T]";
193        Count = "count", "count() -> Effect[Int]";
194        Fold = "fold", "fold(init: U, step: (U, T) -> U) -> Effect[U]";
195        Any = "any", "any(p: T -> Bool) -> Effect[Bool]";
196        All = "all", "all(p: T -> Bool) -> Effect[Bool]";
197        Sum = "sum", "sum(key: T -> K) -> Effect[K]";
198        Min = "min", "min(key: T -> K) -> Effect[Option[K]]";
199        Max = "max", "max(key: T -> K) -> Effect[Option[K]]";
200        Average = "average", "average(key: T -> K) -> Effect[Option[Float]]";
201        ForEach = "forEach", "forEach(f: T -> Effect[()]) -> Effect[()]";
202        ParTraverse = "parTraverse", "parTraverse(f: T -> Effect[()]) -> Effect[()]";
203        TraverseAll = "traverseAll", "traverseAll(f: T -> Effect[Result[U, E]]) -> Effect[List[Result[U, E]]]";
204        ParTraverseAll = "parTraverseAll", "parTraverseAll(f: T -> Effect[Result[U, E]]) -> Effect[List[Result[U, E]]]";
205        TraverseTry = "traverseTry", "traverseTry(f: T -> Effect[Result[U, E]]) -> Effect[Result[List[U], E]]";
206        ParTraverseTry = "parTraverseTry", "parTraverseTry(f: T -> Effect[Result[U, E]]) -> Effect[Result[List[U], E]]";
207    }
208/// `Option[T]` combinators (v0.22a).
209    OptionOp {
210        Map = "map", "map(f: T -> U) -> Option[U]";
211        AndThen = "andThen", "andThen(f: T -> Option[U]) -> Option[U]";
212        GetOrElse = "getOrElse", "getOrElse(default: T) -> T";
213        IsSome = "isSome", "isSome() -> Bool";
214        OkOr = "okOr", "okOr(err: E) -> Result[T, E]";
215        IsNone = "isNone", "isNone() -> Bool";
216        OrElse = "orElse", "orElse(f: () -> Option[T]) -> Option[T]";
217        Filter = "filter", "filter(p: T -> Bool) -> Option[T]";
218    }
219/// `Result[T, E]` combinators (v0.22a).
220    ResultOp {
221        Map = "map", "map(f: T -> U) -> Result[U, E]";
222        AndThen = "andThen", "andThen(f: T -> Result[U, E]) -> Result[U, E]";
223        MapErr = "mapErr", "mapErr(f: E -> F) -> Result[T, F]";
224        GetOrElse = "getOrElse", "getOrElse(default: T) -> T";
225        IsOk = "isOk", "isOk() -> Bool";
226        IsErr = "isErr", "isErr() -> Bool";
227        Ok = "ok", "ok() -> Option[T]";
228    }
229/// The `String` kernel (v0.22a; UTF-16 code units, except `chars`).
230    StringOp {
231        Length = "length", "length() -> Int";
232        Split = "split", "split(sep: String) -> List[String]";
233        Trim = "trim", "trim() -> String";
234        ToUpper = "toUpper", "toUpper() -> String";
235        ToLower = "toLower", "toLower() -> String";
236        Contains = "contains", "contains(s: String) -> Bool";
237        StartsWith = "startsWith", "startsWith(s: String) -> Bool";
238        EndsWith = "endsWith", "endsWith(s: String) -> Bool";
239        Replace = "replace", "replace(from: String, to: String) -> String";
240        Slice = "slice", "slice(start: Int, end: Int) -> String";
241        IndexOf = "indexOf", "indexOf(s: String) -> Option[Int]";
242        Chars = "chars", "chars() -> List[String]";
243        Concat = "concat", "concat(s: String) -> String";
244        // K2 (#2594): RFC 3986 percent-encoding over the UTF-8 bytes.
245        PercentEncode = "percentEncode", "percentEncode() -> String";
246        PercentDecode = "percentDecode", "percentDecode() -> Option[String]";
247        // K6c (#2600): regex methods over a string-literal pattern.
248        MatchesRegex = "matchesRegex", "matchesRegex(pattern: String) -> Bool";
249        ContainsRegex = "containsRegex", "containsRegex(pattern: String) -> Bool";
250        FindRegex = "findRegex", "findRegex(pattern: String) -> Option[List[Option[String]]]";
251        FindAllRegex = "findAllRegex", "findAllRegex(pattern: String) -> List[List[Option[String]]]";
252        ReplaceRegex = "replaceRegex", "replaceRegex(pattern: String, with: String) -> String";
253        SplitRegex = "splitRegex", "splitRegex(pattern: String) -> List[String]";
254    }
255/// The `Int` numeric kernel (v0.21).
256    IntOp {
257        ToFloat = "toFloat", "toFloat() -> Float";
258        ToString = "toString", "toString() -> String";
259        Abs = "abs", "abs() -> Int";
260        Min = "min", "min(other: Int) -> Int";
261        Max = "max", "max(other: Int) -> Int";
262        Clamp = "clamp", "clamp(lo: Int, hi: Int) -> Int";
263        // K6b (#2598): division companions (fault on zero) and an exact power.
264        Div = "div", "div(other: Int) -> Int";
265        Rem = "rem", "rem(other: Int) -> Int";
266        Mod = "mod", "mod(other: Int) -> Int";
267        Pow = "pow", "pow(exp: Int) -> Int";
268        // #2621: bitwise operations over the whole safe-integer range, faulting
269        // on a negative operand or a shift count outside 0..52.
270        And = "and", "and(other: Int) -> Int";
271        Or = "or", "or(other: Int) -> Int";
272        Xor = "xor", "xor(other: Int) -> Int";
273        AndNot = "andNot", "andNot(mask: Int) -> Int";
274        Shl = "shl", "shl(count: Int) -> Int";
275        Shr = "shr", "shr(count: Int) -> Int";
276    }
277/// The `Float` numeric kernel (v0.21).
278    FloatOp {
279        Round = "round", "round() -> Int";
280        Floor = "floor", "floor() -> Int";
281        Ceil = "ceil", "ceil() -> Int";
282        Truncate = "truncate", "truncate() -> Int";
283        ToString = "toString", "toString() -> String";
284        Abs = "abs", "abs() -> Float";
285        Min = "min", "min(other: Float) -> Float";
286        Max = "max", "max(other: Float) -> Float";
287        Clamp = "clamp", "clamp(lo: Float, hi: Float) -> Float";
288        IsNaN = "isNaN", "isNaN() -> Bool";
289        IsFinite = "isFinite", "isFinite() -> Bool";
290        // K6b (#2598): `Math` functions, host-defined outside their domains.
291        Sqrt = "sqrt", "sqrt() -> Float";
292        Pow = "pow", "pow(exp: Float) -> Float";
293        Exp = "exp", "exp() -> Float";
294        Ln = "ln", "ln() -> Float";
295        Log10 = "log10", "log10() -> Float";
296        Log2 = "log2", "log2() -> Float";
297        Sin = "sin", "sin() -> Float";
298        Cos = "cos", "cos() -> Float";
299        Tan = "tan", "tan() -> Float";
300        Asin = "asin", "asin() -> Float";
301        Acos = "acos", "acos() -> Float";
302        Atan = "atan", "atan() -> Float";
303        Atan2 = "atan2", "atan2(x: Float) -> Float";
304    }
305/// The `Duration` kernel (v0.86, ADR 0112). Comparison/arithmetic are operators
306/// (D3/D4); the kernel is the explicit escape to raw milliseconds (D5).
307    DurationOp {
308        ToMillis = "toMillis", "toMillis() -> Int";
309        ToString = "toString", "toString() -> String";
310    }
311/// The `Instant` kernel (v0.90, ADR 0114). Comparison/arithmetic are operators
312/// (D3); the kernel is the explicit escape to raw epoch milliseconds (D6).
313    InstantOp {
314        ToEpochMillis = "toEpochMillis", "toEpochMillis() -> Int";
315        ToString = "toString", "toString() -> String";
316        // K3 (#2592): RFC 3339 in UTC, `YYYY-MM-DDTHH:mm:ss.sssZ`.
317        ToIso = "toIso", "toIso() -> String";
318    }
319/// The `Bytes` kernel (v0.110, ADR 0142). Equality is an operator (D4, content
320/// compare); the kernel is length plus the String-interop bridge (D3). #2016
321/// (standard-library K1) adds `concat`, `slice`, `compare` (a method: `Bytes`
322/// stays unorderable), hex and base64url.
323    BytesOp {
324        Length = "length", "length() -> Int";
325        Concat = "concat", "concat(other: Bytes) -> Bytes";
326        Slice = "slice", "slice(start: Int, end: Int) -> Bytes";
327        Compare = "compare", "compare(other: Bytes) -> Int";
328        ToHex = "toHex", "toHex() -> String";
329        ToBase64 = "toBase64", "toBase64() -> String";
330        ToBase64Url = "toBase64Url", "toBase64Url() -> String";
331        DecodeUtf8 = "decodeUtf8", "decodeUtf8() -> Option[String]";
332    }
333/// The `Decimal` kernel (#2622). `round` and `div` take a `RoundingMode`
334/// (`RoundingMode.HalfEven`), read syntactically at that argument.
335    DecimalOp {
336        Scale = "scale", "scale() -> Int";
337        ToString = "toString", "toString() -> String";
338        Round = "round", "round(scale: Int, mode: RoundingMode) -> Decimal";
339        Div = "div", "div(other: Decimal, scale: Int, mode: RoundingMode) -> Decimal";
340        Abs = "abs", "abs() -> Decimal";
341        Min = "min", "min(other: Decimal) -> Decimal";
342        Max = "max", "max(other: Decimal) -> Decimal";
343        ToInt = "toInt", "toInt() -> Option[Int]";
344        ToFloat = "toFloat", "toFloat() -> Float";
345    }
346/// `RequestHeaders` (#2341, L4): an HTTP handler's read-only view of the
347/// request's headers.
348    RequestHeadersOp {
349        Get = "get", "get(name: String) -> Option[String]";
350        Bearer = "bearer", "bearer() -> Option[String]";
351        ClientIp = "clientIp", "clientIp() -> Option[String]";
352    }
353/// `HttpResult[T]` (#3277): attach a cookie to a response, clear one, or read the
354/// cookies a result carries (a test's view of what the router will send).
355    HttpResultOp {
356        WithCookie = "withCookie", "withCookie(c: Cookie) -> HttpResult[T]";
357        ClearCookie = "clearCookie", "clearCookie(c: Cookie) -> HttpResult[T]";
358        Cookies = "cookies", "cookies() -> List[Cookie]";
359    }
360/// `RequestQuery` (#2854): an HTTP handler's read-only view of the request's
361/// query string.
362    RequestQueryOp {
363        Get = "get", "get(name: String) -> Option[String]";
364        All = "all", "all(name: String) -> List[String]";
365        Params = "params", "params() -> Map[String, List[String]]";
366    }
367/// `RequestCookies` (#3277): an HTTP handler's read-only view of the request's
368/// cookies, for a name a record field cannot spell (`__Host-sid`).
369    RequestCookiesOp {
370        Get = "get", "get(name: String) -> Option[String]";
371        All = "all", "all(name: String) -> List[String]";
372        Names = "names", "names() -> List[String]";
373    }
374/// `TokenClaims` (#2380, L5): an `Oidc` actor's verified token claims.
375    TokenClaimsOp {
376        Get = "get", "get(name: String) -> Option[String]";
377        Has = "has", "has(name: String) -> Bool";
378    }
379/// `TestConnection[F]` (#3051): a case's recording handle for a `from
380/// websocket` connection; a test body only.
381    TestConnectionOp {
382        Sent = "sent", "sent() -> List[F]";
383        Closed = "closed", "closed() -> Bool";
384        Connection = "connection", "connection() -> Connection[F]";
385    }
386
387/// `Stream[T]` (v0.100): the lazy builders and the draining terminal. Not in
388/// the completion registry ([`crate::kernel_methods::ALL_METHODS`]).
389    StreamOp {
390        Map = "map", "map(f: T -> U) -> Stream[U]";
391        Take = "take", "take(n: Int) -> Stream[T]";
392        Collect = "collect", "collect() -> Effect[List[T]]";
393    }
394/// `Connection[F]` (v0.102): the held-resource operations. Not in the
395/// completion registry.
396    ConnectionOp {
397        Send = "send", "send(frame: F) -> Effect[()]";
398        Close = "close", "close() -> Effect[()]";
399    }
400/// `Effect[T]` (#2683, #2711, #3437): `within`, `race` and `detach`, on every `Effect`.
401    EffectOp {
402        // #2683: `e.within(d)` races `e` against a deadline and hands the
403        // abandoned effect to the execution context's `waitUntil`; it is never
404        // cancelled, so a `TimedOut` does not mean the work did not happen.
405        Within = "within", "within(d: Duration) -> Effect[Result[T, TimedOut]]";
406        // #2711: `a.race(b)`: the first side to succeed wins; the other is handed,
407        // uncancelled, to the execution context's `waitUntil`, so its side effects
408        // still happen. Meant for idempotent work.
409        Race = "race", "race(other: Effect[T]) -> Effect[T]";
410        // #3437: `e.detach()` stops waiting for `e`: it returns once the effect
411        // has been handed to the runtime, not once it has finished. A fault or
412        // an `Err` in it is reported by the runtime, never lost.
413        Detach = "detach", "detach() -> Effect[()]";
414    }
415/// The `Effect[Result[T, E]]` combinators (v0.152, ADR 0176; design doc §2.8.3),
416/// beyond [`EffectOp`]: the compiler-synthesised methods on the universal
417/// cross-context shape.
418    EffectResultOp {
419        MapOk = "mapOk", "mapOk(f: T -> U) -> Effect[Result[U, E]]";
420        MapErr = "mapErr", "mapErr(f: E -> F) -> Effect[Result[T, F]]";
421        FlatMapOk = "flatMapOk", "flatMapOk(f: T -> Effect[Result[U, E]]) -> Effect[Result[U, E]]";
422        FlatMapErr = "flatMapErr", "flatMapErr(f: E -> Effect[Result[T, F]]) -> Effect[Result[T, F]]";
423    }
424}
425
426/// A resolved built-in method: the receiver kind and the operation on it.
427#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
428pub enum KernelOp {
429    List(ListOp),
430    Query(QueryOp),
431    Stream(StreamOp),
432    Connection(ConnectionOp),
433    TestConnection(TestConnectionOp),
434    Map(MapOp),
435    Set(SetOp),
436    Int(IntOp),
437    Float(FloatOp),
438    Duration(DurationOp),
439    Instant(InstantOp),
440    RequestHeaders(RequestHeadersOp),
441    HttpResult(HttpResultOp),
442    RequestQuery(RequestQueryOp),
443    RequestCookies(RequestCookiesOp),
444    TokenClaims(TokenClaimsOp),
445    Bytes(BytesOp),
446    Decimal(DecimalOp),
447    String(StringOp),
448    Option(OptionOp),
449    Result(ResultOp),
450    /// `within`/`race`, on every `Effect[T]`.
451    Effect(EffectOp),
452    /// A combinator on an `Effect[Result[T, E]]`.
453    EffectResult(EffectResultOp),
454}
455
456impl KernelOp {
457    /// The method's source spelling.
458    pub const fn name(self) -> &'static str {
459        match self {
460            KernelOp::List(o) => o.name(),
461            KernelOp::Query(o) => o.name(),
462            KernelOp::Stream(o) => o.name(),
463            KernelOp::Connection(o) => o.name(),
464            KernelOp::TestConnection(o) => o.name(),
465            KernelOp::Map(o) => o.name(),
466            KernelOp::Set(o) => o.name(),
467            KernelOp::Int(o) => o.name(),
468            KernelOp::Float(o) => o.name(),
469            KernelOp::Duration(o) => o.name(),
470            KernelOp::Instant(o) => o.name(),
471            KernelOp::RequestHeaders(o) => o.name(),
472            KernelOp::HttpResult(o) => o.name(),
473            KernelOp::RequestQuery(o) => o.name(),
474            KernelOp::RequestCookies(o) => o.name(),
475            KernelOp::TokenClaims(o) => o.name(),
476            KernelOp::Bytes(o) => o.name(),
477            KernelOp::Decimal(o) => o.name(),
478            KernelOp::String(o) => o.name(),
479            KernelOp::Option(o) => o.name(),
480            KernelOp::Result(o) => o.name(),
481            KernelOp::Effect(o) => o.name(),
482            KernelOp::EffectResult(o) => o.name(),
483        }
484    }
485}
486
487impl KernelOp {
488    /// The operation a *base* type's kernel offers under `name`: what a bare
489    /// `Int`/`Float`/`String`/… receiver resolves to, and what a refined
490    /// receiver inherits (#561). `None` for `Bool`, which has no kernel.
491    pub fn for_base(base: bynk_syntax::ast::BaseType, name: &str) -> Option<KernelOp> {
492        use bynk_syntax::ast::BaseType;
493        match base {
494            BaseType::Int => IntOp::from_name(name).map(KernelOp::Int),
495            BaseType::Float => FloatOp::from_name(name).map(KernelOp::Float),
496            BaseType::String => StringOp::from_name(name).map(KernelOp::String),
497            BaseType::Duration => DurationOp::from_name(name).map(KernelOp::Duration),
498            BaseType::Instant => InstantOp::from_name(name).map(KernelOp::Instant),
499            BaseType::Bytes => BytesOp::from_name(name).map(KernelOp::Bytes),
500            BaseType::Decimal => DecimalOp::from_name(name).map(KernelOp::Decimal),
501            BaseType::Bool => None,
502        }
503    }
504}
505
506// ---------------------------------------------------------------------------
507// Static intrinsics (1A.33, Decision B)
508// ---------------------------------------------------------------------------
509
510kernel_ops! {
511/// `List.empty()`.
512    ListStatic {
513        Empty = "empty", "List.empty() -> List[T]";
514    }
515/// `Map.empty()`.
516    MapStatic {
517        Empty = "empty", "Map.empty() -> Map[K, V]";
518        Of = "of", "Map.of(entries: List[MapEntry[K, V]]) -> Map[K, V]";
519    }
520/// `Set.empty()` / `Set.of(xs)` (K6a, #2596).
521    SetStatic {
522        Empty = "empty", "Set.empty() -> Set[T]";
523        Of = "of", "Set.of(items: List[T]) -> Set[T]";
524    }
525/// `Int.parse(s)` (v0.22a).
526    IntStatic {
527        Parse = "parse", "Int.parse(s: String) -> Option[Int]";
528    }
529/// `Float.parse(s)`, and the K6b (#2598) constants `Float.pi()` / `Float.e()`.
530    FloatStatic {
531        Parse = "parse", "Float.parse(s: String) -> Option[Float]";
532        Pi = "pi", "Float.pi() -> Float";
533        E = "e", "Float.e() -> Float";
534    }
535/// `Decimal.parse(s)` / `Decimal.fromInt(n)` (#2622).
536    DecimalStatic {
537        Parse = "parse", "Decimal.parse(s: String) -> Option[Decimal]";
538        FromInt = "fromInt", "Decimal.fromInt(n: Int) -> Decimal";
539    }
540/// `Duration.millis(n)` (v0.86, ADR 0112).
541    DurationStatic {
542        Millis = "millis", "Duration.millis(n: Int) -> Duration";
543    }
544/// `Instant.fromEpochMillis(n)` / `Instant.fromIso(s)`.
545    InstantStatic {
546        FromEpochMillis = "fromEpochMillis", "Instant.fromEpochMillis(n: Int) -> Instant";
547        FromIso = "fromIso", "Instant.fromIso(s: String) -> Option[Instant]";
548    }
549/// The `Bytes` static constructors (v0.110, ADR 0142 D2).
550    BytesStatic {
551        FromUtf8 = "fromUtf8", "Bytes.fromUtf8(s: String) -> Bytes";
552        FromBase64 = "fromBase64", "Bytes.fromBase64(s: String) -> Option[Bytes]";
553        FromHex = "fromHex", "Bytes.fromHex(s: String) -> Option[Bytes]";
554        FromBase64Url = "fromBase64Url", "Bytes.fromBase64Url(s: String) -> Option[Bytes]";
555        Empty = "empty", "Bytes.empty() -> Bytes";
556    }
557/// `TokenClaims.of(lines)` (#2380, L5).
558    TokenClaimsStatic {
559        Of = "of", "TokenClaims.of(lines: List[String]) -> TokenClaims";
560    }
561/// `RequestHeaders.of(lines)` / `RequestHeaders.empty()` (#2341, L4).
562    RequestHeadersStatic {
563        Of = "of", "RequestHeaders.of(lines: List[String]) -> RequestHeaders";
564        Empty = "empty", "RequestHeaders.empty() -> RequestHeaders";
565    }
566/// `RequestQuery.of(pairs)` / `RequestQuery.empty()` (#2854).
567    RequestQueryStatic {
568        Of = "of", "RequestQuery.of(pairs: List[String]) -> RequestQuery";
569        Empty = "empty", "RequestQuery.empty() -> RequestQuery";
570    }
571/// `RequestCookies.of(pairs)` / `RequestCookies.empty()` (#3277).
572    RequestCookiesStatic {
573        Of = "of", "RequestCookies.of(pairs: List[String]) -> RequestCookies";
574        Empty = "empty", "RequestCookies.empty() -> RequestCookies";
575    }
576/// `Stream.of(xs)` (v0.100).
577    StreamStatic {
578        Of = "of", "Stream.of(items: List[T]) -> Stream[T]";
579    }
580/// The typed `Json` codec statics (v0.22b, ADR 0045).
581    JsonStatic {
582        Encode = "encode", "Json.encode(value: T) -> String";
583        EncodePlain = "encodePlain", "Json.encodePlain(value: T) -> String";
584        Decode = "decode", "Json.decode[T](s: String) -> Result[T, DecodeError]";
585        DecodeSql = "decodeSql", "Json.decodeSql[T](row: String) -> Result[T, DecodeError]";
586    }
587/// `Yaml.decode[T]` (#3214).
588    YamlStatic {
589        Decode = "decode", "Yaml.decode[T](s: String) -> Result[T, DecodeError]";
590    }
591/// `Form.decode[T]` / `Form.encode(v)` (#3276).
592    FormStatic {
593        Encode = "encode", "Form.encode(value: T) -> String";
594        Decode = "decode", "Form.decode[T](s: String) -> Result[T, DecodeError]";
595    }
596/// `TestConnection[F]()`, the test-side connection constructor.
597    TestConnectionStatic {
598        New = "new", "TestConnection[F]() -> TestConnection[F]";
599    }
600/// `run.id`, a test run's identity (#2138).
601    TestRunStatic {
602        Id = "id", "run.id -> String";
603    }
604}
605
606/// The namespace a [`crate::checker::Callee::Intrinsic`] belongs to: the built-in
607/// type (or, for `TestRun`, the test-body value) a static operation hangs off.
608/// Closed: every namespace the checker records is a variant, so a consumer
609/// matches exhaustively rather than comparing against a `builtin_names` constant.
610#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
611pub enum IntrinsicNs {
612    Json,
613    Yaml,
614    Form,
615    List,
616    Map,
617    Set,
618    Int,
619    Float,
620    Decimal,
621    Duration,
622    Instant,
623    Bytes,
624    TokenClaims,
625    RequestHeaders,
626    RequestQuery,
627    RequestCookies,
628    Stream,
629    /// An `HttpResult` variant reference or construction (`NotFound`, `HttpResult.Ok(x)`).
630    HttpResult,
631    /// A `QueueResult` variant (`Ack`, `Retry(reason)`).
632    QueueResult,
633    TestConnection,
634    /// `run.id` ([`crate::checker::RUN_ID_NS`]).
635    TestRun,
636}
637
638impl IntrinsicNs {
639    /// The namespace's source spelling (the `builtin_names` constant it replaces).
640    pub const fn name(self) -> &'static str {
641        use crate::builtin_names::types as t;
642        match self {
643            IntrinsicNs::Json => t::JSON,
644            IntrinsicNs::Yaml => t::YAML,
645            IntrinsicNs::Form => t::FORM,
646            IntrinsicNs::List => t::LIST,
647            IntrinsicNs::Map => t::MAP,
648            IntrinsicNs::Set => t::SET,
649            IntrinsicNs::Int => t::INT,
650            IntrinsicNs::Float => t::FLOAT,
651            IntrinsicNs::Decimal => t::DECIMAL,
652            IntrinsicNs::Duration => t::DURATION,
653            IntrinsicNs::Instant => t::INSTANT,
654            IntrinsicNs::Bytes => t::BYTES,
655            IntrinsicNs::TokenClaims => t::TOKEN_CLAIMS,
656            IntrinsicNs::RequestHeaders => t::REQUEST_HEADERS,
657            IntrinsicNs::RequestQuery => t::REQUEST_QUERY,
658            IntrinsicNs::RequestCookies => t::REQUEST_COOKIES,
659            IntrinsicNs::Stream => t::STREAM,
660            IntrinsicNs::HttpResult => t::HTTP_RESULT,
661            IntrinsicNs::QueueResult => t::QUEUE_RESULT,
662            IntrinsicNs::TestConnection => "TestConnection",
663            IntrinsicNs::TestRun => crate::checker::RUN_ID_NS,
664        }
665    }
666}
667
668/// A resolved static intrinsic: the operation a [`crate::checker::Callee::Intrinsic`]
669/// names, in the closed vocabulary of its namespace. Built by the checker once the
670/// call's method name is known to belong to the namespace, so an unknown method
671/// never gets a callee.
672///
673/// The two sum-variant namespaces (`HttpResult`, `QueueResult`) carry the variant
674/// table entry the parser already owns (`bynk_syntax::ast::HTTP_VARIANTS` /
675/// `QUEUE_VARIANTS`), which is a closed static table.
676#[derive(Debug, Clone, Copy, PartialEq, Eq)]
677pub enum StaticOp {
678    List(ListStatic),
679    Map(MapStatic),
680    Set(SetStatic),
681    Int(IntStatic),
682    Float(FloatStatic),
683    Decimal(DecimalStatic),
684    Duration(DurationStatic),
685    Instant(InstantStatic),
686    Bytes(BytesStatic),
687    TokenClaims(TokenClaimsStatic),
688    RequestHeaders(RequestHeadersStatic),
689    RequestQuery(RequestQueryStatic),
690    RequestCookies(RequestCookiesStatic),
691    Stream(StreamStatic),
692    Json(JsonStatic),
693    Yaml(YamlStatic),
694    Form(FormStatic),
695    HttpResult(bynk_syntax::ast::HttpVariant),
696    QueueResult(bynk_syntax::ast::QueueVariant),
697    TestConnection(TestConnectionStatic),
698    TestRun(TestRunStatic),
699}
700
701impl StaticOp {
702    /// The namespace this operation belongs to.
703    pub const fn ns(self) -> IntrinsicNs {
704        match self {
705            StaticOp::List(_) => IntrinsicNs::List,
706            StaticOp::Map(_) => IntrinsicNs::Map,
707            StaticOp::Set(_) => IntrinsicNs::Set,
708            StaticOp::Int(_) => IntrinsicNs::Int,
709            StaticOp::Float(_) => IntrinsicNs::Float,
710            StaticOp::Decimal(_) => IntrinsicNs::Decimal,
711            StaticOp::Duration(_) => IntrinsicNs::Duration,
712            StaticOp::Instant(_) => IntrinsicNs::Instant,
713            StaticOp::Bytes(_) => IntrinsicNs::Bytes,
714            StaticOp::TokenClaims(_) => IntrinsicNs::TokenClaims,
715            StaticOp::RequestHeaders(_) => IntrinsicNs::RequestHeaders,
716            StaticOp::RequestQuery(_) => IntrinsicNs::RequestQuery,
717            StaticOp::RequestCookies(_) => IntrinsicNs::RequestCookies,
718            StaticOp::Stream(_) => IntrinsicNs::Stream,
719            StaticOp::Json(_) => IntrinsicNs::Json,
720            StaticOp::Yaml(_) => IntrinsicNs::Yaml,
721            StaticOp::Form(_) => IntrinsicNs::Form,
722            StaticOp::HttpResult(_) => IntrinsicNs::HttpResult,
723            StaticOp::QueueResult(_) => IntrinsicNs::QueueResult,
724            StaticOp::TestConnection(_) => IntrinsicNs::TestConnection,
725            StaticOp::TestRun(_) => IntrinsicNs::TestRun,
726        }
727    }
728
729    /// The operation's source spelling (a variant's name for the sum namespaces).
730    pub const fn name(self) -> &'static str {
731        match self {
732            StaticOp::List(o) => o.name(),
733            StaticOp::Map(o) => o.name(),
734            StaticOp::Set(o) => o.name(),
735            StaticOp::Int(o) => o.name(),
736            StaticOp::Float(o) => o.name(),
737            StaticOp::Decimal(o) => o.name(),
738            StaticOp::Duration(o) => o.name(),
739            StaticOp::Instant(o) => o.name(),
740            StaticOp::Bytes(o) => o.name(),
741            StaticOp::TokenClaims(o) => o.name(),
742            StaticOp::RequestHeaders(o) => o.name(),
743            StaticOp::RequestQuery(o) => o.name(),
744            StaticOp::RequestCookies(o) => o.name(),
745            StaticOp::Stream(o) => o.name(),
746            StaticOp::Json(o) => o.name(),
747            StaticOp::Yaml(o) => o.name(),
748            StaticOp::Form(o) => o.name(),
749            StaticOp::HttpResult(v) => v.name,
750            StaticOp::QueueResult(v) => v.name,
751            StaticOp::TestConnection(o) => o.name(),
752            StaticOp::TestRun(o) => o.name(),
753        }
754    }
755
756    /// The operation spelt `name` in namespace `ns`, if the namespace has one.
757    pub fn resolve(ns: IntrinsicNs, name: &str) -> Option<StaticOp> {
758        Some(match ns {
759            IntrinsicNs::List => StaticOp::List(ListStatic::from_name(name)?),
760            IntrinsicNs::Map => StaticOp::Map(MapStatic::from_name(name)?),
761            IntrinsicNs::Set => StaticOp::Set(SetStatic::from_name(name)?),
762            IntrinsicNs::Int => StaticOp::Int(IntStatic::from_name(name)?),
763            IntrinsicNs::Float => StaticOp::Float(FloatStatic::from_name(name)?),
764            IntrinsicNs::Decimal => StaticOp::Decimal(DecimalStatic::from_name(name)?),
765            IntrinsicNs::Duration => StaticOp::Duration(DurationStatic::from_name(name)?),
766            IntrinsicNs::Instant => StaticOp::Instant(InstantStatic::from_name(name)?),
767            IntrinsicNs::Bytes => StaticOp::Bytes(BytesStatic::from_name(name)?),
768            IntrinsicNs::TokenClaims => StaticOp::TokenClaims(TokenClaimsStatic::from_name(name)?),
769            IntrinsicNs::RequestHeaders => {
770                StaticOp::RequestHeaders(RequestHeadersStatic::from_name(name)?)
771            }
772            IntrinsicNs::RequestQuery => {
773                StaticOp::RequestQuery(RequestQueryStatic::from_name(name)?)
774            }
775            IntrinsicNs::RequestCookies => {
776                StaticOp::RequestCookies(RequestCookiesStatic::from_name(name)?)
777            }
778            IntrinsicNs::Stream => StaticOp::Stream(StreamStatic::from_name(name)?),
779            IntrinsicNs::Json => StaticOp::Json(JsonStatic::from_name(name)?),
780            IntrinsicNs::Yaml => StaticOp::Yaml(YamlStatic::from_name(name)?),
781            IntrinsicNs::Form => StaticOp::Form(FormStatic::from_name(name)?),
782            IntrinsicNs::HttpResult => StaticOp::HttpResult(bynk_syntax::ast::http_variant(name)?),
783            IntrinsicNs::QueueResult => {
784                StaticOp::QueueResult(bynk_syntax::ast::queue_variant(name)?)
785            }
786            IntrinsicNs::TestConnection => {
787                StaticOp::TestConnection(TestConnectionStatic::from_name(name)?)
788            }
789            IntrinsicNs::TestRun => StaticOp::TestRun(TestRunStatic::from_name(name)?),
790        })
791    }
792}
793
794// ---------------------------------------------------------------------------
795// Store entry operations (1A.33, Decision C)
796// ---------------------------------------------------------------------------
797//
798// `MapOp`/`SetOp` above are the *value* kernels' vocabularies (`length`, `keys`,
799// `insert`); a `store` field's entry operations are a different vocabulary
800// (`put`, `remove`, `upsert`), enumerated for hover in [`crate::store_ops`]. They get
801// their own enums here, declared once with the same macro.
802
803kernel_ops! {
804/// The entry operations of a `store Map[K, V]` and a `store Cache[K, V]` (the
805/// same names; a cache's apply expiry). ADR 0110, ADR 0113.
806    MapStoreOp {
807        Put = "put", "put(key: K, value: V) -> Effect[()]";
808        Get = "get", "get(key: K) -> Effect[Option[V]]";
809        Remove = "remove", "remove(key: K) -> Effect[()]";
810        Contains = "contains", "contains(key: K) -> Effect[Bool]";
811        Size = "size", "size() -> Effect[Int]";
812        Update = "update", "update(key: K, f: (V) -> V) -> Effect[()]";
813        Upsert = "upsert", "upsert(key: K, initial: V, f: (V) -> V) -> Effect[()]";
814    }
815/// The entry operations of a `store Set[T]` (v0.83).
816    SetStoreOp {
817        Add = "add", "add(item: T) -> Effect[()]";
818        Remove = "remove", "remove(item: T) -> Effect[()]";
819        Contains = "contains", "contains(item: T) -> Effect[Bool]";
820        Size = "size", "size() -> Effect[Int]";
821    }
822/// The one method-shaped operation of a `store Cell[T]` (v0.98, ADR 0125).
823    CellStoreOp {
824        Update = "update", "update(f: (T) -> T) -> Effect[()]";
825    }
826/// The one effectful write of a `store Log[T]` (v0.95, ADR 0121).
827    LogStoreOp {
828        Append = "append", "append(entry: T) -> Effect[()]";
829    }
830/// The time-window roots of a `store Log[T]`: they lift the log into a lazy `Query[T]`.
831    LogWindowOp {
832        Since = "since", "since(start: Instant) -> Query[T]";
833        Before = "before", "before(end: Instant) -> Query[T]";
834        Between = "between", "between(start: Instant, end: Instant) -> Query[T]";
835        Recent = "recent", "recent(count: Int) -> Query[T]";
836        Reversed = "reversed", "reversed() -> Query[T]";
837    }
838}
839
840/// A resolved effectful entry operation on a `store` field, carried in
841/// [`crate::checker::Callee::Store`]: the field's kind and the operation on it.
842#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
843pub enum StoreEntryOp {
844    Map(MapStoreOp),
845    Cache(MapStoreOp),
846    Set(SetStoreOp),
847    Cell(CellStoreOp),
848    Log(LogStoreOp),
849}
850
851impl StoreEntryOp {
852    /// The operation's source spelling.
853    pub const fn name(self) -> &'static str {
854        match self {
855            StoreEntryOp::Map(o) | StoreEntryOp::Cache(o) => o.name(),
856            StoreEntryOp::Set(o) => o.name(),
857            StoreEntryOp::Cell(o) => o.name(),
858            StoreEntryOp::Log(o) => o.name(),
859        }
860    }
861
862    /// Whether the operation writes the field (a write the handler's implicit
863    /// commit persists). The same flags [`crate::store_ops`] carries for hover.
864    pub fn mutates(self) -> bool {
865        crate::store_ops::is_mutating(self.kind_head(), self.name())
866    }
867
868    /// The storage kind's head identifier (`"Map"`, `"Cache"`, …).
869    const fn kind_head(self) -> &'static str {
870        match self {
871            StoreEntryOp::Map(_) => "Map",
872            StoreEntryOp::Cache(_) => "Cache",
873            StoreEntryOp::Set(_) => "Set",
874            StoreEntryOp::Cell(_) => "Cell",
875            StoreEntryOp::Log(_) => "Log",
876        }
877    }
878}
879
880/// A resolved lifting operation on a `store` field, carried in
881/// [`crate::checker::Callee::Query`]: a query builder or terminal ([`QueryOp`]), or
882/// a `Log`'s time-window root ([`LogWindowOp`]).
883#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
884pub enum StoreQueryOp {
885    Query(QueryOp),
886    LogWindow(LogWindowOp),
887}
888
889impl StoreQueryOp {
890    /// The operation's source spelling.
891    pub const fn name(self) -> &'static str {
892        match self {
893            StoreQueryOp::Query(o) => o.name(),
894            StoreQueryOp::LogWindow(o) => o.name(),
895        }
896    }
897}
898
899#[cfg(test)]
900mod tests {
901    use super::*;
902
903    macro_rules! round_trips {
904        ($($Enum:ident),* $(,)?) => {$(
905            for op in $Enum::ALL {
906                // A duplicated spelling would resolve to its first variant.
907                assert_eq!($Enum::from_name(op.name()), Some(*op), "{op:?}");
908            }
909            assert!($Enum::ALL.len() >= $Enum::TABLE.len());
910        )*};
911    }
912
913    #[test]
914    fn every_operation_round_trips_through_its_spelling() {
915        round_trips!(
916            ListOp,
917            QueryOp,
918            StreamOp,
919            ConnectionOp,
920            TestConnectionOp,
921            MapOp,
922            SetOp,
923            IntOp,
924            FloatOp,
925            DurationOp,
926            InstantOp,
927            RequestHeadersOp,
928            HttpResultOp,
929            RequestQueryOp,
930            RequestCookiesOp,
931            TokenClaimsOp,
932            BytesOp,
933            DecimalOp,
934            StringOp,
935            OptionOp,
936            ResultOp,
937            EffectOp,
938            EffectResultOp,
939            ListStatic,
940            MapStatic,
941            SetStatic,
942            IntStatic,
943            FloatStatic,
944            DecimalStatic,
945            DurationStatic,
946            InstantStatic,
947            BytesStatic,
948            TokenClaimsStatic,
949            RequestHeadersStatic,
950            RequestQueryStatic,
951            RequestCookiesStatic,
952            StreamStatic,
953            JsonStatic,
954            YamlStatic,
955            FormStatic,
956            TestConnectionStatic,
957            TestRunStatic,
958            MapStoreOp,
959            SetStoreOp,
960            CellStoreOp,
961            LogStoreOp,
962            LogWindowOp,
963        );
964    }
965
966    /// The display signature of `name` in a completion/hover table.
967    fn signature(table: &[KernelMethod], name: &str) -> &'static str {
968        table
969            .iter()
970            .find(|m| m.name == name)
971            .unwrap_or_else(|| panic!("no `{name}` in the table"))
972            .signature
973    }
974
975    #[test]
976    fn equi_joins_display_their_two_key_functions() {
977        // `joinOn`/`leftJoin` are equi-joins checked with a left and a right
978        // key function (`check_equi_join`), not a predicate; only `join` takes
979        // `on: (T, U) -> Bool`.
980        for (table, kind) in [(ListOp::TABLE, "List"), (QueryOp::TABLE, "Query")] {
981            assert_eq!(
982                signature(table, "joinOn"),
983                format!(
984                    "joinOn(other: {kind}[U], left: T -> K, right: U -> K, into: (T, U) -> V) -> {kind}[V]"
985                ),
986            );
987            assert_eq!(
988                signature(table, "leftJoin"),
989                format!(
990                    "leftJoin(other: {kind}[U], left: T -> K, right: U -> K, into: (T, Option[U]) -> V) -> {kind}[V]"
991                ),
992            );
993            assert!(signature(table, "join").contains("on: (T, U) -> Bool"));
994        }
995    }
996
997    #[test]
998    fn an_unknown_spelling_resolves_to_nothing() {
999        assert_eq!(ListOp::from_name("nope"), None);
1000        assert_eq!(
1001            KernelOp::for_base(bynk_syntax::ast::BaseType::Bool, "length"),
1002            None
1003        );
1004    }
1005}