Skip to main content

prune

Function prune 

Source
pub fn prune(s: &Schema) -> Schema
Expand description

An equivalent schema with everything that can never match removed: records unreachable from root are dropped; fields with max == 0 are dropped; optional (min == 0) fields whose type is an unsatisfiable record are dropped; records left unreachable/unsatisfiable after the above are dropped from the environment too.

Root-unsatisfiable case. If the root record itself is unsatisfiable (is_empty is true), field pruning is not applied to the root: its mandatory fields are exactly what make it unsatisfiable, and stripping them would silently produce a different, satisfiable schema. Instead the root record is kept as-is and only the rest of the environment is reduced to what’s reachable from it.

Environment order (omnist-ts#56). The returned environment iterates s.env() in its own declaration order, filtered to reachable – not the other way round. IndexSet::contains is a membership check only; iterating the set itself instead of the schema’s own IndexMap is exactly the bug TS’s port had (traversal order leaking into the output instead of preserving the input’s authored order).