ADR 0041: Dtype equality is not type equality¶
Status: Final
Type: Architecture
Created: 2026-08-04
Consolidated: 2026-08-07: its original field rung (dict/set-valued fields) moved into 0024; what stands here is the boundary rule the rung forced
Related-ADRs: 0035 (where a parameter lives), 0030, 0027. Provenance: see arbitrations A113, A119, A123, A124.
Context¶
POST has no generics, so a parameterised type's parameter does not live in its dtype: list[int] and list[Item] are one dtype, and the members live in side-records keyed to the slot holding the value. That representation is cheap and correct until two values of one dtype and different members meet at a boundary that compares dtypes alone.
Decision¶
Every boundary that compares dtypes must additionally compare declared members. Four positions trusted the dtype alone, with these costs:
| position | consequence of trusting the dtype |
|---|---|
a field store (b.items = xs) |
the next element read hands a scalar payload to an instance accessor |
| a call argument | the callee's loop does the same, in another frame |
a return |
the caller's accessors, same |
| an annotated binding | the annotation misstates the members; no corruption, since members travel with the value |
The fix is one helper at the four boundaries, each handing it the declared members its own record holds (the class record, the parameter, the function's return fields, the resolved annotation). A fifth boundary position calls the same helper or is the next gap, as the helper's own documentation says.
Why no instrument could see three of the four. The differential needs a wrong program that someone wrote, and wrong programs are never written on purpose. The reclamation counters count releases that all happen. The verifier checks static types, which are consistent; the confusion exists only in memory at run time. A reachable invariant with no instrument in front of it must be closed by a frontend check at the boundary, because nothing downstream can catch it.
The general reading: the want of generics taxes three faces, each owning a guard.
- Storage: the side-records (per-slot, per-class, per-container), bounded and enumerable, a product of two small closed sets.
- Dispatch: the dtype-keyed lowering tables, held by the declared-domain guard, which refuses an undeclared narrowing the day a table is added.
- Comparison: this ADR. Dtype equality is not type equality, so any place that compares dtypes is a suspect until it consults the members.
Consequences¶
- The boundary check turns a silent memory-corruption class into ordinary diagnostics at the four boundaries and gives the next boundary a named obligation.
- The three-face inventory is the standing checklist for any feature that touches parameterised types: say which face it extends, and point at that face's guard.
- The original field rung this rule emerged from (dict/set-valued fields at the descriptor's predicted one-character price) lives with the memory model in 0024.
Alternatives considered¶
- Generics (parameterised dtypes): the structural fix, but a language-scale decision this compiler has not taken. The three guards make its absence safe in the meantime.
- Encoding members into the dtype (one dtype per instantiation): rejected. It is generics by the back door, with identity questions (two mintings of
list[int]) the type system is not prepared to answer.