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}(wherethresholdis 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: ComprehensionModeHow 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
impl Comprehension
Sourcepub fn cartesian(clauses: Vec<Clause>) -> Comprehension
pub fn cartesian(clauses: Vec<Clause>) -> Comprehension
A cross product of the clauses with no filter or order.
Sourcepub fn union(subspaces: Vec<Vec<Clause>>) -> Comprehension
pub fn union(subspaces: Vec<Vec<Clause>>) -> Comprehension
A union of subspaces with no filter or order.
Sourcepub fn union_from(subspaces: Vec<Subspace>) -> Comprehension
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.
Sourcepub fn with_filter(self, predicate: impl Into<String>) -> Comprehension
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.
Sourcepub fn with_order(self, order: TraversalOrder) -> Comprehension
pub fn with_order(self, order: TraversalOrder) -> Comprehension
Attach a traversal order, returning self for builder
chaining. See TraversalOrder and SRD-18d.
Sourcepub fn coordinate_names(&self) -> Vec<&str>
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).
Sourcepub fn flat_clauses(&self) -> Vec<&Clause>
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).
Sourcepub fn clause_count(&self) -> usize
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.
Sourcepub fn is_cartesian(&self) -> bool
pub fn is_cartesian(&self) -> bool
Whether the mode is one cross product.
Sourcepub fn validate(&self) -> Result<(), Vec<String>>
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:
- Non-empty clause set. Cartesian must have ≥ 1 clause; Union must have ≥ 1 sub-space, each with ≥ 1 clause.
- 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.
- 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.
lexandcustomare 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
impl Clone for Comprehension
Source§fn clone(&self) -> Comprehension
fn clone(&self) -> Comprehension
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Comprehension
impl Debug for Comprehension
Source§impl<'de> Deserialize<'de> for Comprehension
impl<'de> Deserialize<'de> for Comprehension
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Comprehension, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Comprehension, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Display for Comprehension
Canonical text rendering of a comprehension:
<clauses> [where <filter>] [order <spec>].
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).
impl Eq for Comprehension
Source§impl PartialEq for Comprehension
impl PartialEq for Comprehension
Source§impl Serialize for Comprehension
impl Serialize for Comprehension
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Comprehension
Auto Trait Implementations§
impl Freeze for Comprehension
impl RefUnwindSafe for Comprehension
impl Send for Comprehension
impl Sync for Comprehension
impl Unpin for Comprehension
impl UnsafeUnpin for Comprehension
impl UnwindSafe for Comprehension
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more