Skip to main content

Predicate

Enum Predicate 

Source
pub enum Predicate {
    True,
    False,
    Approximate {
        marker: String,
        paths: BTreeSet<String>,
        role: ApproximationRole,
        sound_subset: Option<Box<Predicate>>,
    },
    Guard(Guard),
    Not(Box<Predicate>),
    And(Vec<Predicate>),
    Or(Vec<Predicate>),
}
Expand description

Typed Boolean formula recovered from template control flow.

Variants§

§

True

Formula that holds for every input.

§

False

Formula that holds for no input.

§

Approximate

A control condition whose exact relation could not be lowered.

The paths remain available for diagnostics and conservative attribution, but consumers must not turn this marker into a narrowing schema condition.

Fields

§marker: String

Stable description of the expression shape that could not be lowered.

§paths: BTreeSet<String>

Values paths mentioned by the unlowerable expression.

§role: ApproximationRole

Whether the subset describes ordinary execution or returned-value selection.

§sound_subset: Option<Box<Predicate>>

A predicate that IMPLIES the real condition (a sound subset). Usable only in POSITIVE polarity where firing less often is safe — a fail-arm’s outer condition — never through a negation, which would invert the containment.

§

Guard(Guard)

Exactly lowerable atomic guard.

§

Not(Box<Predicate>)

Logical negation of a predicate.

§

And(Vec<Predicate>)

Conjunction of every enclosed predicate.

§

Or(Vec<Predicate>)

Disjunction of the enclosed predicates.

Implementations§

Source§

impl Predicate

Source

pub fn truthy_path(path: impl Into<String>) -> Self

Creates an atomic truthiness predicate for a values path.

Source

pub fn invalid_kind_path(path: impl Into<String>) -> Self

Creates the exact predicate for Sprig’s kindIs "invalid" over a values path.

Source

pub fn approximate(marker: impl Into<String>, paths: BTreeSet<String>) -> Self

Marks an unlowerable condition without inventing a relation between its paths.

Source

pub fn approximate_with_sound_subset( marker: impl Into<String>, paths: BTreeSet<String>, sound_subset: Vec<Guard>, ) -> Self

Marks an unlowerable condition that still admits a bounded sound strengthening: guards hold only in states where the real condition holds too.

Source

pub fn approximate_with_sound_predicate( marker: impl Into<String>, paths: BTreeSet<String>, sound_subset: Self, ) -> Self

Marks an unlowerable condition with a typed predicate that implies it.

Source

pub fn approximate_output_selection( marker: impl Into<String>, paths: BTreeSet<String>, sound_subset: Self, ) -> Self

Marks an inexact returned-value selection with a typed predicate that proves when the candidate supplies the result.

Source

pub fn all(predicates: Vec<Self>) -> Self

Normalizes a conjunction, collapsing empty and singleton formulas.

Source

pub fn negated(&self) -> Self

Returns the logical complement without retaining redundant double negation.

Source

pub fn normalize_boolean(self) -> Self

Canonicalizes an exact Boolean formula without distributive expansion.

Opaque approximate predicates are returned unchanged. Exact formulas use a bounded decision diagram internally and fall back to the input formula if neither normal form stays bounded.

Source

pub fn exactly_implies(&self, consequent: &Self) -> bool

Reports whether this exact Boolean formula entails consequent.

Opaque approximations never prove entailment. The bounded decision diagram may also abstain when either formula exceeds its limits.

Source

pub fn is_trivial(&self) -> bool

Reports whether the predicate is the constant true or false formula.

Source

pub fn contains_approximation(&self) -> bool

Whether this predicate contains a condition that could not be lowered exactly.

Source

pub fn value_paths(&self) -> BTreeSet<String>

Returns every values path referenced by the formula.

Source

pub fn with_context_predicates(self) -> Vec<Self>

Expands header predicates into the context-selection facts active in their bodies.

Source

pub fn conditionally_optional_paths(&self) -> BTreeSet<String>

Returns values paths whose branch structure permits them to be absent.

Source

pub fn contract_guards(&self) -> Vec<Guard>

Projects this formula into the contract guard vocabulary.

Source

pub fn contract_guards_are_exact(&self) -> bool

Whether Self::contract_guards represents this predicate EXACTLY: the flattened guard conjunction selects the same states. Negations distribute by De Morgan down to negatable guard leaves; a negation reaching a leaf the vocabulary cannot flip flattens to NOTHING, which an And flatten would silently drop — a fail conjunction missing such a conjunct negates into states the validator never rejects, so callers keep those conjuncts as raw predicates instead.

Source

pub fn contract_guard_stack(predicates: &[Self]) -> Vec<Guard>

Projects a predicate stack into a deduplicated guard conjunction.

Source

pub fn map_value_paths<F>(self, map: &mut F) -> Self
where F: FnMut(&str) -> String,

Rewrites every values path carried by this formula.

Trait Implementations§

Source§

impl Clone for Predicate

Source§

fn clone(&self) -> Predicate

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Predicate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Predicate

Source§

impl From<Guard> for Predicate

Source§

fn from(guard: Guard) -> Self

Converts to this type from the input type.
Source§

impl Hash for Predicate

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Predicate

Source§

fn cmp(&self, other: &Predicate) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 (const: unstable) · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 (const: unstable) · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 (const: unstable) · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Predicate

Source§

fn eq(&self, other: &Predicate) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl PartialOrd for Predicate

Source§

fn partial_cmp(&self, other: &Predicate) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 (const: unstable) · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 (const: unstable) · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 (const: unstable) · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl StructuralPartialEq for Predicate

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.