cyrs-db 0.1.0

Salsa-backed incremental analysis database for Cypher / GQL (spec 0001 §11).
Documentation
//! Per-query LRU capacity options for the incremental database (spec §11.X).
//!
//! [`DatabaseOptions`] is passed to [`crate::workspace::Database::with_options`]
//! at construction time; it cannot be mutated after the database is created.
//!
//! ## Default capacities
//!
//! | Query layer      | Default cap | Notes                              |
//! |------------------|------------|-------------------------------------|
//! | `parse_cst`      | 256        | Parse + HIR (fast; keep warm)       |
//! | `sema`           | 256        | Name-res + semantic passes          |
//! | `plan`           | 256        | Logical plan                        |
//! | `formatted`      | 256        | Formatter output                    |
//! | `ast`            | uncapped   | Zero-cost view over parse output    |
//! | `diagnostics`    | uncapped   | Union of parse + sema diags         |
//!
//! ## Salsa LRU integration
//!
//! Salsa 0.26 requires the `lru` capacity to be declared at compile time via
//! `#[salsa::tracked(lru = N)]`.  The compile-time constant is set to the
//! default of 256.  At construction time, if [`DatabaseOptions`] carries a
//! different value, [`crate::workspace::Database::with_options`] calls the runtime
//! `set_lru_capacity` API generated by Salsa to adjust the cap.  When the
//! options match the compile-time default the runtime call is elided.

/// Per-query LRU capacity configuration for [`crate::workspace::Database`].
///
/// Pass to [`crate::workspace::Database::with_options`] at construction.
/// The options are immutable after construction — Salsa does not support
/// changing LRU capacity mid-session.
///
/// # Example
///
/// ```rust,ignore
/// use cyrs_db::{Database, DatabaseOptions};
///
/// let opts = DatabaseOptions { parse_lru: 512, ..DatabaseOptions::default() };
/// let db = Database::with_options(opts);
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct DatabaseOptions {
    /// Maximum number of memoised `parse_cst` / HIR results.
    ///
    /// Covers the `parse_cst` tracked function.  Default: 256.
    pub parse_lru: usize,

    /// Maximum number of memoised semantic-analysis results.
    ///
    /// Covers `resolved_names` and `sema_diagnostics`.  Default: 256.
    pub sema_lru: usize,

    /// Maximum number of memoised logical-plan results.
    ///
    /// Covers `plan_of`.  Default: 256.
    pub plan_lru: usize,

    /// Maximum number of memoised formatted-output results.
    ///
    /// Covers any future `formatted` tracked query.  Default: 256.
    /// Currently unused — reserved for the formatter tracked query
    /// (bead cy-31b-followup).
    pub formatted_lru: usize,
}

impl Default for DatabaseOptions {
    fn default() -> Self {
        Self {
            parse_lru: 256,
            sema_lru: 256,
            plan_lru: 256,
            formatted_lru: 256,
        }
    }
}