0027. Nominal interfaces with static dispatch and global coherence
- Status: Accepted; unrestricted method lookup superseded by 0069
- Date: 2026-10-30
- Plan: M4.7
- Review: Language semantics; Changes to the plugin decisions
Context
Generic definitions need explicit capabilities while preserving definition-time checking (ADR-0024). Whole-program compilation permits bridge implementations without an orphan rule. The agreed M4 plan fixes syntax and diagnostic codes.
Decision
Declare signatures with
interface Area { fn area(self) -> i64 }, implement
with
impl Area for Point { fn area(self) -> i64 { … } },
and call x.area(). Only the first method parameter
may omit its annotation: self means
Self. Self in signatures denotes the
receiver type, including other parameters and returns. Impl
targets are exact concrete types, including builtins and generic
instantiations. Function bounds use
<T: Area + Named>; definitions check using only
those bounds, and calls prove them after inference, including
forwarding.
Collect interfaces, then all impl keys before checking bodies.
There is one impl per (interface, exact type), globally, without
an orphan restriction. E0650 points at the later impl and names
both definitions by line and column. Missing methods are reported
together. Method lookup searches applicable interfaces or
parameter bounds; ambiguity requires
Area.area(x).
Monomorphization discovers called impl methods after user
functions and emits ordinary direct calls with the receiver
evaluated first. Unreached impls emit no C. Method instances
display as Area.area<Point>; self
is a value parameter. Interfaces and impls format as braced,
newline-separated methods; signatures have no semicolons, per
ADR-0018. Existing record/union postfix formatting applies.
Alternatives considered
- Orphan rule — prevents bridge plugins despite global conflict checking.
- Dynamic dispatch /
dyn— adds representation and runtime costs without M4 evidence; static dispatch uses existing concrete IR and both backends. - Inherent impls or qualified calls as the primary form — widen lookup or burden common calls; qualification serves only explicit disambiguation.
- Generic interfaces/methods/impls, defaults or associated types — expand inference and coherence; M4 rejects these rather than checking at instantiation.
Consequences
Interfaces are bounds, not value types. Adding a required method breaks impls. Exact concrete impls may be repetitive; blanket impls wait for measured need. No vtables, indirect calls, new IR operations or backend-specific semantics. The three pre-M4.7 placeholder method/bound diagnostic expectations must change: their future-tense help is obsolete and missing concrete methods now use E0662 instead of E0405, as the agreed code table requires. Program/IR goldens stay exact.