ddn.cti
ddn.cti — compile-time interfaces (CTI).
A CTI is one of DDN's two contract styles (the other is ddn.api's run-time interfaces with a registry; see doc/API-CONVENTIONS.md). One module per role holds the value types, a reference struct whose member functions are declared without bodies (a legal D "header": it compiles, is never instantiated, and is only compared against), DDoc stating the semantics the compiler cannot check, and a one-line isXxx constraint derived from the reference by implements. An implementor is a struct mirroring the reference surface, proven by one static assert(isXxx!MyType);. No classes, no virtual calls, no registry, no shared static this(); implementors are chosen when the binary is built (version blocks and dub configurations), never when it runs.
Reference templates are parameterized by the implementor's Self (and associated types), so the signatures an implementor must mirror are concrete: FontFaceRef!T.open fills an out T and returns Status!TextError, never a reference instance. (Factories use out parameters plus Status, not by-value Result!(T, E) returns: construction from a move-only T in its own member factory fails on the validated compiler; the compiler-internal cause is not confirmed — see the factory convention amendment in doc/DDN-CTI.md section 9.1.) Role predicates pass the concrete types to implements and compare the associated-type aliases themselves; a missing alias yields false, not a template-error avalanche.
What implements compares, per public member of the reference:
- Functions (exactly one non-template function per name — an
overloaded or template reference member is diagnosed and never guessed): parameter types and their
scope/ref/outstorage classes, return type, linkage, static vs member,refreturn,const/immutable/inout/sharedqualifiers, and the required attributes@safe,pure,nothrow,@nogc— the implementor's set must be at least as strict, and@trustedsatisfies a@saferequirement. - Fields and manifest constants: same type; a manifest constant
in the reference requires one in the implementor; static-ness must match.
- Copyability: a move-only reference (
@disable this(this))requires a move-only implementor. Constructors, destructors and compiler-generated members are never member-compared; copyability is checked by this separate probe, not by matching
opAssign.
Extra members on the implementor are allowed. Aliases to types are skipped by the generic loop and compared by the role predicates.
Diagnostics: implements evaluates to false if a member mismatches; with LDC's --d-version=DdnCtiExplain (DMD's -version=DdnCtiExplain) it prints mismatching members and their reasons with pragma(msg). Diagnostics are compile-time only.
Design record: doc/DDN-CTI.md (section 9 is the normative contract). The first roles live in ddn.cti.text; every role module's DDoc carries an Inspiration section naming the libraries its reference was designed against. CTIs are experimental until real-provider conformance evidence exists.
Templates 5
True when T provides every checked public member of Ref with a compatible signature and attributes at least as strict.
Ref is a bodiless reference struct (possibly a template instantiated with T and associated types, for explicit-Self signatures); T is the implementor. The comparison rules are listed in the module documentation. On the first mismatch the template evaluates to false; with --d-version=DdnCtiExplain (LDC) the mismatch is also printed.
Parameters
T | the implementor type. |
Ref | the reference struct (instantiated reference template). |
True for a move-only struct whose destruction is safe, non-throwing and allocation-free. Role predicates use this separately from member matching; references themselves are never instantiated to test destruction.
This checks callable cleanup attributes, not semantic ownership, native resource validity, or address stability. Providers must test those lifetimes.
Parameters
T | concrete implementor type, complete before applying this check. |
Parameter storage classes compared element-wise (is identity of two AliasSeq instantiations does not compare contents).
One reference function against one implementor function.
One reference member against the implementor; true when satisfied.