Expand description
#2485: is a service-contract change compatible, or breaking?
crate::contract reduces a service to a canonical text and an FNV-1a hash,
and the deploy gate (ADR 0491) counts any difference as skew. A hash says
whether a contract moved, never how. This module keeps the structure the
hash throws away, so the toolchain can say whether a caller compiled against
one contract still works against a callee providing another, and why.
Three pieces, all here so the deploy gate and the editor share one answer:
ServiceShape: the contract as a tree, built by the same walk ascrate::contract::service_normal_formand rendering back to exactly that text (ServiceShape::normal_form), so a stored shape can be checked against the hash it was recorded with.ServiceShape::to_text/ServiceShape::from_text: a compact, unambiguous text for the ledger and the build manifest. The normal form itself cannot be parsed back (AgeInt where Positivedoes not say where the type’s name stops and its base begins), so the ledger keeps this beside the hash instead.check_call: the classifier.
§The rule
Compatibility is about values on the wire, so the rules are the wire
format’s own (reference/wire-format.md): a record is an object keyed by
field name, an unknown key is ignored, a missing Option field is None,
a bare value is accepted where an Option is expected, and a multi-argument
call is an object keyed by parameter name. A request flows caller to callee
and a response callee to caller; in both, the receiver must be able to
decode everything the sender can produce. That one question,
flows(sender, receiver), is asked of the request with the caller as sender
and of the response with the callee as sender, which is how “add an optional
request field” is compatible and “add a response variant” is breaking from a
single definition.
The classifier errs towards breaking. A field missing from the sender
is compatible only when it is an Option or the receiver’s field declares a
default (#2689: the stored shape marks it; a shape recorded before the
marker reads as having none). A wrong
“compatible” lets a breaking deploy through; a wrong “breaking” only names a
skew the gate already refuses.
Structs§
- Accepted
- #2554: what a callee accepts of the older contracts a lock lists for one service.
- Compatibility
- Context
Accepted - #2554: the older contracts one context’s services accept, from the contracts lock, with what was left out.
- Field
- Finding
- One difference between the two contracts, and whether the call survives it.
- Service
Shape - One
on callservice contract as a tree. - Variant
Enums§
- Direction
- Which half of the call a finding is about.
- Shape
- One type as it appears on the wire. Mirrors the
Contractrendering ofcrate::contract: named types expand structurally, record fields and sum variants are sorted, predicates are a sorted set, and an opaque type’s predicate is left out. - Verdict
Functions§
- accepted_
for - Decide which of
older(shape texts from the contracts lock) the callee whose service hascurrentaccepts. - check_
call - Can a caller compiled against
callersafely call a callee providingcallee? - own_
accepted - Which older contracts each of a context’s
on callservices accepts.older(service)is the lock’s shape texts for it.capis how many a service may keep before it is reported. - own_
contract_ shapes - A context’s own
on callshapes as ledger text, keyed by service name — the structured twin ofcrate::contract::own_contract_hashes, built from the same projection and the same table so each text hashes to the hash recorded beside it.