kernel!K returns (one type for all kinds).dispatch
auto dispatch(alias kernel, Args...)(DataType dtype, Args args)Calls kernel!K(args) for the runtime kind of dtype, through a final switch with exactly one textual call site inside a static foreach over Kinds.
The five rules every kernel passed to dispatch obeys (verified by probes/facts 1 and 2; ../ddn/doc/DDN-TYPES.md records the general convention):
- Arguments are passed by value.
auto refon the dispatchsignature would make the template impossible to name (
cannot explicitly instantiate template function with 'auto ref' parameter). - One erased return type per kernel: every instantiation for all
fourteen kinds must return the same type (
ArrayData,size_t, ...). A kernel constrained to a subset of kinds, or returning different types per kind, does not compile — usedispatchNumeric, anunsupported!Kbranch, or (for aggregations, whose result dtype depends on the kind) a one-slotArrayDataof the promoted dtype read out afterwards. - Kernels are module-level templates. A local (nested) template
kernel is rejected, so no closure is ever heap-allocated through dispatch; user callbacks travel as runtime
scope delegatearguments. - Binary operations cast both operands to the supertype first
(ddn.columnar.types.supertypeOf) and dispatch once: fourteen instantiations per operation, not 196.
- Attribute contracts are pinned by attributed unittests calling
the kernels through
dispatch, never by taking&dispatch.
Parameters
kernel | a module-level template with a Kind value parameter |
dtype | the dtype whose kind selects the instantiation |
args | forwarded by value to the kernel |