DS Opaque Types#
Adapter-published opaque nominal types. Prefix LOPQ.
Opaque types are the inverse of the unit system ([LUNI]): the same compile-time nominal-tag mechanism, erased at runtime with zero overhead, but with the operation stance reversed — a unit adds dimensional algebra to a number, an opaque type seals a value to an adapter-defined surface.
The representation is over Bytes only; the mechanism is representation-general (over String
/ over Int are gated on a named need, §[LOPQ.10]). A fixed-length bound
(length N), value ordering, and a resource/handle type are deferred or
out-of-scope (§[LOPQ.10]).
The feature is compile-time only and erases to its representation at lowering ([LOPQ.6.3]), so it adds no runtime registry entry. Its compiler validators are [LOPQ.11].
1. What an opaque type is [LOPQ.1]#
[LOPQ.1.1] An opaque type is a nominal type carried by an underlying builtin
representation, whose operation surface is sealed to equality plus a set
the publishing adapter declares. To the rule author the value is its opaque type,
never its representation: Bytes is the correct engine representation for a
public key, and the wrong author-facing type.
[LOPQ.1.2] An opaque value is a value, not a record and not a fact: it is held
in a slot, bound in a let, passed as a call argument, bound in a pattern, and
carried on a fact, exactly as a scalar is ([LOPQ.5]).
see also: LOPQ.5
[LOPQ.1.3] Purpose (the capability boundary). With an opaque type the rule
layer holds an unforgeable, inert token: it may match it and hand it to an
adapter, and it must not read, convert, slice, construct, or cross-confuse it
([LOPQ.3], [LOPQ.4]). All domain meaning — for a Key, all cryptography — lives
behind the adapter boundary. The seal is a compile-time guarantee: a control-plane
bug or a malicious rule cannot forge or leak the underlying value.
2. Declaration [LOPQ.2]#
[LOPQ.2.1] An opaque type is declared opaque type <Name> over <repr>, where
<repr> is a builtin representation. In v1 <repr> must be Bytes
(§[LOPQ.10.1]).
ratified — see also: LOPQ.10.1
[LOPQ.2.2] An opaque type may be declared in a program or in a library. An
adapter's contract library ships them the way unit libraries ship units, and they
are importable: from crypto import (Key, Signature, Digest).
ratified
[LOPQ.2.3] An opaque type is nominal and distinct. Each opaque type, and its
representation, are pairwise distinct types with no implicit conversion. An
assignment, comparison, or argument binding across two distinct opaque types, or
between an opaque type and its representation, is a compile error
(DS_VALIDATE_OPAQUE_TYPE_MISMATCH). Two declarations are two opaque types,
whatever their names: two libraries' Keys are distinct, and a file that imports
a declaration holds that declaration.
ratified — checks: alloy×3
3. The operation surface [LOPQ.3]#
The total set of operations on an opaque value is [LOPQ.3.1]–[LOPQ.3.2]; everything else is sealed ([LOPQ.3.3]).
see also: LOPQ.3.1, LOPQ.3.2, LOPQ.3.3
[LOPQ.3.1] Equality (== / !=) is always available. It is bytewise on
the representation — reflexive, total, exact, and deterministic — and it is the
routing primitive: an equality join is how a rule matches an opaque value against
an allowlist. An opaque value may be equality-compared only to a value of the
same opaque type ([LOPQ.2.3]).
see also: LOPQ.2.3
[LOPQ.3.2] Declared adapter operations. Any service or builtin whose
signature names the opaque type may take or return it; the type system enforces
argument and return matching.
A service takes its arguments as kwarg declarations and names a response
schema rather than a scalar return ([LGRA] response_decl), so an opaque
return type appears as a slot on that schema.
ratified
[LOPQ.3.3] Everything else is sealed. Every representation operation —
len, indexing, every member of the representation type ([LGRA.9.6.2]), a :: cast of the
representation ([LGRA.9.6]), interpolation of the raw value into a string, and
any other builtin method of the representation — applied to an opaque receiver
is a compile error (DS_VALIDATE_OPAQUE_NO_OP). Value ordering (< <= >
>=) is likewise sealed in v1 (ordering is deferred, [LOPQ.10.4]). The
validator consults the type's declared operation surface
([LOPQ.3.1]–[LOPQ.3.2]) for an opaque receiver, not the representation's
builtin method table ([LOPQ.9.4]).
ratified — see also: LGRA.9.6, LGRA.9.6.2, LOPQ.10.4, LOPQ.3.1, LOPQ.3.2, LOPQ.9.4
4. Construction and elimination — the seal [LOPQ.4]#
checks: alloy×2
[LOPQ.4.1] A rule must not construct an opaque value from its representation.
There is no rule-level Key(some_bytes) form; such an expression is a compile
error (DS_VALIDATE_OPAQUE_NO_OP). This is the forge-prevention seal.
ratified — checks: alloy
[LOPQ.4.2] An opaque value originates only from:
(a) adapter ingest — a fact slot or call argument typed as the opaque type, populated by the adapter from the wire representation across the
IDSPboundary ([LOPQ.6.2]);(b) a declared operation that returns the type ([LOPQ.3.3], e.g.
crypto.hash(...) -> Digest); or(c) a constant declared in an adapter's contract library — a trust anchor (a well-known key, a root digest). This is a trusted-layer origin, not a rule-layer construction: a rule may use the declared constant but must not mint a different value, so it is not a forge path ([LOPQ.1.3]).
checks: alloy×3 — see also: LOPQ.1.3, LOPQ.3.3, LOPQ.6.2
[LOPQ.4.3] A rule must not eliminate an opaque value to its representation.
There is no .raw / to_bytes accessor, and the :: conversion cast is barred:
the compiler must reject <opaque>::T for any non-opaque T ([LCST.4.5.2]). The
underlying value cannot be extracted in a rule. The adapter, on its side of the
IDSP boundary, holds the representation.
ratified — checks: alloy — see also: LCST.4.5.2
[LOPQ.4.4] A test or fixture obtains an opaque value through the ingest
boundary ([LOPQ.4.2(a)]) — fact injection or a recorded event trace supplying
the representation bytes — the same path production uses. There is no
test-only construction form and no +unsafe constructor; the seal is
unconditional.
see also: LOPQ.4.2
5. Type rules and semantics [LOPQ.5]#
[LOPQ.5.1] An opaque value flows like a scalar: slot value, let binding,
call argument, pattern binding, fact slot. It is not a record (it has no fields)
and not a fact.
ratified
[LOPQ.5.2] Joins. An opaque-typed slot may be equality-joined ([LOPQ.3.1]); it must not be compared by any sealed operation ([LOPQ.3.3]). Range comparison is deferred with ordering ([LOPQ.10.4]).
see also: LOPQ.10.4, LOPQ.3.1, LOPQ.3.3
[LOPQ.5.3] Equality is bytewise on the representation, reflexive and total ([LOPQ.3.1]); two opaque values of the same type are equal exactly when their representations are bytewise equal.
see also: LOPQ.3.1
6. Runtime, wire, and lowering [LOPQ.6]#
[LOPQ.6.1] Zero runtime overhead. The opaque type is a compile-time tag, erased after validation. At runtime an opaque value is its representation; there is no per-value type tag and no memory overhead (as for the unit system, [LUNI]).
[LOPQ.6.2] Wire (IDSP). An opaque value crosses the adapter boundary as its
representation's encoding — over Bytes is the protobuf bytes encoding, exactly
as Bytes. The opaque type is recovered from the schema or service signature and
is never carried per value.
[LOPQ.6.3] DSC / IR. An opaque type lowers to its representation; the tag does not survive into the bundle. An opaque type therefore incurs no wire cost beyond what its representation already incurs.
7. Determinism [LOPQ.7]#
[LOPQ.7.1] Opaque types add no nondeterminism. Equality is bytewise-exact — no floating point, no transcendental — so it is deterministic and cross-platform bit-identical, and the feature fits the exact-only language surface with no capability required.
[LOPQ.7.2] On replay an opaque value is re-supplied through the ingest boundary ([LOPQ.4.2(a)]) from its recorded representation bytes; replay is bit-identical.
see also: LOPQ.4.2
8. Gating [LOPQ.8]#
[LOPQ.8.1] Opaque types are part of the base language: the feature has no runtime footprint ([LOPQ.6.1]) and is opt-in by use (a program that declares or imports no opaque type has none).
see also: LOPQ.6.1
9. Interaction with existing features [LOPQ.9]#
[LOPQ.9.1] Units ([LUNI]) are the parallel mechanism ([LOPQ.1]); the two share the nominal-tag lowering but are kept distinct declarations because their operation models are opposite (enrichment vs sealing).
see also: LOPQ.1
[LOPQ.9.2] Schemas. An opaque type is a scalar; a schema may have an opaque-typed slot. An opaque type is not modelled as a schema or record.
[LOPQ.9.3] Adapter contract ([LADP]). An adapter's
contract library declares its opaque types alongside its schemas and
services; IDSP dispatch carries opaque-typed slots as their representation
encoding ([LOPQ.6.2]).
see also: LOPQ.6.2
[LOPQ.9.4] Method dispatch. For an opaque receiver the validator must resolve operations against the type's declared surface ([LOPQ.3]) rather than the representation's builtin method table.
see also: LOPQ.3
10. Scope, deferrals, and out-of-scope [LOPQ.10]#
[LOPQ.10.1] Representation. An opaque type is declared over Bytes; that is
the only admitted representation. The mechanism is representation-general, so a
further representation would use the identical declaration and carry its own
sealed-op surface and conformance.
ratified
[LOPQ.10.2] An opaque type's bound is its representation's. It inherits whatever bounding its representation has.
[LOPQ.10.3] Resource / handle types — out of scope. Opaque types are values:
copyable, equatable, inert ([LOPQ.5]). A resource or handle type — uncopyable,
lifecycle-bound, must-be-released — is a distinct feature (linear typing) and is
not specified here. Lifecycle-bound resources are held by the adapter behind the
IDSP boundary; only value-like results cross into the rule layer. A
content-addressed reference (a hash that is identity) is an opaque value and
fits here; an open file or socket handle is a resource and does not.
see also: LOPQ.5
[LOPQ.10.4] Value ordering. Opaque values are not ordered: the driver routes
purely on equality, and an ordering comparison (< <= > >=) on an opaque
value is a sealed operation ([LOPQ.3.3], DS_VALIDATE_OPAQUE_NO_OP).
see also: LOPQ.3.3
11. Error codes [LOPQ.11]#
Compile-time validators (no runtime code):
DS_VALIDATE_OPAQUE_NO_OP— a sealed operation applied to an opaque receiver: a representation builtin or value ordering ([LOPQ.3.3]; ordering deferred, [LOPQ.10.4]), rule-level construction ([LOPQ.4.1]), or rule-level elimination ([LOPQ.4.3]).DS_VALIDATE_OPAQUE_TYPE_MISMATCH— an assignment, comparison, or argument binding across two distinct opaque types, or between an opaque type and its representation ([LOPQ.2.3]).
12. Example [LOPQ.12]#
A crypto adapter publishes Key, Signature, Digest; the build coordinator's
rules route on keys and delegate verification, and can neither read nor forge key
material:
r.builder_pubkey.len() ([LOPQ.3.3]), r.builder_pubkey == r.artifact_hash
(Key vs Digest, [LOPQ.2.3]), and Key(some_bytes) ([LOPQ.4.1]) are each
compile errors.