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:
- 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.)
- Initialize each predicate’s schema as
vec![None; arity]. - Iterate: for each rule, compute a per-rule variable-to-type
map by walking body atoms (typing vars from
base_relationsschemas first, then from currently-inferred SCC predicate schemas where columns areSome). Then back-propagate: for eachTerm::Variablein the head at columni, if the variable has a derived type, propose it as the type forhead_predicate.schema[i]. Conflict if a column has been previously typed differently. - 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.