Skip to main content

bock_types/
vocab.rs

1//! Catalog of annotations and strictness levels recognized by the type system.
2//!
3//! Exposed so that tooling (vocab emitter, editor completion) can render
4//! the full set without duplicating the list.
5
6use crate::Strictness;
7
8/// Metadata for a single annotation recognized by the compiler.
9pub struct AnnotationInfo {
10    /// Annotation name without the leading `@` (e.g. `"managed"`).
11    pub name: &'static str,
12    /// Comma-separated parameter names, or empty for zero-arg annotations.
13    pub params: &'static str,
14    /// One-line purpose summary.
15    pub purpose: &'static str,
16    /// Spec section reference, if any.
17    pub spec_ref: Option<&'static str>,
18}
19
20/// Metadata for a strictness level.
21pub struct StrictnessLevelInfo {
22    /// Canonical lowercase name (matches `bock.project` and the CLI).
23    pub name: &'static str,
24    /// Short description.
25    pub description: &'static str,
26    /// Spec section reference, if any.
27    pub spec_ref: Option<&'static str>,
28}
29
30/// The full set of annotations recognized by the compiler.
31#[must_use]
32pub fn annotations() -> Vec<AnnotationInfo> {
33    vec![
34        AnnotationInfo {
35            name: "managed",
36            params: "",
37            purpose: "Suppress ownership and move-checking for the annotated item.",
38            spec_ref: Some("§3.6"),
39        },
40        AnnotationInfo {
41            name: "derive",
42            params: "trait,...",
43            purpose: "Auto-derive trait implementations for a record or enum.",
44            spec_ref: Some("§4.7"),
45        },
46        AnnotationInfo {
47            name: "test",
48            params: "",
49            purpose: "Mark a function as a unit test discovered by `bock test`.",
50            spec_ref: Some("§16.2"),
51        },
52        AnnotationInfo {
53            name: "requires",
54            params: "capability,...",
55            purpose: "Declare the capabilities this function requires.",
56            spec_ref: Some("§9"),
57        },
58        AnnotationInfo {
59            name: "performance",
60            params: "max_latency, max_allocations",
61            purpose: "Declare performance budgets enforced by the context pass.",
62            spec_ref: Some("§9"),
63        },
64    ]
65}
66
67/// The full set of strictness levels supported by the compiler.
68#[must_use]
69pub fn strictness_levels() -> Vec<StrictnessLevelInfo> {
70    vec![
71        StrictnessLevelInfo {
72            name: "sketch",
73            description: "Lenient mode: effects and capabilities are inferred; no diagnostics.",
74            spec_ref: Some("§8.4"),
75        },
76        StrictnessLevelInfo {
77            name: "development",
78            description: "Public items must declare effects; private items are not checked.",
79            spec_ref: Some("§8.4"),
80        },
81        StrictnessLevelInfo {
82            name: "production",
83            description: "Every function must declare its effects and capabilities.",
84            spec_ref: Some("§8.4"),
85        },
86    ]
87}
88
89/// Canonical lowercase name for a [`Strictness`] level.
90#[must_use]
91pub fn strictness_name(level: Strictness) -> &'static str {
92    match level {
93        Strictness::Sketch => "sketch",
94        Strictness::Development => "development",
95        Strictness::Production => "production",
96    }
97}