datalog_structural_model/
capability.rs1use crate::{Aggregator, BindingKind, FilterKind, HeadForm};
3use std::collections::BTreeSet;
4
5#[derive(
8 Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize,
9)]
10pub enum DatalogFeature {
11 StratifiedNegation,
13 TripleTerms,
15 SkolemGeneration,
17 Filter(FilterKind),
19 Binding(BindingKind),
21 Aggregate(Aggregator),
23 ConjunctiveHeads,
25 ExistentialHeads,
27 DisjunctiveHeads,
29 InconsistencyConstraints,
31}
32
33#[derive(Clone, Debug, Default, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
35#[serde(transparent)]
36pub struct DatalogCapabilities(BTreeSet<DatalogFeature>);
37impl DatalogCapabilities {
38 #[must_use]
40 pub fn positive() -> Self {
41 Self::default()
42 }
43 #[must_use]
45 pub fn with(mut self, feature: DatalogFeature) -> Self {
46 self.0.insert(feature);
47 self
48 }
49 #[must_use]
51 pub fn contains(&self, feature: &DatalogFeature) -> bool {
52 self.0.contains(feature)
53 }
54 pub fn iter(&self) -> impl Iterator<Item = &DatalogFeature> {
56 self.0.iter()
57 }
58 #[must_use]
60 pub fn all_model_features() -> Self {
61 let mut result = Self::positive()
62 .with(DatalogFeature::StratifiedNegation)
63 .with(DatalogFeature::TripleTerms)
64 .with(DatalogFeature::SkolemGeneration);
65 for form in HeadForm::ALL {
66 if let Some(feature) = form.required_feature() {
67 result.0.insert(feature);
68 }
69 }
70 for kind in FilterKind::ALL {
71 result.0.insert(DatalogFeature::Filter(*kind));
72 }
73 for kind in BindingKind::ALL {
74 result.0.insert(DatalogFeature::Binding(*kind));
75 }
76 for kind in [
77 Aggregator::Count,
78 Aggregator::Sum,
79 Aggregator::Min,
80 Aggregator::Max,
81 Aggregator::Avg,
82 ] {
83 result.0.insert(DatalogFeature::Aggregate(kind));
84 }
85 result
86 }
87 pub(crate) fn insert(&mut self, feature: DatalogFeature) {
88 self.0.insert(feature);
89 }
90 pub(crate) fn missing_from(&self, supported: &Self) -> Self {
91 Self(self.0.difference(&supported.0).copied().collect())
92 }
93 pub(crate) fn is_empty(&self) -> bool {
94 self.0.is_empty()
95 }
96}