Skip to main content

mago_codex/
assertion.rs

1use std::borrow::Cow;
2use std::hash::BuildHasher;
3use std::hash::Hash;
4
5use foldhash::fast::FixedState;
6
7use mago_word::Word;
8use mago_word::concat_word;
9use mago_word::i64_word;
10use mago_word::usize_word;
11use mago_word::word;
12
13use crate::metadata::CodebaseMetadata;
14use crate::ttype::TType;
15use crate::ttype::atomic::TAtomic;
16use crate::ttype::atomic::array::key::ArrayKey;
17use crate::ttype::template::TemplateResult;
18use crate::ttype::template::inferred_type_replacer;
19use crate::ttype::union::TUnion;
20
21#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
22#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
23pub enum Assertion {
24    Any,
25    IsType(TAtomic),
26    IsNotType(TAtomic),
27    Falsy,
28    Truthy,
29    IsIdentical(TAtomic),
30    IsNotIdentical(TAtomic),
31    IsEqual(TAtomic),
32    IsNotEqual(TAtomic),
33    IsEqualIsset,
34    IsIsset,
35    IsNotIsset,
36    HasStringArrayAccess,
37    HasIntOrStringArrayAccess,
38    ArrayKeyExists,
39    ArrayKeyDoesNotExist,
40    InArray(TUnion),
41    NotInArray(TUnion),
42    HasArrayKey(ArrayKey),
43    DoesNotHaveArrayKey(ArrayKey),
44    HasNonnullEntryForKey(ArrayKey),
45    DoesNotHaveNonnullEntryForKey(ArrayKey),
46    Empty,
47    NonEmpty,
48    NonEmptyCountable(bool),
49    EmptyCountable,
50    HasExactCount(usize),
51    HasAtLeastCount(usize),
52    DoesNotHaveExactCount(usize),
53    DoesNotHasAtLeastCount(usize),
54    IsLessThan(i64),
55    IsLessThanOrEqual(i64),
56    IsGreaterThan(i64),
57    IsGreaterThanOrEqual(i64),
58    /// A range fact implied by a comparison with a non-literal bound.
59    ///
60    /// For example, `$a > $b` with `int<0, max> $b` implies `$a > 0`
61    /// in the true branch, but its negation does not imply `$a <= 0`.
62    /// These assertions therefore deliberately negate to `Any`.
63    IsLessThanFromBound(i64),
64    IsLessThanOrEqualFromBound(i64),
65    IsGreaterThanFromBound(i64),
66    IsGreaterThanOrEqualFromBound(i64),
67    /// An exact comparison with another tracked expression.
68    ///
69    /// Unlike bound-derived facts, these retain the relationship so consumers
70    /// can reason about arithmetic such as `$limit - $length` after
71    /// `$length < $limit`.
72    IsLessThanVariable(Word),
73    IsLessThanOrEqualVariable(Word),
74    IsGreaterThanVariable(Word),
75    IsGreaterThanOrEqualVariable(Word),
76    StringLengthLessThan(i64),
77    StringLengthGreaterThanOrEqual(i64),
78    Countable,
79    NotCountable(bool),
80}
81
82impl Assertion {
83    #[must_use]
84    pub fn to_atom(&self) -> Word {
85        match self {
86            Assertion::Any => word("any"),
87            Assertion::Falsy => word("falsy"),
88            Assertion::Truthy => word("truthy"),
89            Assertion::IsEqualIsset => word("=isset"),
90            Assertion::IsIsset => word("isset"),
91            Assertion::IsNotIsset => word("!isset"),
92            Assertion::HasStringArrayAccess => word("=string-array-access"),
93            Assertion::HasIntOrStringArrayAccess => word("=int-or-string-array-access"),
94            Assertion::ArrayKeyExists => word("array-key-exists"),
95            Assertion::ArrayKeyDoesNotExist => word("!array-key-exists"),
96            Assertion::EmptyCountable => word("empty-countable"),
97            Assertion::Empty => word("empty"),
98            Assertion::NonEmpty => word("non-empty"),
99            Assertion::Countable => word("countable"),
100            Assertion::NotCountable(_) => word("!countable"),
101            Assertion::IsType(atomic) => atomic.get_id(),
102            Assertion::IsNotType(atomic) => concat_word!(b"!", atomic.get_id()),
103            Assertion::IsIdentical(atomic) => concat_word!(b"=", atomic.get_id()),
104            Assertion::IsNotIdentical(atomic) => concat_word!(b"!=", atomic.get_id()),
105            Assertion::IsEqual(atomic) => concat_word!(b"~", atomic.get_id()),
106            Assertion::IsNotEqual(atomic) => concat_word!(b"!~", atomic.get_id()),
107            Assertion::InArray(union) => concat_word!(b"=in-array-", union.get_id()),
108            Assertion::NotInArray(union) => concat_word!(b"!=in-array-", union.get_id()),
109            Assertion::HasArrayKey(key) => concat_word!(b"=has-array-key-", key.to_atom()),
110            Assertion::DoesNotHaveArrayKey(key) => concat_word!(b"!=has-array-key-", key.to_atom()),
111            Assertion::HasNonnullEntryForKey(key) => concat_word!(b"=has-nonnull-entry-for-", key.to_atom()),
112            Assertion::DoesNotHaveNonnullEntryForKey(key) => {
113                concat_word!(b"!=has-nonnull-entry-for-", key.to_atom())
114            }
115            Assertion::HasExactCount(number) => concat_word!(b"has-exactly-", usize_word(*number)),
116            Assertion::HasAtLeastCount(number) => concat_word!(b"has-at-least-", usize_word(*number)),
117            Assertion::DoesNotHaveExactCount(number) => concat_word!(b"!has-exactly-", usize_word(*number)),
118            Assertion::DoesNotHasAtLeastCount(number) => concat_word!(b"has-at-most-", usize_word(*number)),
119            Assertion::IsLessThan(number) => concat_word!(b"is-less-than-", i64_word(*number)),
120            Assertion::IsLessThanOrEqual(number) => concat_word!(b"is-less-than-or-equal-", i64_word(*number)),
121            Assertion::IsGreaterThan(number) => concat_word!(b"is-greater-than-", i64_word(*number)),
122            Assertion::IsGreaterThanOrEqual(number) => concat_word!(b"is-greater-than-or-equal-", i64_word(*number)),
123            Assertion::IsLessThanFromBound(number) => concat_word!(b"is-less-than-from-bound-", i64_word(*number)),
124            Assertion::IsLessThanOrEqualFromBound(number) => {
125                concat_word!(b"is-less-than-or-equal-from-bound-", i64_word(*number))
126            }
127            Assertion::IsGreaterThanFromBound(number) => {
128                concat_word!(b"is-greater-than-from-bound-", i64_word(*number))
129            }
130            Assertion::IsGreaterThanOrEqualFromBound(number) => {
131                concat_word!(b"is-greater-than-or-equal-from-bound-", i64_word(*number))
132            }
133            Assertion::IsLessThanVariable(variable) => concat_word!(b"is-less-than-variable-", variable),
134            Assertion::IsLessThanOrEqualVariable(variable) => {
135                concat_word!(b"is-less-than-or-equal-variable-", variable)
136            }
137            Assertion::IsGreaterThanVariable(variable) => {
138                concat_word!(b"is-greater-than-variable-", variable)
139            }
140            Assertion::IsGreaterThanOrEqualVariable(variable) => {
141                concat_word!(b"is-greater-than-or-equal-variable-", variable)
142            }
143            Assertion::StringLengthLessThan(number) => {
144                concat_word!(b"string-length-is-less-than-", i64_word(*number))
145            }
146            Assertion::StringLengthGreaterThanOrEqual(number) => {
147                concat_word!(b"string-length-is-greater-than-or-equal-", i64_word(*number))
148            }
149            Assertion::NonEmptyCountable(negatable) => {
150                if *negatable {
151                    word("non-empty-countable")
152                } else {
153                    word("=non-empty-countable")
154                }
155            }
156        }
157    }
158
159    #[must_use]
160    pub fn to_hash(&self) -> u64 {
161        FixedState::default().hash_one(self.to_atom())
162    }
163
164    /// Hash the opposite assertion without copying its type.
165    #[must_use]
166    pub fn negated_hash(&self) -> u64 {
167        let atom = match self {
168            Self::IsType(atomic) => concat_word!(b"!", atomic.get_id()),
169            Self::IsNotType(atomic) => atomic.get_id(),
170            Self::IsIdentical(atomic) => concat_word!(b"!=", atomic.get_id()),
171            Self::IsNotIdentical(atomic) => concat_word!(b"=", atomic.get_id()),
172            Self::IsEqual(atomic) => concat_word!(b"!~", atomic.get_id()),
173            Self::IsNotEqual(atomic) => concat_word!(b"~", atomic.get_id()),
174            Self::InArray(union) => concat_word!(b"!=in-array-", union.get_id()),
175            Self::NotInArray(union) => concat_word!(b"=in-array-", union.get_id()),
176            _ => self.get_negation().to_atom(),
177        };
178
179        FixedState::default().hash_one(atom)
180    }
181
182    #[must_use]
183    pub fn is_negation(&self) -> bool {
184        matches!(
185            self,
186            Assertion::Falsy
187                | Assertion::IsNotType(_)
188                | Assertion::IsNotEqual(_)
189                | Assertion::IsNotIdentical(_)
190                | Assertion::IsNotIsset
191                | Assertion::NotInArray(..)
192                | Assertion::ArrayKeyDoesNotExist
193                | Assertion::DoesNotHaveArrayKey(_)
194                | Assertion::DoesNotHaveExactCount(_)
195                | Assertion::DoesNotHaveNonnullEntryForKey(_)
196                | Assertion::DoesNotHasAtLeastCount(_)
197                | Assertion::EmptyCountable
198                | Assertion::Empty
199                | Assertion::NotCountable(_)
200        )
201    }
202
203    #[must_use]
204    pub fn has_isset(&self) -> bool {
205        matches!(
206            self,
207            Assertion::IsIsset | Assertion::ArrayKeyExists | Assertion::HasStringArrayAccess | Assertion::IsEqualIsset
208        )
209    }
210
211    #[must_use]
212    pub fn has_equality(&self) -> bool {
213        matches!(
214            self,
215            Assertion::InArray(_)
216                | Assertion::HasIntOrStringArrayAccess
217                | Assertion::HasStringArrayAccess
218                | Assertion::IsEqualIsset
219                | Assertion::IsIdentical(_)
220                | Assertion::IsNotIdentical(_)
221                | Assertion::IsEqual(_)
222                | Assertion::IsNotEqual(_)
223                | Assertion::HasExactCount(_)
224        )
225    }
226
227    #[must_use]
228    pub fn has_literal_value(&self) -> bool {
229        self.get_type().is_some_and(|atomic| {
230            atomic.is_literal_int()
231                || atomic.is_literal_float()
232                || atomic.is_known_literal_string()
233                || atomic.is_literal_class_string()
234        })
235    }
236
237    #[must_use]
238    pub fn with_type(&self, atomic: TAtomic) -> Self {
239        match self {
240            Assertion::IsType(_) => Assertion::IsType(atomic),
241            Assertion::IsNotType(_) => Assertion::IsNotType(atomic),
242            Assertion::IsIdentical(_) => Assertion::IsIdentical(atomic),
243            Assertion::IsNotIdentical(_) => Assertion::IsNotIdentical(atomic),
244            Assertion::IsEqual(_) => Assertion::IsEqual(atomic),
245            Assertion::IsNotEqual(_) => Assertion::IsNotEqual(atomic),
246            _ => self.clone(),
247        }
248    }
249
250    #[must_use]
251    pub fn get_type(&self) -> Option<&TAtomic> {
252        match self {
253            Assertion::IsIdentical(atomic)
254            | Assertion::IsNotIdentical(atomic)
255            | Assertion::IsType(atomic)
256            | Assertion::IsNotType(atomic)
257            | Assertion::IsEqual(atomic)
258            | Assertion::IsNotEqual(atomic) => Some(atomic),
259            _ => None,
260        }
261    }
262
263    pub fn get_type_mut(&mut self) -> Option<&mut TAtomic> {
264        match self {
265            Assertion::IsIdentical(atomic)
266            | Assertion::IsNotIdentical(atomic)
267            | Assertion::IsType(atomic)
268            | Assertion::IsNotType(atomic)
269            | Assertion::IsEqual(atomic)
270            | Assertion::IsNotEqual(atomic) => Some(atomic),
271            _ => None,
272        }
273    }
274
275    #[must_use]
276    pub fn resolve_templates(&self, codebase: &CodebaseMetadata, template_result: &TemplateResult) -> Vec<Self> {
277        match self {
278            Assertion::IsType(atomic) => {
279                let union = TUnion::from_single(Cow::Owned(atomic.clone()));
280                let resolved_union = inferred_type_replacer::replace(&union, template_result, codebase);
281
282                let mut result = vec![];
283                for resolved_atomic in resolved_union.types.into_owned() {
284                    result.push(Assertion::IsType(resolved_atomic));
285                }
286
287                if result.is_empty() {
288                    result.push(Assertion::IsType(TAtomic::Never));
289                }
290
291                result
292            }
293            Assertion::IsNotType(atomic) => {
294                let union = TUnion::from_single(Cow::Owned(atomic.clone()));
295                let resolved_union = inferred_type_replacer::replace(&union, template_result, codebase);
296
297                let mut result = vec![];
298                for resolved_atomic in resolved_union.types.into_owned() {
299                    result.push(Assertion::IsNotType(resolved_atomic));
300                }
301
302                if result.is_empty() {
303                    result.push(Assertion::IsNotType(TAtomic::Never));
304                }
305
306                result
307            }
308            Assertion::InArray(union) => {
309                let resolved_union = inferred_type_replacer::replace(union, template_result, codebase);
310
311                vec![Assertion::InArray(resolved_union)]
312            }
313            Assertion::NotInArray(union) => {
314                let resolved_union = inferred_type_replacer::replace(union, template_result, codebase);
315
316                vec![Assertion::NotInArray(resolved_union)]
317            }
318            _ => {
319                vec![self.clone()]
320            }
321        }
322    }
323
324    #[must_use]
325    pub fn is_negation_of(&self, other: &Assertion) -> bool {
326        match self {
327            Assertion::Any => false,
328            Assertion::Falsy => matches!(other, Assertion::Truthy),
329            Assertion::Truthy => matches!(other, Assertion::Falsy),
330            Assertion::IsType(atomic) => match other {
331                Assertion::IsNotType(other_atomic) => other_atomic == atomic,
332                _ => false,
333            },
334            Assertion::IsNotType(atomic) => match other {
335                Assertion::IsType(other_atomic) => other_atomic == atomic,
336                _ => false,
337            },
338            Assertion::IsIdentical(atomic) => match other {
339                Assertion::IsNotIdentical(other_atomic) => other_atomic == atomic,
340                _ => false,
341            },
342            Assertion::IsNotIdentical(atomic) => match other {
343                Assertion::IsIdentical(other_atomic) => other_atomic == atomic,
344                _ => false,
345            },
346            Assertion::IsEqual(atomic) => match other {
347                Assertion::IsNotEqual(other_atomic) => other_atomic == atomic,
348                _ => false,
349            },
350            Assertion::IsNotEqual(atomic) => match other {
351                Assertion::IsEqual(other_atomic) => other_atomic == atomic,
352                _ => false,
353            },
354            Assertion::IsEqualIsset => false,
355            Assertion::IsIsset => matches!(other, Assertion::IsNotIsset),
356            Assertion::IsNotIsset => matches!(other, Assertion::IsIsset),
357            Assertion::HasStringArrayAccess => false,
358            Assertion::HasIntOrStringArrayAccess => false,
359            Assertion::ArrayKeyExists => matches!(other, Assertion::ArrayKeyDoesNotExist),
360            Assertion::ArrayKeyDoesNotExist => matches!(other, Assertion::ArrayKeyExists),
361            Assertion::HasArrayKey(str) => match other {
362                Assertion::DoesNotHaveArrayKey(other_str) => other_str == str,
363                _ => false,
364            },
365            Assertion::DoesNotHaveArrayKey(str) => match other {
366                Assertion::HasArrayKey(other_str) => other_str == str,
367                _ => false,
368            },
369            Assertion::HasNonnullEntryForKey(str) => match other {
370                Assertion::DoesNotHaveNonnullEntryForKey(other_str) => other_str == str,
371                _ => false,
372            },
373            Assertion::DoesNotHaveNonnullEntryForKey(str) => match other {
374                Assertion::HasNonnullEntryForKey(other_str) => other_str == str,
375                _ => false,
376            },
377            Assertion::InArray(union) => match other {
378                Assertion::NotInArray(other_union) => other_union == union,
379                _ => false,
380            },
381            Assertion::NotInArray(union) => match other {
382                Assertion::InArray(other_union) => other_union == union,
383                _ => false,
384            },
385            Assertion::Empty => matches!(other, Assertion::NonEmpty),
386            Assertion::NonEmpty => matches!(other, Assertion::Empty),
387            Assertion::NonEmptyCountable(negatable) => *negatable && matches!(other, Assertion::EmptyCountable),
388            Assertion::EmptyCountable => matches!(other, Assertion::NonEmptyCountable(true)),
389            Assertion::HasExactCount(number) => match other {
390                Assertion::DoesNotHaveExactCount(other_number) => other_number == number,
391                _ => false,
392            },
393            Assertion::DoesNotHaveExactCount(number) => match other {
394                Assertion::HasExactCount(other_number) => other_number == number,
395                _ => false,
396            },
397            Assertion::HasAtLeastCount(number) => match other {
398                Assertion::DoesNotHasAtLeastCount(other_number) => other_number == number,
399                _ => false,
400            },
401            Assertion::DoesNotHasAtLeastCount(number) => match other {
402                Assertion::HasAtLeastCount(other_number) => other_number == number,
403                _ => false,
404            },
405            Assertion::IsLessThan(number) => match other {
406                Assertion::IsGreaterThanOrEqual(other_number) => other_number == number,
407                _ => false,
408            },
409            Assertion::IsLessThanOrEqual(number) => match other {
410                Assertion::IsGreaterThan(other_number) => other_number == number,
411                _ => false,
412            },
413            Assertion::IsGreaterThan(number) => match other {
414                Assertion::IsLessThanOrEqual(other_number) => other_number == number,
415                _ => false,
416            },
417            Assertion::IsGreaterThanOrEqual(number) => match other {
418                Assertion::IsLessThan(other_number) => other_number == number,
419                _ => false,
420            },
421            Assertion::IsLessThanFromBound(_)
422            | Assertion::IsLessThanOrEqualFromBound(_)
423            | Assertion::IsGreaterThanFromBound(_)
424            | Assertion::IsGreaterThanOrEqualFromBound(_) => false,
425            Assertion::IsLessThanVariable(variable) => match other {
426                Assertion::IsGreaterThanOrEqualVariable(other_variable) => other_variable == variable,
427                _ => false,
428            },
429            Assertion::IsLessThanOrEqualVariable(variable) => match other {
430                Assertion::IsGreaterThanVariable(other_variable) => other_variable == variable,
431                _ => false,
432            },
433            Assertion::IsGreaterThanVariable(variable) => match other {
434                Assertion::IsLessThanOrEqualVariable(other_variable) => other_variable == variable,
435                _ => false,
436            },
437            Assertion::IsGreaterThanOrEqualVariable(variable) => match other {
438                Assertion::IsLessThanVariable(other_variable) => other_variable == variable,
439                _ => false,
440            },
441            Assertion::StringLengthLessThan(number) => match other {
442                Assertion::StringLengthGreaterThanOrEqual(other_number) => other_number == number,
443                _ => false,
444            },
445            Assertion::StringLengthGreaterThanOrEqual(number) => match other {
446                Assertion::StringLengthLessThan(other_number) => other_number == number,
447                _ => false,
448            },
449            Assertion::Countable => matches!(other, Assertion::NotCountable(negatable) if *negatable),
450            Assertion::NotCountable(_) => matches!(other, Assertion::Countable),
451        }
452    }
453
454    #[must_use]
455    pub fn get_negation(&self) -> Self {
456        match self {
457            Assertion::Any => Assertion::Any,
458            Assertion::Falsy => Assertion::Truthy,
459            Assertion::IsType(atomic) => Assertion::IsNotType(atomic.clone()),
460            Assertion::IsNotType(atomic) => Assertion::IsType(atomic.clone()),
461            Assertion::Truthy => Assertion::Falsy,
462            Assertion::IsIdentical(atomic) => Assertion::IsNotIdentical(atomic.clone()),
463            Assertion::IsNotIdentical(atomic) => Assertion::IsIdentical(atomic.clone()),
464            Assertion::IsEqual(atomic) => Assertion::IsNotEqual(atomic.clone()),
465            Assertion::IsNotEqual(atomic) => Assertion::IsEqual(atomic.clone()),
466            Assertion::IsIsset => Assertion::IsNotIsset,
467            Assertion::IsNotIsset => Assertion::IsIsset,
468            Assertion::Empty => Assertion::NonEmpty,
469            Assertion::NonEmpty => Assertion::Empty,
470            Assertion::NonEmptyCountable(negatable) => {
471                if *negatable {
472                    Assertion::EmptyCountable
473                } else {
474                    Assertion::Any
475                }
476            }
477            Assertion::EmptyCountable => Assertion::NonEmptyCountable(true),
478            Assertion::ArrayKeyExists => Assertion::ArrayKeyDoesNotExist,
479            Assertion::ArrayKeyDoesNotExist => Assertion::ArrayKeyExists,
480            Assertion::InArray(union) => Assertion::NotInArray(union.clone()),
481            Assertion::NotInArray(union) => Assertion::InArray(union.clone()),
482            Assertion::HasExactCount(size) => Assertion::DoesNotHaveExactCount(*size),
483            Assertion::DoesNotHaveExactCount(size) => Assertion::HasExactCount(*size),
484            Assertion::HasAtLeastCount(size) => Assertion::DoesNotHasAtLeastCount(*size),
485            Assertion::DoesNotHasAtLeastCount(size) => Assertion::HasAtLeastCount(*size),
486            Assertion::HasArrayKey(str) => Assertion::DoesNotHaveArrayKey(*str),
487            Assertion::DoesNotHaveArrayKey(str) => Assertion::HasArrayKey(*str),
488            Assertion::HasNonnullEntryForKey(str) => Assertion::DoesNotHaveNonnullEntryForKey(*str),
489            Assertion::DoesNotHaveNonnullEntryForKey(str) => Assertion::HasNonnullEntryForKey(*str),
490            Assertion::HasStringArrayAccess => Assertion::Any,
491            Assertion::HasIntOrStringArrayAccess => Assertion::Any,
492            Assertion::IsEqualIsset => Assertion::Any,
493            Assertion::IsLessThan(number) => Assertion::IsGreaterThanOrEqual(*number),
494            Assertion::IsLessThanOrEqual(number) => Assertion::IsGreaterThan(*number),
495            Assertion::IsGreaterThan(number) => Assertion::IsLessThanOrEqual(*number),
496            Assertion::IsGreaterThanOrEqual(number) => Assertion::IsLessThan(*number),
497            Assertion::IsLessThanFromBound(_)
498            | Assertion::IsLessThanOrEqualFromBound(_)
499            | Assertion::IsGreaterThanFromBound(_)
500            | Assertion::IsGreaterThanOrEqualFromBound(_) => Assertion::Any,
501            Assertion::IsLessThanVariable(variable) => Assertion::IsGreaterThanOrEqualVariable(*variable),
502            Assertion::IsLessThanOrEqualVariable(variable) => Assertion::IsGreaterThanVariable(*variable),
503            Assertion::IsGreaterThanVariable(variable) => Assertion::IsLessThanOrEqualVariable(*variable),
504            Assertion::IsGreaterThanOrEqualVariable(variable) => Assertion::IsLessThanVariable(*variable),
505            Assertion::StringLengthLessThan(number) => Assertion::StringLengthGreaterThanOrEqual(*number),
506            Assertion::StringLengthGreaterThanOrEqual(number) => Assertion::StringLengthLessThan(*number),
507            Assertion::Countable => Assertion::NotCountable(true),
508            Assertion::NotCountable(_) => Assertion::Countable,
509        }
510    }
511
512    /// Whether this assertion represents the condition itself and can be used
513    /// while constructing the opposite branch.
514    ///
515    /// Facts inferred from a non-literal range bound are only consequences of
516    /// a condition. They are useful in the true branch but are not logically
517    /// equivalent to that condition, so negating them would be unsound.
518    #[inline]
519    #[must_use]
520    pub const fn is_negatable(&self) -> bool {
521        !matches!(
522            self,
523            Self::IsLessThanFromBound(_)
524                | Self::IsLessThanOrEqualFromBound(_)
525                | Self::IsGreaterThanFromBound(_)
526                | Self::IsGreaterThanOrEqualFromBound(_)
527        )
528    }
529
530    /// Returns the expression referenced by a relational assertion.
531    #[inline]
532    #[must_use]
533    pub const fn referenced_variable(&self) -> Option<Word> {
534        match self {
535            Self::IsLessThanVariable(variable)
536            | Self::IsLessThanOrEqualVariable(variable)
537            | Self::IsGreaterThanVariable(variable)
538            | Self::IsGreaterThanOrEqualVariable(variable) => Some(*variable),
539            _ => None,
540        }
541    }
542}