Skip to main content

sim_incremental_core/
budget.rs

1//! Budget records for incremental query verification and snapshots.
2
3/// The resource class that exhausted a query run.
4#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
5pub enum BudgetKind {
6    /// Query execution work units were exhausted.
7    Work,
8    /// Dependency observation records were exhausted.
9    Observations,
10    /// Nested query depth was exhausted.
11    Depth,
12    /// Output units were exhausted.
13    Output,
14}
15
16/// Limits applied while verifying queries.
17#[derive(Clone, Copy, Debug, Eq, PartialEq)]
18pub struct QueryBudgets {
19    /// Maximum query executions and explicit work charges.
20    pub max_work: usize,
21    /// Maximum dependency observations recorded during the run.
22    pub max_observations: usize,
23    /// Maximum nested query stack depth.
24    pub max_depth: usize,
25    /// Maximum output units charged by query results or user code.
26    pub max_output: usize,
27}
28
29impl QueryBudgets {
30    /// Returns an unbounded query budget.
31    #[must_use]
32    pub const fn unlimited() -> Self {
33        Self {
34            max_work: usize::MAX,
35            max_observations: usize::MAX,
36            max_depth: usize::MAX,
37            max_output: usize::MAX,
38        }
39    }
40
41    /// Returns a query budget with explicit limits.
42    #[must_use]
43    pub const fn new(
44        max_work: usize,
45        max_observations: usize,
46        max_depth: usize,
47        max_output: usize,
48    ) -> Self {
49        Self {
50            max_work,
51            max_observations,
52            max_depth,
53            max_output,
54        }
55    }
56}
57
58impl Default for QueryBudgets {
59    fn default() -> Self {
60        Self::unlimited()
61    }
62}
63
64/// Limits applied when exporting a graph snapshot.
65#[derive(Clone, Copy, Debug, Eq, PartialEq)]
66pub struct SnapshotBudgets {
67    /// Maximum memo nodes exported into the snapshot.
68    pub max_nodes: usize,
69    /// Maximum dependency edges exported into the snapshot.
70    pub max_edges: usize,
71}
72
73impl SnapshotBudgets {
74    /// Returns an unbounded snapshot budget.
75    #[must_use]
76    pub const fn unlimited() -> Self {
77        Self {
78            max_nodes: usize::MAX,
79            max_edges: usize::MAX,
80        }
81    }
82
83    /// Returns a snapshot budget with explicit node and edge limits.
84    #[must_use]
85    pub const fn new(max_nodes: usize, max_edges: usize) -> Self {
86        Self {
87            max_nodes,
88            max_edges,
89        }
90    }
91}
92
93impl Default for SnapshotBudgets {
94    fn default() -> Self {
95        Self::unlimited()
96    }
97}