Skip to main content

datalog_structural_model/
limits.rs

1//! [`ValidationLimits`] — structural ceilings a program must stay within.
2
3/// Structural ceilings checked during validation. Every ceiling is
4/// inclusive: a value equal to its limit is accepted.
5///
6/// [`Self::default`] holds the standard limits used by [`Program::validate`]
7/// and the built-in profiles. A [`DatalogProfile`] owns its limits, and
8/// [`Program::validate_for`] enforces them.
9///
10/// [`Program::validate`]: crate::Program::validate
11/// [`Program::validate_for`]: crate::Program::validate_for
12/// [`DatalogProfile`]: crate::DatalogProfile
13#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, serde::Serialize, serde::Deserialize)]
14#[serde(deny_unknown_fields)]
15pub struct ValidationLimits {
16    triple_term_nesting: usize,
17    rules: usize,
18    body_literals: usize,
19    skolem_depth: usize,
20}
21
22impl ValidationLimits {
23    /// Standard triple-term nesting depth.
24    pub const STANDARD_TRIPLE_TERM_NESTING: usize = 4;
25    /// Standard number of rules in one program.
26    pub const STANDARD_RULES: usize = 65_536;
27    /// Standard number of literals in one rule body, aggregate bodies included.
28    pub const STANDARD_BODY_LITERALS: usize = 1_024;
29    /// Standard depth of invented values, as measured by
30    /// [`WeakAcyclicity::skolem_depth`](crate::WeakAcyclicity::skolem_depth).
31    pub const STANDARD_SKOLEM_DEPTH: usize = 64;
32
33    /// The standard limits.
34    #[must_use]
35    pub const fn standard() -> Self {
36        Self {
37            triple_term_nesting: Self::STANDARD_TRIPLE_TERM_NESTING,
38            rules: Self::STANDARD_RULES,
39            body_literals: Self::STANDARD_BODY_LITERALS,
40            skolem_depth: Self::STANDARD_SKOLEM_DEPTH,
41        }
42    }
43
44    /// Replace the triple-term nesting depth limit.
45    #[must_use]
46    pub const fn with_triple_term_nesting(mut self, limit: usize) -> Self {
47        self.triple_term_nesting = limit;
48        self
49    }
50
51    /// Replace the rule count limit.
52    #[must_use]
53    pub const fn with_rules(mut self, limit: usize) -> Self {
54        self.rules = limit;
55        self
56    }
57
58    /// Replace the per-rule body length limit.
59    #[must_use]
60    pub const fn with_body_literals(mut self, limit: usize) -> Self {
61        self.body_literals = limit;
62        self
63    }
64
65    /// Replace the invented-value depth limit.
66    #[must_use]
67    pub const fn with_skolem_depth(mut self, limit: usize) -> Self {
68        self.skolem_depth = limit;
69        self
70    }
71
72    /// Deepest accepted [`Term::TripleTerm`](crate::Term::TripleTerm) nesting.
73    #[must_use]
74    pub const fn triple_term_nesting(&self) -> usize {
75        self.triple_term_nesting
76    }
77
78    /// Most accepted rules in one program.
79    #[must_use]
80    pub const fn rules(&self) -> usize {
81        self.rules
82    }
83
84    /// Most accepted literals in one rule, counting aggregate inner bodies.
85    #[must_use]
86    pub const fn body_literals(&self) -> usize {
87        self.body_literals
88    }
89
90    /// Deepest accepted nesting of invented values.
91    #[must_use]
92    pub const fn skolem_depth(&self) -> usize {
93        self.skolem_depth
94    }
95}
96
97impl Default for ValidationLimits {
98    fn default() -> Self {
99        Self::standard()
100    }
101}