Canonical form, canonical bytes, and identities of queries. Source:
canon.rs.Sources: SPEC-007 Sophia Query Language §4; SPEC-001 Sophia Store v0 §4 (the shared identity rule). code:
canon.rs
canonicaliseis exact:- it numbers variables by first occurrence and drops exact duplicate rules;
- the result is the smallest encoding over every valid traversal from the select: predicates by first mention, each predicate’s rules sorted with not-yet-numbered predicates masked, and every order of tied rules tried;
- beyond
CANON_BUDGET(4096) traversals the query is refused, never given an unstable id; - literal order is not normalised (SP-009 Canonical form of queries).
tests/properties.rschecks invariance under random permutations, duplicates, unreachable predicates and renaming.encode/decode: WP-66 tag-length-value framing, as for sophialang terms.query_id: the member id of a one-member component of the languagesophia-query, normalisersophia-query@0, so a stored query verifies withRecord::verifylike any definition.result_id: H(query id, snapshot, parameters).record: the store record; id constants the store knows becomerefsornominal_refs.