Skip to main content

infer_scc_predicate_schemas

Function infer_scc_predicate_schemas 

Source
pub fn infer_scc_predicate_schemas(
    rules: &BTreeMap<String, Vec<Rule>>,
    base_relations: &RefRelationStore,
) -> Result<InferredSchemas, InferenceError>
Expand description

Infer per-predicate schemas for a rule group via constraint propagation through the rule graph.

Algorithm:

  1. Determine head arity per predicate from the first rule with a non-empty head. (Predicates whose every rule has an empty head are treated as 0-arity; in practice this is rare.)
  2. Initialize each predicate’s schema as vec![None; arity].
  3. Iterate: for each rule, compute a per-rule variable-to-type map by walking body atoms (typing vars from base_relations schemas first, then from currently-inferred SCC predicate schemas where columns are Some). Then back-propagate: for each Term::Variable in the head at column i, if the variable has a derived type, propose it as the type for head_predicate.schema[i]. Conflict if a column has been previously typed differently.
  4. Stop when no schema column changes between iterations.

Within-rule body conflicts are NOT detected here; they are caught by the existing super::typed gate during its own per-rule type-derivation walk. See module docs for the conflict-layering split.