Skip to main content

bynk_check/
builtin_names.rs

1//! Centralised string literals for the language's built-in vocabulary (refactor
2//! track item 8, v0.29.11). Built-in type/method names were compared as bare
3//! string literals scattered across the checker, emitter, and project modules;
4//! a typo was a silent never-match. One edit point per name now.
5
6/// Built-in type names (as they appear in source / qualified positions).
7pub mod types {
8    pub const JSON: &str = "Json";
9    /// #3214: the YAML decoder, `Yaml.decode[T]`, beside `Json`.
10    pub const YAML: &str = "Yaml";
11    /// #3276: the form codec, `Form.decode[T]` / `Form.encode(v)`, beside `Json`.
12    pub const FORM: &str = "Form";
13    pub const LIST: &str = "List";
14    pub const MAP: &str = "Map";
15    /// K6a (#2596): the built-in immutable set.
16    pub const SET: &str = "Set";
17    pub const INT: &str = "Int";
18    pub const FLOAT: &str = "Float";
19    pub const DURATION: &str = "Duration";
20    pub const INSTANT: &str = "Instant";
21    pub const BYTES: &str = "Bytes";
22    /// #2622: the exact decimal base type.
23    pub const DECIMAL: &str = "Decimal";
24    /// #2341 (L4): an HTTP handler's read-only view of the request's headers.
25    pub const REQUEST_HEADERS: &str = "RequestHeaders";
26    /// #2854: an HTTP handler's read-only view of the request's query string.
27    pub const REQUEST_QUERY: &str = "RequestQuery";
28    /// #3277: the raw cookies view, `cookies: RequestCookies`.
29    pub const REQUEST_COOKIES: &str = "RequestCookies";
30    /// #2380 (L5): an `Oidc` actor's verified token claims.
31    pub const TOKEN_CLAIMS: &str = "TokenClaims";
32    pub const HTTP_RESULT: &str = "HttpResult";
33    pub const QUEUE_RESULT: &str = "QueueResult";
34    pub const STREAM: &str = "Stream";
35    /// The compiler-known entry record a map's `.entries` query yields
36    /// (v0.158, ADR 0184). A nominal generic record `{ key: K, value: V }`
37    /// — bynk stays nominal (ADR 0120), so a map entry is a named record, not
38    /// an anonymous pair. Non-boundary like every generic-record instantiation
39    /// (ADR 0183): project it through `.map` into a named type before a
40    /// terminal that leaves the pipeline.
41    pub const MAP_ENTRY: &str = "MapEntry";
42}
43
44/// #2620: the ambient built-in functions that fault deliberately. Each is a
45/// bare call of the bottom type; a user declaration of the same name shadows it.
46pub mod faults {
47    pub const UNREACHABLE: &str = "unreachable";
48    pub const TODO: &str = "todo";
49
50    /// The runtime fault kind a built-in name raises, or `None` for any other name.
51    pub fn kind_of(name: &str) -> Option<&'static str> {
52        match name {
53            UNREACHABLE => Some("Unreachable"),
54            TODO => Some("Todo"),
55            _ => None,
56        }
57    }
58}
59
60/// The `.entries` / `.keys` / `.values` accessors a `store Map[K, V]` field
61/// exposes as lazy queries (v0.158, ADR 0184), and the two fields the
62/// `MapEntry` record carries.
63pub mod map_query {
64    /// `map.entries : Query[MapEntry[K, V]]`.
65    pub const ENTRIES: &str = "entries";
66    /// `map.keys : Query[K]`.
67    pub const KEYS: &str = "keys";
68    /// `map.values : Query[V]`.
69    pub const VALUES: &str = "values";
70    /// `MapEntry.key : K`.
71    pub const KEY: &str = "key";
72    /// `MapEntry.value : V`.
73    pub const VALUE: &str = "value";
74}
75
76/// Privileged built-in member names — constructors (`of`/`unsafe`), the refined
77/// raw accessor (`raw`), and the effect terminals (`foldEff`/`forEach`).
78pub mod methods {
79    pub const OF: &str = "of";
80    pub const UNSAFE: &str = "unsafe";
81    pub const RAW: &str = "raw";
82    pub const FOLD_EFF: &str = "foldEff";
83    pub const FOR_EACH: &str = "forEach";
84    pub const PAR_FOR_EACH: &str = "parForEach";
85    pub const PAR_TRAVERSE: &str = "parTraverse";
86    pub const TRAVERSE_ALL: &str = "traverseAll";
87    pub const PAR_TRAVERSE_ALL: &str = "parTraverseAll";
88    pub const TRAVERSE_TRY: &str = "traverseTry";
89    pub const PAR_TRAVERSE_TRY: &str = "parTraverseTry";
90}
91
92#[cfg(test)]
93mod tests {
94    use super::*;
95
96    #[test]
97    fn constants_hold_expected_values() {
98        assert_eq!(types::JSON, "Json");
99        assert_eq!(types::YAML, "Yaml");
100        assert_eq!(types::FORM, "Form");
101        assert_eq!(types::HTTP_RESULT, "HttpResult");
102        assert_eq!(methods::OF, "of");
103        assert_eq!(methods::FOLD_EFF, "foldEff");
104        assert_eq!(methods::FOR_EACH, "forEach");
105        assert_eq!(methods::PAR_FOR_EACH, "parForEach");
106        assert_eq!(methods::PAR_TRAVERSE, "parTraverse");
107        assert_eq!(methods::TRAVERSE_ALL, "traverseAll");
108        assert_eq!(methods::PAR_TRAVERSE_ALL, "parTraverseAll");
109        assert_eq!(methods::TRAVERSE_TRY, "traverseTry");
110        assert_eq!(methods::PAR_TRAVERSE_TRY, "parTraverseTry");
111    }
112}