cyrs_db/options.rs
1//! Per-query LRU capacity options for the incremental database (spec §11.X).
2//!
3//! [`DatabaseOptions`] is passed to [`crate::workspace::Database::with_options`]
4//! at construction time; it cannot be mutated after the database is created.
5//!
6//! ## Default capacities
7//!
8//! | Query layer | Default cap | Notes |
9//! |------------------|------------|-------------------------------------|
10//! | `parse_cst` | 256 | Parse + HIR (fast; keep warm) |
11//! | `sema` | 256 | Name-res + semantic passes |
12//! | `plan` | 256 | Logical plan |
13//! | `formatted` | 256 | Formatter output |
14//! | `ast` | uncapped | Zero-cost view over parse output |
15//! | `diagnostics` | uncapped | Union of parse + sema diags |
16//!
17//! ## Salsa LRU integration
18//!
19//! Salsa 0.26 requires the `lru` capacity to be declared at compile time via
20//! `#[salsa::tracked(lru = N)]`. The compile-time constant is set to the
21//! default of 256. At construction time, if [`DatabaseOptions`] carries a
22//! different value, [`crate::workspace::Database::with_options`] calls the runtime
23//! `set_lru_capacity` API generated by Salsa to adjust the cap. When the
24//! options match the compile-time default the runtime call is elided.
25
26/// Per-query LRU capacity configuration for [`crate::workspace::Database`].
27///
28/// Pass to [`crate::workspace::Database::with_options`] at construction.
29/// The options are immutable after construction — Salsa does not support
30/// changing LRU capacity mid-session.
31///
32/// # Example
33///
34/// ```rust,ignore
35/// use cyrs_db::{Database, DatabaseOptions};
36///
37/// let opts = DatabaseOptions { parse_lru: 512, ..DatabaseOptions::default() };
38/// let db = Database::with_options(opts);
39/// ```
40#[derive(Debug, Clone, PartialEq, Eq)]
41pub struct DatabaseOptions {
42 /// Maximum number of memoised `parse_cst` / HIR results.
43 ///
44 /// Covers the `parse_cst` tracked function. Default: 256.
45 pub parse_lru: usize,
46
47 /// Maximum number of memoised semantic-analysis results.
48 ///
49 /// Covers `resolved_names` and `sema_diagnostics`. Default: 256.
50 pub sema_lru: usize,
51
52 /// Maximum number of memoised logical-plan results.
53 ///
54 /// Covers `plan_of`. Default: 256.
55 pub plan_lru: usize,
56
57 /// Maximum number of memoised formatted-output results.
58 ///
59 /// Covers any future `formatted` tracked query. Default: 256.
60 /// Currently unused — reserved for the formatter tracked query
61 /// (bead cy-31b-followup).
62 pub formatted_lru: usize,
63}
64
65impl Default for DatabaseOptions {
66 fn default() -> Self {
67 Self {
68 parse_lru: 256,
69 sema_lru: 256,
70 plan_lru: 256,
71 formatted_lru: 256,
72 }
73 }
74}