Class OrderingAvailability

java.lang.Object
org.ek9lang.compiler.support.sameness.OrderingAvailability

public final class OrderingAvailability extends Object
🛑 THE ONE question "can this <=> (and the ordering built on it) be used?" (D55, D58, D62, D63, D71) - orderingSurvives(MethodSymbol, ISymbol), bareOrderingRetracted(IAggregateSymbol, ISymbol), withdrawnOrdering(IAggregateSymbol, ISymbol) and isUnavailableOrdering(MethodSymbol, ISymbol) with the readings built on them. EVERY use of <=> asks this class - hold one; never a second "can this be ordered" predicate (E07620, NaturalOrderQueue, D63). The retraction step that acts on the answer is RetractWithdrawnBareOrdering, its wording WhyNotOrderable.

All its answers read the methods as DECLARED, a retracted one included, so they are the same before, during and after phase 5's retraction pass, whatever order it visits the types in.

  • Constructor Details

    • OrderingAvailability

      public OrderingAvailability()
  • Method Details

    • orderingSurvives

      public boolean orderingSurvives(MethodSymbol comparison, ISymbol ek9Any)
      THE "does this <=> still order values once PRE_IR_CHECKS has run?" (D55, Steve 2026-10-20). A <=> written by hand always does; an explicit default operator <=> does when every property can be ordered (it can fail to only in a generic, where a property is a T that became a type with no <=> - D71). One the BARE default operator added survives only when every property of its owner can be ordered (HasRealComparator.allPropertiesOrderable(IAggregateSymbol)) AND the nearest <=> above it - the one its generated body calls for the inherited fields - survives too. Otherwise phase 5 retracts it, with the rest of the bare ordering family, and the type is equatable only: a sub-type follows its super. Below a Base whose bare <=> is retracted (a field's type has == only), a Leaf's bare <=> once compared only Leaf's own fields - Leaf(1, "x") == Leaf(2, "x") was TRUE while their #? differed.

      Read by phase 5's retraction (DefaultComparatorRecheckOrError), by E07186, E07190 and E07238 in phase 3, and by HasOwnComparator, so none of them can disagree about whether a type is ordered. The walk above reads the methods as DECLARED, a retracted one included, so the answer is the same before, during and after the retraction pass, whatever order it visits the types in.

      Parameters:
      comparison - a <=> comparing its owner with itself
      ek9Any - the Any type, which never contributes
      Returns:
      true when the comparison orders values after PRE_IR_CHECKS
    • isOrderable

      public boolean isOrderable(IAggregateSymbol type, ISymbol ek9Any)
      THE "is this type orderable?" behind HasRealComparator: the nearest <=> it declares or inherits (super chain before Any, then its traits) that survives (orderingSurvives(MethodSymbol, ISymbol)). A bare one that does not survive is passed over, as if the default operator had never added it.
      Parameters:
      type - the type asked about
      ek9Any - the Any type, whose degenerate <=> never counts
      Returns:
      true when values of the type can be ordered
    • allPropertiesOrderable

      public boolean allPropertiesOrderable(IAggregateSymbol aggregate, ISymbol ek9Any)
      THE "can every property of this type be ordered?" (isOrderable(IAggregateSymbol, ISymbol) for each property's type) - what a bare default operator's <=> needs of its own fields.
      Parameters:
      aggregate - the type whose properties are asked about
      ek9Any - the Any type
      Returns:
      true when every property's type is orderable
    • bareOrderingRetracted

      public boolean bareOrderingRetracted(IAggregateSymbol owner, ISymbol ek9Any)
      THE retraction decision for a type's BARE ordering family (<=> < <= > >= added by the bare default operator): its own bare <=> decides for the whole family through orderingSurvives(MethodSymbol, ISymbol); without one (the ordering family alone, beside a hand-written <=>) the type's own properties decide. Phase 5's retraction (RetractWithdrawnBareOrdering) acts on it, and isRetractedOrdering(MethodSymbol, ISymbol) answers the same question for one operator before or after that pass (D58), so a use and the retraction cannot disagree.
      Parameters:
      owner - the type whose bare ordering operators are asked about
      ek9Any - the Any type
      Returns:
      true when the type's bare ordering operators are (or will be) retracted
    • isRetractedOrdering

      public boolean isRetractedOrdering(MethodSymbol operator, ISymbol ek9Any)
      Is this operator a BARE ordering operator that phase 5 retracts (bareOrderingRetracted(IAggregateSymbol, ISymbol) of its owner)? Order-independent, so usable from POST_RESOLUTION_CHECKS on: a generic's body that uses <=> or < on T, parameterised with a type whose ordering is retracted, is E07620 at the parameterisation (D58, Steve 2026-10-21).
      Parameters:
      operator - the operator a use resolved to
      ek9Any - the Any type
      Returns:
      true when the operator will not be generated
    • constrainedOverRetractedOrdering

      boolean constrainedOverRetractedOrdering(IAggregateSymbol owner, ISymbol ek9Any)
      Is this a constrained type whose base's bare ordering is withdrawn? Its copied ordering operators are then withdrawn with it: a constrained type offers exactly the operators its base has (M1).
    • isDegenerateDefaultedOrdering

      public boolean isDegenerateDefaultedOrdering(MethodSymbol operator, ISymbol ek9Any)
      A defaulted ordering operator on a type whose <=> degenerates because a field cannot be ordered - the case a generic instantiation reaches without any retraction marker: Box of List (its template's default operator <=> is over a T that became a List). Its == falls back to field by field and it has no ordering (B18 rule 8); without this, first < second compiled and was always UNSET.
      Parameters:
      operator - an operator a use resolved to
      ek9Any - the Any type
      Returns:
      true when the operator is a defaulted ordering over a type that has no comparator of its own
    • isUnavailableOrdering

      public boolean isUnavailableOrdering(MethodSymbol operator, ISymbol ek9Any)
      THE verdict on a call of an ordering operator written as an operator (first < second, a case < x): the operator it resolved to is one phase 5 retracts (isRetractedOrdering(MethodSymbol, ISymbol)) or one that degenerates (isDegenerateDefaultedOrdering(MethodSymbol, ISymbol)). Phase 5's RetractedComparatorUseOrError reads the retraction marker where this reads the methods as declared; phase 4 asks it for a generic's operator use where the type parameters are replaced (D71, D63 residual).
      Parameters:
      operator - the operator a use resolved to
      ek9Any - the Any type
      Returns:
      true when the operator is not available
    • withdrawnOrdering

      public Optional<MethodSymbol> withdrawnOrdering(IAggregateSymbol type, ISymbol ek9Any)
      THE "does a use of this type's <=> rely on an ordering that is withdrawn?" (D58, Steve 2026-10-21): the nearest <=> declared on the type or above it - the one phase 3 resolved the use to - is one the bare default operator added, and it does not survive (orderingSurvives(MethodSymbol, ISymbol)). Every use that needs it without naming it - <? >?, a sort stage with no comparator, x in a ... b, a for range - asks here, after phase 5 has retracted it. It is NOT isOrderable(IAggregateSymbol, ISymbol): a sub-type whose own bare <=> is retracted below a super with a hand-written one is "orderable" through the super, yet the use resolved to the sub-type's own <=>(Sub), which is not generated (NoSuchMethodError) - the same answer the binary < gets from the retraction mark. Empty for any other type, so a type that never offered a bare ordering is never touched.
      Parameters:
      type - the type whose <=> a use needs
      ek9Any - the Any type
      Returns:
      the withdrawn bare <=> the use relied on, if any
    • unorderedDictEntryKey

      public Optional<ISymbol> unorderedDictEntryKey(ISymbol type, ISymbol ek9Any)
      The key type that stops a DictEntry of (K, V) being ordered (Steve, 2026-10-21): a DictEntry orders by its KEY's <=>, then by its VALUE's when the keys are the same (the entries of one Dict have unique keys), so a key type that cannot be ordered (isOrderable(IAggregateSymbol, ISymbol); a function never can) leaves the entry unordered, and a comparator-less sort, <?, range or natural-order queue over it is E07620 - not the run-time "Sort cannot order" Exception it was. A conceptual T key (inside a generic's body) never counts here: a generic body's ordering of a type BUILT ON T (DictEntry of (K, Integer)) is recorded in phase 3 (conceptual/NoteOrderingUse) and judged where K is substituted (phase4/ParameterisedTypeOrError), by THIS verdict on the replaced type (D71, D63 residual).
      Parameters:
      type - the type asked about; anything but a parameterisation of DictEntry answers empty
      ek9Any - the Any type
      Returns:
      the key type that cannot be ordered, if any
    • orderingWithdrawn

      public boolean orderingWithdrawn(IAggregateSymbol type, ISymbol ek9Any)
      Does a use that needs the type's <=> without naming it (sort, <?, a range) rely on an ordering that is not there: a withdrawn bare <=> (withdrawnOrdering(IAggregateSymbol, ISymbol)) or a DictEntry whose key cannot be ordered (unorderedDictEntryKey(ISymbol, ISymbol))? THE test of phase 5's RetractedComparatorUseOrError; WhyNotOrderable words it.
      Parameters:
      type - the type whose <=> a use needs
      ek9Any - the Any type
      Returns:
      true when the use is E07620
    • unorderedPropertyBehind

      public Optional<UnorderedProperty> unorderedPropertyBehind(MethodSymbol comparison, ISymbol ek9Any)
      THE reason a bare <=> does not survive: the first property, from the owner of comparison upward through the <=>s each bare one builds on (read as DECLARED, so it answers the same after the retraction), whose type cannot be ordered (isOrderable(IAggregateSymbol, ISymbol)).
      Parameters:
      comparison - a bare <=>
      ek9Any - the Any type
      Returns:
      the field and its owner, if one is found