datalog_structural_model/termination/
edge.rs1use std::fmt;
4
5use crate::ir::PredicateSymbol;
6use crate::position::{AtomSlot, RuleIndex, RuleSite};
7
8#[derive(
14 Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize,
15)]
16#[serde(deny_unknown_fields)]
17pub struct ArgumentPosition {
18 pub predicate: PredicateSymbol,
20 pub slot: AtomSlot,
22 pub rule: RuleIndex,
24 pub site: RuleSite,
26}
27
28impl ArgumentPosition {
29 #[must_use]
31 pub fn new(
32 predicate: PredicateSymbol,
33 slot: AtomSlot,
34 rule: RuleIndex,
35 site: RuleSite,
36 ) -> Self {
37 Self {
38 predicate,
39 slot,
40 rule,
41 site,
42 }
43 }
44}
45
46impl fmt::Display for ArgumentPosition {
47 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
48 write!(
49 f,
50 "{}[{}] ({}, {})",
51 self.predicate.as_str(),
52 self.slot.get(),
53 self.rule,
54 self.site
55 )
56 }
57}
58
59#[derive(
61 Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize,
62)]
63pub enum InventionKind {
64 Skolem,
66 TripleTerm,
68 Bind,
70 Aggregate,
72 Existential,
75}
76
77impl fmt::Display for InventionKind {
78 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
79 f.write_str(match self {
80 Self::Skolem => "Skolem",
81 Self::TripleTerm => "triple-term",
82 Self::Bind => "BIND",
83 Self::Aggregate => "aggregate",
84 Self::Existential => "existential",
85 })
86 }
87}
88
89#[derive(
96 Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Serialize, serde::Deserialize,
97)]
98#[serde(deny_unknown_fields)]
99pub struct SpecialEdge {
100 pub from: ArgumentPosition,
102 pub to: ArgumentPosition,
104 pub kind: InventionKind,
106}
107
108impl fmt::Display for SpecialEdge {
109 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
110 write!(f, "{} edge from {} to {}", self.kind, self.from, self.to)
111 }
112}