Generic Requirement Architecture
Public syntax and semantics are specified in Generics, Interfaces, and Methods. This document records the compiler boundary completed through v0.11.0 Phase 3.
Representations
The AST represents a generic parameter as a name and source span only. Every constraint belongs to one declaration-owned WhereClause. Its predicates retain separate spans for contextual keywords, target names, capability types, and equality operands. where copy T, where T: Interface, and where L.Item = R.Item therefore remain distinct authored nodes instead of overloading a type expression or a parameter modifier.
Resolver signatures map predicates to lexical parameter identities. They store parameter requirements in GenericRequirements and resolved type equalities beside them. Each parameter requirement has one semantic kind: nominal, callable, or intrinsic copy. Consumers select the kind they understand instead of reclassifying arbitrary TypeExpr values or inspecting formatted text.
TypeEnvironment carries the resolved requirements for every visible generic parameter. Interface lookup consumes nominal requirements, callable invocation consumes callable requirements, and the ownership classifier consumes copy. Concrete call and conditional-conformance matching use the same classifier as generic-body ownership. Copy requirements produce no witness, ABI field, or runtime metadata. Equality entailment consumes the same type environment and produces no runtime witness.
Declaration and Specialization Flow
- 1. Parsing records name-only parameter lists and declaration-wide
wherepredicates without reservingcopyorwhereglobally. - Declaration validation resolves every predicate target in lexical generic scope and rejects duplicate or invalid requirement sets.
- Resolver signatures derive every parameter requirement from the clause by parameter identity.
- Generic-body checking treats
Tas copyable only when its environment contains the intrinsic requirement. - Call specialization validates the concrete substitution at the argument evidence span.
- A nominal specialization validates its declaration's requirements before the type can be used as a field, parameter, result, conformance target, or nested type argument.
- Associated-type bounds and equality predicates validate through the same resolved requirement and projection services.
- Imported signatures qualify nominal bound and equality operand types while preserving intrinsic identities and source spans.
AST JSON, normalized presentation, type occurrences, semantic tokens, signature help, and diagnostics derive from these representations. Editor code must not scan source text to rediscover requirements.
Standard-Library Contract
Readonly generic copying must be stated at the public declaration. Vec.from_slice, Vec.try_from_slice, and their top-level forwarding functions use where copy T. Moving iteration and construction APIs remain unconstrained.
Source Invariants
<T, U>declares names and arity;<copy T>and<T: Interface>are rejected syntax.where T: Capabilityis reserved for interface and structural callable conformance.where copy Tis the only intrinsic copy spelling;where T: copyis rejected.where Left = Righton an ordinary generic declaration relates types and requires at least one associated projection.instanceandconformclassifywhere Binder = Typeseparately as a directed declaration-pattern refinement; see Declaration Type Pattern Architecture.- functions, methods, literals, nominal declarations, aliases, instances, and conformances all own the same clause representation; no declaration kind carries an inline fallback.
- associated type declarations may retain
pub type Item: Interfacebecause that bound constrains the type selected for the member, not a generic parameter.
Parser recovery, AST JSON, formatting, qualification, diagnostics, hover, completion, signature help, and semantic tokens consume these authored nodes or their resolved identities. Editor code must not scan source text or parse a presentation label to rediscover a requirement.