inference_engine/shacl12/mod.rs
1//! SHACL 1.2 scheduling over an explicitly supplied native execution backend.
2//!
3//! This controller is not a SHACL compiler or a complete SHACL processor. The
4//! backend must preflight supported rule types, expressions, conditions, targets,
5//! processors and entailment selection before constructing a plan. It supplies
6//! pinned graph scope, immutable query snapshots and queryable spilled staging.
7//! All staging belongs to a fresh attempt; any error invalidates the attempt.
8//! Only the caller can atomically publish successful output.
9
10mod controller;
11mod plan;
12mod types;
13
14pub use controller::Controller;
15pub use plan::{Plan, PlanError, Rule};
16pub use types::{ExecutionError, Limit, Limits, Report, Work, WorkExceeded};
17
18use std::{error::Error, future::Future};
19
20/// Native graph/query capabilities required by the scheduling controller.
21///
22/// This port extends beyond triple scans: a SPARQL evaluator may need an entire
23/// pinned dataset context. Never silently flatten named graphs or copy a graph
24/// into controller memory. Reuse canonical storage/query adapters. All callbacks
25/// must observe cancellation and charge streamed reads, focus nodes, expression
26/// work and candidate output through [`Work::charge`]. Dictionary, nesting, I/O,
27/// and query-engine internal budgets remain mandatory backend obligations.
28pub trait RuleBackend: Send {
29 /// Identity/handle of a preflight-checked rule, unique across linked shapes.
30 type Rule: Eq + Send + Sync;
31 /// Owned immutable view: later staging and merges cannot change its results.
32 type Snapshot: Send + Sync;
33 /// Typed native failure, never translated into absence or an empty result.
34 type Error: Error + Send + Sync + 'static;
35 /// Freeze selected base plus the current attempt's inference graph.
36 fn snapshot(&mut self) -> impl Future<Output = Result<Self::Snapshot, Self::Error>> + Send;
37 /// Compute this layer's expected derived triples once before either phase.
38 /// `rules` identifies exactly the preflight-checked rules in this layer.
39 fn begin_layer(
40 &mut self,
41 rules: &[Rule<Self::Rule>],
42 work: &mut Work,
43 ) -> impl Future<Output = Result<(), Self::Error>> + Send;
44 /// Execute one rule against exactly `snapshot`, staging into a separate phase.
45 ///
46 /// Global rules receive no focus binding. Shape rules stream the deduplicated
47 /// union of active targets across linked shapes and test all active conditions.
48 /// Preserve actual rule/focus/source/shapes/snapshot/phase evidence and fresh
49 /// term identity. Do not forge RDFS proofs. `phase` is an attempt-local ordinal.
50 /// No staged candidate may become visible to another execution in this phase.
51 fn execute(
52 &mut self,
53 rule: &Self::Rule,
54 snapshot: &Self::Snapshot,
55 phase: u64,
56 work: &mut Work,
57 ) -> impl Future<Output = Result<(), Self::Error>> + Send;
58 /// Merge the complete pending phase; return only novel inferred triples.
59 /// Deduplicate in indexed scratch, preserving assertion precedence and evidence.
60 fn merge_phase(
61 &mut self,
62 work: &mut Work,
63 ) -> impl Future<Output = Result<u64, Self::Error>> + Send;
64 /// Remove this layer's derived-only triples and annotations; retain those
65 /// independently inferred by rules. Called only after a proved fixed point.
66 fn finish_layer(
67 &mut self,
68 rules: &[Rule<Self::Rule>],
69 work: &mut Work,
70 ) -> impl Future<Output = Result<(), Self::Error>> + Send;
71 /// Remove temporary triples and their annotations, without publishing output.
72 fn finish(&mut self, work: &mut Work) -> impl Future<Output = Result<(), Self::Error>> + Send;
73 /// Whether the pinned attempt has been cancelled or superseded.
74 fn is_cancelled(&self) -> bool;
75}