Expand description
Which types are Ord, and the checks that need it. Constrained generics
slice 1 (#2660; the model is the track’s Q2/Q5 in
design/archive/retired-tracks.md).
Ord is a declared, structural property. A type is Ord when it is one of:
Int,Float,String,Duration,InstantorBytes, or a refined type over one of them (a refinement is visible everywhere, so it needs no declaration);Option[T]orList[T]withTOrd;- a record, sum, enum or opaque type that declares
derives Ord, and, when it is generic, whose type arguments areOrd; - a type parameter declared
T: Ord(checked separately: seesuper::equality::require_ord_vars).
Bool, Result, Map, Set, functions and held resources are not Ord.
derives Ord makes declaration order meaningful: a record orders by its fields
in declaration order, a sum by variant declaration order and then by payload.
That is why Ord is opt-in (Q2) while Eq is automatic.
Query’s sortBy/min/max take any Ord key too (#2787); a Query is
evaluated in memory, so there is no storage path that needs a base-type key.
Functions§
- witness_
params - The type parameters of
fthat take a comparator witness, in witness order (DECISION D): the receiver type’s parameters first, in the type’s declaration order, then the function’s own, in declaration order. A parameter is a witness parameter when declaredOrdinline (T: Ord), in awhereentry, or, for a receiver parameter, on the type (type Sorted[T: Ord]). The emitter adds one trailing parameter per name, and every call site passes one argument per name, so this order is the contract between them; it is not part of the published ABI.