# RFC 0027: Explicit built-in error values Status: Implemented Scope: STD-6d.2 prerequisite; vertical Phase 6, additive AIR format 0 Language version: 0.1 Adoption: owner-requested intermediate std merge, 2026-10-07; normative rules and reference implementation are integrated together. ## Motivation A library must reject overflowing allocation sizes before allocation. Built-in errors could previously only arrive from runtime operations. Artificially allocating to obtain an error would obscure authority and failure behavior. Explicit construction makes pure validation implementable and preserves a single error vocabulary. ## Precise invariant An error value is Copy data. Creating, copying, returning or matching it never confers authority, consumes a resource or proves that an operation happened. Runtime operations keep their existing outcome contracts. ## Normative rule changes Spec 05 §14 specifies pure construction of every frozen registered variant of alloc_error, cap_error and io_error. Spec 07a and the AIR grammar add `error.const B.variant`. Spec 15 §6 extends the existing source variant expression to those built-in families. The registry adds `error_values`, depending on the full feature closure defining all three families. ## Verifier implications Validate static family/tag and result uses; define one available Copy value. No new abstract state, ownership, alias, resource or concurrency rule. Validation is constant time over the fixed variant registry. ## Interpreter / runtime implications Bind a built-in family/tag deterministically, consuming ordinary fuel, without program allocation, I/O or capability acquisition. Error data already has a runtime representation. Real allocation failure remains separately specified. ## AIR changes `error.const` takes a registered error family and variant as static operands, no SSA inputs or payloads, and has one result of that family's type. It has no ownership, borrow, memory or concurrency effects, requires no effects/capabilities and has no instruction-specific traps. The feature declaration is mandatory. This is not syntax sugar: no existing pure instruction constructs a built-in error. `enum.make` retains its declared-enum contract. ## Valid example ```aji fn overflow() -> alloc_error effects [] { return alloc_error::budget_exceeded; } ``` ## Rejected example ```aji fn forge() -> cap effects [] { return alloc_error::budget_exceeded; } ``` Expected diagnostic: E7005; equivalent AIR is E1001. Missing feature is E0006, unknown AIR family/tag E0004, payload syntax E0001. Unknown source variant is E7002, payload arity E7005. No new diagnostic codes. ## Spec integration Spec 05 §14, 07 §8.9, 07a Values, 08 §3, 15 §6; reference AIR grammar and feature registry; both agent bundle manifests and Quick Reference. Q-038 is resolved by these contracts. ## Compatibility and migration Additive feature in format 0. Existing type/variant meanings, enum.make, fallible operations and authority rules remain frozen. Older implementations reject modules declaring error_values through normal feature negotiation. No migration for existing source or AIR. ## Agent complexity impact One coherent semantic block: constructing ordinary error data. One feature and AIR instruction, no new source syntax form, diagnostics, verifier state or ownership concepts. Existing Enum::variant syntax and exhaustive matching suffice. Explicit preflight failures reduce the need for ad hoc error enums or artificial runtime calls. No empirical MCC benefit is claimed. Dependencies define the error data vocabulary, not ambient authority. Measured Quick Reference, source and AIR bundle growth and validation are recorded below when checks finish. ## Alternatives considered Changing enum.make would alter frozen baseline semantics. A new library-specific overflow enum would force different allocation error handling. Harvesting runtime errors through fake allocations changes failure/authority behavior. A payload-free constant is the smallest explicit primitive covering existing error families. ## Unresolved questions None for this feature. General map key hashing/equality remains Q-037. ## Validation and measured documentation budget `zig build`, `zig build test` and formatting pass. All 32 error-value conformance cases pass normally and with collection before every instruction; all 17 registered tags are exercised directly in AIR and through exhaustive source matches. `tests/hosted/source_errors.py` passes 26 CLI checks, including canonical lowering, matching source/AIR run records, hosted execution and zero-allocation/zero-entry-authority audit reports. Source coverage is 96/96. The full working-tree regression also includes the developing map consumer. Relative to RFC 0026, excluding the uncommitted map library contract from the generated source library page: | Group | cl100k | o200k | Qwen2.5 | |---|---|---|---| | Quick Reference | 7,806 → 7,863 | 7,837 → 7,894 | 8,043 → 8,102 | | Other source docs | 47,475 → 48,061 | 47,616 → 48,204 | 48,802 → 49,419 | | Full source excluding AIR | 55,281 → 55,924 | 55,453 → 56,098 | 56,845 → 57,521 | | AIR inside source bundle | 45,520 → 46,300 | 45,667 → 46,451 | 46,981 → 47,800 | Standalone AIR grows from 175,736 to 179,282 bytes, 19 files / 51 sections. Incremental full source growth is 1.2%; cumulative growth since the pre-stdlib cl100k baseline 33,981 is 64.6%, above the existing review line. The cost is justified by a necessary pure validation primitive with no new source form, authority or ownership concepts. Detailed contracts remain on demand; documentation growth is not evidence of MCC improvement.