Skip to main content

datalog_structural_model/ir/error/
variants.rs

1//! The [`ProgramValidationError`] variants.
2
3use crate::ir::symbols::VariableSymbol;
4use crate::position::{LiteralPath, RuleIndex, RuleSite, TermPath};
5use crate::stratify::UnstratifiableCycle;
6
7/// Program validation failures. Every failure tied to a location names the
8/// rule and, where narrower, the literal and term inside it.
9#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
10#[serde(deny_unknown_fields)]
11pub enum ProgramValidationError {
12    /// Head variables are missing from the positive body, `BIND` outputs, and
13    /// aggregate exports.
14    UnsafeRule {
15        /// Rule whose head is unsafe.
16        rule: RuleIndex,
17        /// Missing variables.
18        variables: Vec<VariableSymbol>,
19    },
20    /// A negated body literal references variables no positive body literal
21    /// binds (negation-as-failure requires a ground negated atom).
22    UnsafeNegation {
23        /// Rule containing the literal.
24        rule: RuleIndex,
25        /// The first offending negated literal.
26        literal: LiteralPath,
27        /// Its unbound variables.
28        variables: Vec<VariableSymbol>,
29    },
30    /// A [`Literal::Filter`](crate::Literal::Filter) references unbound
31    /// variables. Filters guard bindings; they cannot introduce them.
32    UnsafeFilter {
33        /// Rule containing the literal.
34        rule: RuleIndex,
35        /// The first offending filter.
36        literal: LiteralPath,
37        /// Its unbound variables.
38        variables: Vec<VariableSymbol>,
39    },
40    /// A [`Literal::Bind`](crate::Literal::Bind) references a variable not
41    /// bound earlier, or its output shadows an already-bound variable.
42    UnsafeBind {
43        /// Rule containing the literal.
44        rule: RuleIndex,
45        /// The first offending `BIND`.
46        literal: LiteralPath,
47        /// Unbound expression references or the colliding output name.
48        variables: Vec<VariableSymbol>,
49    },
50    /// A [`Literal::Aggregate`](crate::Literal::Aggregate) violates
51    /// aggregation safety: unbound `input_var` or group key, non-fresh
52    /// `result_var`, or an unsafe inner negation, filter, or `BIND`.
53    UnsafeAggregate {
54        /// Rule containing the literal.
55        rule: RuleIndex,
56        /// The first offending aggregate.
57        literal: LiteralPath,
58        /// Offending variables.
59        variables: Vec<VariableSymbol>,
60    },
61    /// An aggregate's inner body contains another aggregate. Lift the inner
62    /// aggregate into its own rule.
63    NestedAggregateInInnerBody {
64        /// Rule containing the literal.
65        rule: RuleIndex,
66        /// Path to the nested aggregate.
67        literal: LiteralPath,
68    },
69    /// The program contains a recursive cycle through negation or
70    /// aggregation.
71    UnstratifiableCycle(UnstratifiableCycle),
72    /// A negative literal under
73    /// [`EqualityMode::SameAs`](crate::EqualityMode::SameAs); equality
74    /// rewriting and negation-as-failure are mutually exclusive.
75    NegationUnderEqualityMode {
76        /// Rule containing the literal.
77        rule: RuleIndex,
78        /// The negative literal.
79        literal: LiteralPath,
80    },
81    /// An aggregate literal under
82    /// [`EqualityMode::SameAs`](crate::EqualityMode::SameAs); aggregation
83    /// needs a complete extension that equality rewriting keeps changing.
84    AggregationUnderEqualityMode {
85        /// Rule containing the literal.
86        rule: RuleIndex,
87        /// The aggregate literal.
88        literal: LiteralPath,
89    },
90    /// A body literal carries a [`Term::Skolem`](crate::Term::Skolem).
91    /// SKOLEM mints IRIs and is only well-defined in the head.
92    SkolemInBodyAtom {
93        /// Rule containing the literal.
94        rule: RuleIndex,
95        /// The body literal.
96        literal: LiteralPath,
97        /// The Skolem term inside it.
98        term: TermPath,
99    },
100    /// A [`Term::TripleTerm`](crate::Term::TripleTerm) nests deeper than
101    /// [`MAX_TRIPLE_TERM_NESTING`](crate::MAX_TRIPLE_TERM_NESTING).
102    TripleTermNestingExceeded {
103        /// Rule containing the term.
104        rule: RuleIndex,
105        /// Head or body literal containing the term.
106        site: RuleSite,
107        /// The outermost term whose nesting exceeds the limit.
108        term: TermPath,
109        /// Observed nesting depth (always greater than `limit`).
110        depth: usize,
111        /// Configured limit at the time of validation.
112        limit: usize,
113    },
114    /// A Skolem argument is neither a variable nor a constant.
115    InvalidSkolemArguments {
116        /// Rule containing the term.
117        rule: RuleIndex,
118        /// Head or body literal containing the term.
119        site: RuleSite,
120        /// The Skolem term.
121        term: TermPath,
122    },
123}