Skip to main content

Comprehension

Struct Comprehension 

Source
pub struct Comprehension {
    pub mode: ComprehensionMode,
    pub filter: Option<String>,
    pub order: Option<TraversalOrder>,
}
Expand description

The static shape of an iteration scope. See module doc.

filter is an optional Polydat predicate evaluated against each emitted tuple. Tuples for which the predicate evaluates to Value::Bool(false) are skipped — children don’t run for them.

Predicate syntax: a string interpolation expression in the same shape as clause spec text — clause-bound names and inherited scope names appear as {name} placeholders, the rest is a const-evaluable expression. The evaluator interpolates {var} placeholders against the per-tuple kernel (which has every clause value installed and parent-scope wiring done), then runs eval_const_expr on the result. The expression must yield Value::Bool.

Examples:

  • {k} * {limit} < 1000
  • {profile} == "ann"
  • {k} > {threshold} (where threshold is an inherited name)

Cartesian and Union modes both honor the same single filter — it composes uniformly over the cross product (one predicate against each tuple) regardless of how the tuple space was assembled.

Fields§

§mode: ComprehensionMode

How the tuple space is assembled: one cross product, or a union of subspaces.

§filter: Option<String>

A predicate applied to every tuple, if any.

§order: Option<TraversalOrder>

The traversal order, if one was written.

Implementations§

Source§

impl Comprehension

Source

pub fn cartesian(clauses: Vec<Clause>) -> Comprehension

A cross product of the clauses with no filter or order.

Source

pub fn union(subspaces: Vec<Vec<Clause>>) -> Comprehension

A union of subspaces with no filter or order.

Source

pub fn union_from(subspaces: Vec<Subspace>) -> Comprehension

Construct a Union from already-wrapped Subspace values. Use this when subspaces carry metadata; the union(...) shorthand wraps bare Vec<Clause> lists.

Source

pub fn with_filter(self, predicate: impl Into<String>) -> Comprehension

Attach a filter predicate, returning self for builder chaining. The predicate is a Polydat expression that must evaluate to Value::Bool per tuple — anything else is a runtime error from the comprehension’s evaluator.

Source

pub fn with_order(self, order: TraversalOrder) -> Comprehension

Attach a traversal order, returning self for builder chaining. See TraversalOrder and SRD-18d.

Source

pub fn coordinate_names(&self) -> Vec<&str>

Variable names this comprehension declares, in declaration order, deduplicated. For Cartesian mode that’s exactly the LHS of each clause. For Union mode the names typically repeat across sub-spaces; dedup gives the operator-visible coordinate set (children see one extern per name regardless of sub-space count).

Order is first-occurrence (preserves the user’s authored intent — k before limit in "k in …, limit in …" stays in that order even after dedup).

Source

pub fn flat_clauses(&self) -> Vec<&Clause>

Every clause in the comprehension flattened into one iterator, in declaration order. For Cartesian mode that’s the clause list directly; for Union mode it’s the concatenation of all sub-spaces’ clauses (preserving order, including any repeats — callers that want unique names should use Self::coordinate_names).

Source

pub fn clause_count(&self) -> usize

Number of clauses across all sub-spaces (with repetition for Union mode). For Cartesian mode this is also the number of coordinates; for Union mode see Self::coordinate_names for the deduplicated count.

Source

pub fn is_cartesian(&self) -> bool

Whether the mode is one cross product.

Source

pub fn is_union(&self) -> bool

Whether the mode is a union of subspaces.

Source

pub fn validate(&self) -> Result<(), Vec<String>>

Validate the comprehension’s static structure. Returns the empty Ok(()) if every invariant holds; otherwise Err(messages) where each message names one violation.

This is the single entry point for AST-shape invariants — parse_comprehension_text, workload-load, dryrun, and any future linter all route through here so the rule set lives in exactly one place.

Checks performed:

  1. Non-empty clause set. Cartesian must have ≥ 1 clause; Union must have ≥ 1 sub-space, each with ≥ 1 clause.
  2. No coordinate-name collisions in Cartesian mode. Every variable must be unique across the clause list (Cartesian product of two clauses with the same name is undefined). Union mode permits repeated names — that’s the structural Union signal.
  3. Order/mode compatibility. Index-space orderings (reverse_lex, diagonal, antidiagonal, extrema, shells, halton, sobol, lhs) require a single Cartesian lattice — they’re rejected on Union mode where there is no such lattice. lex and custom are accepted on both modes.

Filter / parallel-iter length checks happen at iteration time (they require evaluation, not just structure).

Trait Implementations§

Source§

impl Clone for Comprehension

Source§

fn clone(&self) -> Comprehension

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 Comprehension

Source§

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

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

impl<'de> Deserialize<'de> for Comprehension

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<Comprehension, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for Comprehension

Canonical text rendering of a comprehension: <clauses> [where <filter>] [order <spec>].

Cartesian: clauses are joined by , . Union: each sub-space is rendered as a parenthesised clause group joined by | to make the sub-space boundaries visible (the textual short-form parser detects Union via repeated-name signal, but the explicit form is what Display emits to keep the round-trip semantics-preserving regardless of sub-space layout).

Source§

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

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

impl Eq for Comprehension

Source§

impl PartialEq for Comprehension

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for Comprehension

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Comprehension

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToCompactString for T
where T: Display,

Source§

impl<T> ToLine for T
where T: Display,

Source§

fn to_line(&self) -> Line<'_>

Converts the value to a Line.
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> ToSpan for T
where T: Display,

Source§

fn to_span(&self) -> Span<'_>

Converts the value to a Span.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToText for T
where T: Display,

Source§

fn to_text(&self) -> Text<'_>

Converts the value to a Text.
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, !>

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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more