Class DispatcherWinner
Third member of the dispatcher family, beside DispatcherHandlers (which handlers
compete) and DispatcherReachableTypes (what types can arrive). Together the three answer
the whole dispatch question, and they must be used together: a winner computed over a handler set
or a type set that some other caller derived differently is a different dispatch model wearing
the same name.
Selection rule. Lowest un-coerced assignment cost wins; a negative cost means "not
assignable" and does not compete. Phase 5 (DispatcherAmbiguityOrError) has already
rejected ties at equal cost, so for a program that compiles the winner is unique — the first-wins
tie-break below is therefore unreachable in practice, and is kept only so this is total.
Why the cost comes back with the handler. Phase 7 needs only the winner, but a cost of exactly zero is what distinguishes a handler declared FOR this very type from one it merely inherits into — the DIRECT/INHERITED split the Oracle and IDE dispatcher views show. Recomputing that cost at the call site was how the previous copy drifted, so it is returned rather than left to be re-derived.
Deliberately ISymbol, not IAggregateSymbol. A dispatcher may route over
a FUNCTION hierarchy, and FunctionSymbol is an IFunctionSymbol, NOT an
IAggregateSymbol. Narrowing the parameter is precisely the defect that made a function
handler silently unreachable in phase 5 and phase 7, and it had been re-made a third time in the
Oracle extractor. Keep this signature wide.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA winning handler and the assignment cost it won at. -
Method Summary
Modifier and TypeMethodDescriptionstatic Optional<DispatcherWinner.Selection> forParam(ISymbol concreteType, int paramIndex, List<MethodSymbol> handlers) The winning handler for a concrete type at one parameter position.static Optional<DispatcherWinner.Selection> forParamPair(ISymbol type0, ISymbol type1, List<MethodSymbol> handlers) The winning handler for a pair of concrete types across the first two parameters.
-
Method Details
-
forParam
public static Optional<DispatcherWinner.Selection> forParam(ISymbol concreteType, int paramIndex, List<MethodSymbol> handlers) The winning handler for a concrete type at one parameter position.- Parameters:
concreteType- the type a value could actually have at this positionparamIndex- which parameter is being dispatched onhandlers- the handler set, fromDispatcherHandlers.collectFor(IAggregateSymbol, MethodSymbol)- Returns:
- the winner and the cost it won at, or empty when no handler accepts the type
-
forParamPair
public static Optional<DispatcherWinner.Selection> forParamPair(ISymbol type0, ISymbol type1, List<MethodSymbol> handlers) The winning handler for a pair of concrete types across the first two parameters.- Parameters:
type0- the type at parameter 0type1- the type at parameter 1handlers- the handler set, fromDispatcherHandlers.collectFor(IAggregateSymbol, MethodSymbol)- Returns:
- the winner and the summed cost it won at, or empty when no handler accepts the pair
-