On this page

0084. Generated codecs may import their generator package runtime

Context

ADR-0078 limits generated imports to the deriving package and std.reflect. The JSON generator lives in a path dependency and must call codec.rt helpers. The old validator rejects that import with E0967, so importing Json alone cannot produce a usable encoder without requiring callers to bind private helper names.

Decision

Generated companions may also import modules from the resolved generator's own package, using the deriving package's existing dependency binding. They may also import packages of loaded types opted into that same resolved generator. This allowance covers the whole package: any visible module, not just its encoders, may be imported. It lets a nested derived type call its own encoder across package boundaries. Other external packages remain E0967. Normal resolution, visibility and capability ceilings still apply; this adds neither dependencies nor generator capabilities. The generator package's runtime helpers become ordinary runtime edges, while Json stays staged. This supersedes only ADR-0078 decision 9's generated-import restriction.

Alternatives considered

Consequences

One narrow gen.rs validation change enables the package API. Integration tests prove codec runtime and nested cross-package encoders execute on both backends, and a local generator still cannot import an unrelated dependency. Existing accepted output stays accepted; GEN_ABI and all existing companions remain unchanged in this additive step.