Skip to main content

is_user_compare

Function is_user_compare 

Source
pub fn is_user_compare(node: &AIRNode) -> bool
Expand description

True when a BinaryOp { op: Lt | Le | Gt | Ge, .. } is an ordering comparison on a user Comparable type and must be lowered through the type’s compare(self, other) method rather than the target’s native < / <= / > / >=.

The signal is the checker’s bock_types::checker::USER_COMPARE_META_KEY stamp, set on an ordering operator whose operands resolved to a Named (record / class) type implementing Comparable. A purely syntactic codegen check cannot see that bare identifiers (a < b) are a user Comparable type, so — like is_int_arith — the stamp is the sole signal: there is no syntactic fallback.

Every backend consults this from its NodeKind::BinaryOp arm: native < on two user values is broken on all five targets (Python TypeError, Rust/Go non-comparable structs, JS NaN-coercion). Mapping the operator onto the compare result (<== Less, >== Greater, <=!= Greater, >=!= Less) reuses the per-target Ordering representation the stdlib already emits. See the metadata key’s docs for the rationale.