0086. Binary map keys match supported scalar codecs
- Status: Accepted
- Date: 2026-11-01
- Plan: M9.6 Step 6.6
- Review: Data, schemas and wire formats
Context
Binary encodes map keys as typed values, unlike JSON's string keys. Validating keys as arbitrary codec values permits vectors and records through generation, then fails type-checking the generated map helpers. Paths are valid kernel map keys but have no Binary codec.
Decision
Binary map keys are integers, bool, str, bytes and newtypes recursively wrapping these types. Named keys still require their own Binary derives. Reject other keys with a field-path E0966 before emitting a companion. This narrows validation to the intersection of kernel map keys and implemented Binary codecs; it adds no wire format or compiler/runtime support.
Alternatives considered
- JSON's str-only keys — unnecessarily rejects integer and other scalar keys already supported by Binary's typed wire representation.
- Every codec value as a key — kernel maps do not support compound keys; generated-code errors obscure the originating field and multiply diagnostics.
Consequences
Unsupported schemas fail at the derive with one stable generator diagnostic. Tests pin rejected key categories and roundtrip all accepted scalar categories both directly and through nested newtypes on C and the interpreter.