pub struct Program<'p> {
pub arena: &'p Arena,
pub ext_preds: Vec<PredicateIndex>,
pub rules: FxHashMap<PredicateIndex, Vec<&'p Clause<'p>>>,
}Expand description
Represents a Mangle program consisting of logic rules and declarations.
Program wraps the AST and provides the necessary methods to identify
predicates and their dependencies. It is the primary input for the stratification algorithm.
It distinguishes between extensional predicates (stored facts) and intensional predicates (derived rules).
Fields§
§arena: &'p Arena§ext_preds: Vec<PredicateIndex>§rules: FxHashMap<PredicateIndex, Vec<&'p Clause<'p>>>Implementations§
Source§impl<'p> Program<'p>
impl<'p> Program<'p>
pub fn new(arena: &'p Arena) -> Self
pub fn add_clause<'src>(&mut self, src: &'src Arena, clause: &'src Clause<'_>)
Sourcepub fn extensional_preds(&'p self) -> PredicateSet
pub fn extensional_preds(&'p self) -> PredicateSet
Returns predicates for extensional DB (stored facts).
Sourcepub fn intensional_preds(&'p self) -> PredicateSet
pub fn intensional_preds(&'p self) -> PredicateSet
Returns predicates for intensional DB (derived rules).
Sourcepub fn rules(
&'p self,
sym: PredicateIndex,
) -> impl Iterator<Item = &'p Clause<'p>>
pub fn rules( &'p self, sym: PredicateIndex, ) -> impl Iterator<Item = &'p Clause<'p>>
Maps predicates of intensional DB to their defining rules.
Sourcepub fn stratify(self) -> Result<StratifiedProgram<'p>, String>
pub fn stratify(self) -> Result<StratifiedProgram<'p>, String>
Analyzes the program’s dependency graph and attempts to stratify it.
Stratification partitions the predicates into ordered layers (strata). This is essential for evaluating programs with negation or aggregation, ensuring that dependencies are fully evaluated before they are used.
Returns a StratifiedProgram on success, or an error if the program
contains unstratifiable cycles (e.g., negation cycles).