Expand description
Type checker and refinement validator (spec §§5–6, v0.1 §4.2, v0.2 §4.2).
Operates on a ResolvedCommons. Walks declarations, validates each
refinement against the spec’s predicate-base compatibility and combination
rules, then type-checks every function and method body.
v0.2 extensions:
- Record types (compatibility, field access, construction).
- Sum types and variant construction (qualified and unqualified).
- Methods (instance and static) with UFCS-style call resolution.
- Pattern matching with exhaustiveness checking.
- The
isoperator with binding flow into truthy contexts. - The built-in generic
Option[T].
Modules§
- codable
- Which types are
Codable, and the checks that need it. Constrained generics slice 3 (#2715; the model is the track’s Q4/Q7 indesign/archive/retired-tracks.md). - keying
- Which types are
Key, and the checks that need it. Constrained generics slice 2 (#2684; the model is the track’s Q6 indesign/archive/retired-tracks.md). - ordering
- Which types are
Ord, and the checks that need it. Constrained generics slice 1 (#2660; the model is the track’s Q2/Q5 indesign/archive/retired-tracks.md). - peek
- #3147:
D1.peek(<participant>.<Cap>), the case-only handle on a participant’s test D1 database.
Structs§
- Batch
Position - #3197: where a statement sits in its
batchlist literal. - Capability
Ctx - Mutable per-function context.
Capability bookkeeping for the checker — the
given-clause lifecycle and capability dispatch, grouped out of the checker’s working context (v0.29.10). Empty (Default) for pure functions / non-context code. - Capability
Info - Per-capability info for checker dispatch within a handler body.
- Capability
OpInfo - Check
Sinks - #522: the six output sinks a handler-body check writes into. One struct at
each call site instead of six positional
&mutarguments. - Checked
Program - T3.7 (R3.10): the gate between analysis and emission, as a type rather
than a control-flow decision — constructible only by
certify, so no unchecked or error-carryingTypedCommonscan reach the emitter by construction (previously enforced only by every caller happening to check aResultfirst).certifyrejects on any error-severity diagnostic; T3.3a’sTy::Erroris what a diagnosed checker failure records intoexpr_types, so in practice aTy::Errornever reaches aCheckedProgrameither — R4.3’s “rejected by certify” already holds today via the same diagnostic-severity gatecertifymakes structural. - D1Decode
Site - #3139: a
Json.decodeSql[T](x)linked to the statementx’s rows came from. - D1Sql
Site - #3070: one literal SQL statement of a derived
D1instance, as the project phase prepares it against the migrations’ schema. - ExprId
- P6.27 (design/tracks/the-ir.md §6a): re-exported so a checker consumer keying
off
expr_types/Callee(bothHashMap<ExprId, _>, Q2’s own settled totality story) can nameExprIdthroughbynk-checkalone, without also depending onbynk_syntax::astdirectly just to spell this one identity type — the same public-dependency-already-exists shape asTy/TyIdbelow. T3.4 (R2.4): a node’s identity, independent of position — allocated once, monotonically, per expression the parser constructs (Parser::alloc_expr_idinbynk-syntax/src/parser.rs). Never derived from aSpan, so two expressions occupying the same byte range (a synthetic node, a zero-width span) never collide the way a span-keyed side table could. - FnCaps
- #2868: the capability scope of a context function that declares
given. - Handler
Body Check - #522: everything
check_handler_bodyneeds to know about the handler — signature, capability scope, agent state, and held bindings. Replaces what was 17 positional parameters (of a 24-parameter signature);Self::newfills the agent/actor/store extras with empties, so a simple site (provider op, test body) sets only the fields it actually uses. - Record
Check - The outcome of
check_record: the typed model (Errif the file had any error) and, on the error path, the program as checked so far (typed_despite_errors), whoseexpr_typesare the best-effort types the checker computed. Analyse mode surfaces those for.-member completion and signature help even on a broken buffer (ADR 0094). - RowLink
- #3139: which value a name holds, on the way from a literal D1 read to the
Json.decodeSqlthat decodes its rows. - Test
Handler - One service handler, as a test body sees it (v0.178 / v0.182).
- Test
Service Sig - v0.178 (Slice 0, #662) / v0.182 (Slice A, #664): the shape a test body needs
to resolve a service invocation. Built by the project test pass from the
target unit’s service declarations, so the checker can resolve the addressed
handler (
svc.call(...)on anon callservice, or — Slice A —svc.GET("/x")/svc.schedule("…")/svc.message(m)on afrom http/cron/queueservice) and check its arity, argument types, and principal. - TyId
- T3.6b (R4.1/R4.2): a
Ty’s identity above the intern table —Copy,Hash,Ord, cheap to pass and compare. Resolved back to aTyonly via theTypestable it was interned into (see that type’s own doc). - Typed
Commons - Output of type checking.
- Typed
Expr - T3.4: an
expr_typesentry — the checked type, plus the span of the node it was computed for.Deref-free by design (.ty/.span, not.0/.1) so call sites read the same as they did against a bareTybefore this. - Types
- T3.6b (R4.1): the intern table
TyIdis minted from. Owned percheck_recordinvocation (design settled in the identity-and-totality track doc §9 before this slice started): created fresh atcheck_record’s entry, threaded throughCtx, carried out onTypedCommons/RecordCheckalongsideexpr_types, and forwarded across thebynk-check→bynk-emitboundary onCheckedProgram(T3.7a/T3.7b already built that seam). Confirmed safe by checking how cross-unit type references actually flow:compose_unit_symbolsmergesTypeDecl(immutable AST declarations) across units, never an already-internedTy/TyId— every unit re-interns its ownTygraph from shared declarations, soTyIds are never compared across two differentcheck_recordinvocations. - Variant
Info - A flattened view of a type’s variants (name + payload types).
- WsMessage
Shape - The shape of a
ws messagehandler: which parameter takes the inbound frame and how many parameters it has.
Enums§
- Callee
- P6.0 (design/tracks/the-ir.md §6, #1139): a resolved classification of a
call-shaped expression, recorded once by the checker’s own dispatch
(
checker::calls) rather than re-derived by each later consumer — closing R6.10’s duplicated-classification gap betweenbynk-checkandbynk-emit’slower_method_call/lower_call. - Handler
Address - Where a test-body service address (
svc.call(…),svc.GET("/p"),svc.schedule("*/5 * * * *"),ws.open(…)) is aimed: the typed form ofCallee::TestService’saddressstring (1A.33, Decision D). - Named
Kind - The shape of a named type — what its declaration looks like.
- Query
Role - Whether a
Callee::Querycall returns anotherQuery[T](chainable) or executes and returnsEffect[T]— R6.12: “the builder/terminal split is a field on the callee, not a name list.” Primarily read back fromcheck_query_kernel_method’s own return type at the recording site (query_role, below) — falling back tois_query_builder_nameonly when the call didn’t type at all (an arity mismatch, or a type error deeper inside the call —map’s own lambda body, say — both returnNonetoo, not just an arity failure), so a best-effort reader of an uncertified/erroring unit still gets the right role. - Store
Field - One agent
storefield’s kind and shape (finding #36) — the checker’s dispatch keys off this instead of five separate per-kind maps, so a new storage kind is one new variant rather than a sixth map threaded through every constructor and lookup site. - Ty
- A resolved type.
- WsAddress
- The WebSocket lifecycle step of a
HandlerAddress::Ws.MessageandClosecarry what the emitter needs once the handler is matched: the index of the inbound-frame parameter and the parameter count, and the count forclose. - Zero
Value - A target-neutral zero value: what a state field holds before it is first written. The checker decides whether a type has one; each backend decides how to spell it.
Constants§
- BOUNDARY_
REJECTIONS - #1934: the variants of
BoundaryRejection, each with whether it carries adetail: String(the router’s description of a refused body or path). The first three are the router’sBoundaryErrorkinds;Unauthorizedis the auth seam’s401to a request with no credential, andMethodNotAllowedthe router’s405to a method the path declares no handler for. The last two are the router’s413(a capped body over its cap) and415(a@rawroute’s otherContent-Type). Kept in sync withresponseToHttpOutcomeinbynk-emit/runtime/src/http.ts. - BYNK_
COLLECTION_ DEPRECATED - The
bynk.mapandbynk.setfree functions and the method form each rewrites to:(module, function, method, arity). One table, read by the warning below and by the wasmbynk_referencecatalogue so the two cannot drift. - BYNK_
LIST_ DEPRECATED - The deprecated
bynk.listfree functions and theListmethod form each rewrites to. One table, read by the warning below and by the wasmbynk_referencecatalogue so the two cannot drift. Since #3962 every function has a method form. - NEVER_
DISPLAY - How
Ty::Neverreads in a message or hover. It is not source syntax, so no inlay hint or inserted annotation may carry it (#2727). - RUN_
ID_ NS - #2138: the
Callee::Intrinsicnamespace ofrun.id.
Functions§
- call_
record_ type_ name - The synthetic record type name for
trace(Cap.op)’s call records (v0.117): one record per capability operation, its fields the operation’s parameters. - certify
- The single place “may we emit?” is asked (R3.10). Rejects — returning
every diagnostic, not just the error-severity ones, matching
check_record’s own error-path convention — ifdiagnosticscontains an error-severity entry; otherwise wrapsprogramas certified. - check
- check_
body - Type-check a bare body against
return_tyinscope, withcapsavailable as both in-scope and declared capabilities and (if non-empty)test_services/test_actorsin scope for a test-case body’ssvc.call/by <Actor>(...)resolution (§32/#33: the one shape every hand-rolledCtxoutside this crate needed, lettingCtxitself staypub(crate)).where_pred, if present, is checked first againstBool(a property’s optionalfor all ... wherefilter —bynk.property.where_not_boolon mismatch), sharingctxwith the main body so both populate the sameexpr_types/errorssinks. Unlikecheck_handler_body, this skips the linearity pass, the return-type-mismatch diagnostic, and the unused-givendiagnostic — nothing outside this crate that built its ownCtxran those either, and adding them here would be a behaviour change, not a refactor. - check_
const_ decl - #2617: check a
constdeclaration declared in this file. Its name is upper-camel (bynk.resolve.const_name_case) and is no variant of a sum type in scope (bynk.resolve.name_conflict); its initialiser is inside the closed static set (bynk.resolve.bad_const_initialiser, decision A) and, typed against the annotation in an empty, pure scope (thecheck_static_initialiserdiscipline), a value of that type. A diagnostic the typing raises (a literal its refined type rejects,.unsafeoutside the defining commons) is reported as it stands; a value of another type isbynk.resolve.bad_const_initialiser. The initialiser’s expression types are recorded for the emitter. - check_
context_ fn - #2868: check a context function that declares
given, with its capabilities in scope. - check_
event_ field_ default - Events slice 3a (#972): type-check an event field’s default expression
(
field: T = init), reusingcheck_static_initialiser’s empty-pure-scope discipline. Pushesbynk.types.bad_field_default. - check_
handler_ body - Check a single handler body (used for service and agent handlers).
- check_
invariants - Check an agent’s invariant declarations (v0.80 §14). Each predicate is a pure
Bool-typed expression over the agent’s state fields (referenced by bare name), plusimplies/is. The pass enforces: - check_
migrations - State-migrations S2 (#2224, track §3.3): check each
migratestep’s body on its own terms, with no lock: the old parameter names a record type, the body is pure and key-free, each:=targets aCellorMapfield with a value of that field’s type, and no field is assigned twice (record-literal semantics). What the lock alone can check (the old shape against the recorded version, and which changes the step covers) isschema_registry::reconcile_agents’s. - check_
record check, recording binding edges intorefsat the checker’s resolution sites (v0.25). A fresh sink records nothing.- check_
record_ in check_recordagainst a caller-supplied intern table (T3.6b, R4.1).- check_
state_ initialiser - v0.11: type-check an agent state-field initialiser (
field: T = init). Seecheck_static_initialiser. Pushesbynk.agents.bad_state_initialiser. - check_
suite_ decls - #3066: check the
typeandconstdeclarations of a suite, already added toinput(the suite’s view). They are checked as a unit’s own are:check_type_decl, a record’s field defaults,check_const_decland the cycles through the suite’s constants. Returns the initialisers’ expression types and callee classifications for the emitter. - check_
suite_ fn - #2834: check a suite-local helper
fnagainstinput(the suite’s view, with its sibling helpers), admitting test-only values. - check_
transitions - Check an agent’s step invariants (v0.116 §, testing track slice 4). A
transitionis the invariant predicate widened to the step (ADR 0144 — one predicate surface): a pureBoolpredicate over theold/newstate pair, each bound to the agent’s synthetic state record (state_ty), soold.status/new.statusresolve like any record field. The pass enforces, mirroringcheck_invariants: - compatible
tis usable whereuis expected.- embedding_
for - v0.154 (ADR 0178): the declared error embedding that converts
source_errintotarget_err, if one exists. Whentarget_erris a sum declaringembeds E as VwithEcompatible withsource_err, returns(sum_type_name, variant_name)— the variant a value ofsource_errauto-wraps into. One level only: the source must match a declared embedding directly. Used by?in the checker (to accept the conversion) and the emitter (to lower theErr-wrap) from the same rule, so the two cannot diverge. - instantiate_
field_ ty - v0.157 (ADR 0183): the type of a generic record’s field at a concrete
instantiation. The field’s declared type is resolved with the declaration’s
type parameters in scope as rigid vars, then those vars are replaced by the
instantiation’s
args. For a non-generic record this is a plain resolve. - is_
zeroable - Whether
type_refhas a zero value. - locale_
tag_ accepts - Whether
tagsatisfiesLocaleTag’s refinement — the check behindbynk.messages.invalid_locale_tag. Evaluated with the same regex-engine semantics (regress, anchored, no flags) the emittednew RegExp(...)runs under, so a tag accepted here is one the runtime cast is honest about. - locale_
tag_ pattern - The pattern
LocaleTag’s refinement matches against, for a diagnostic that names it.Noneif the type carries noMatchespredicate. - map_
entry_ ty - v0.158 (ADR 0184): the compiler-known
MapEntry[K, V]record — the element astore Map[K, V]’s.entriesquery yields. A nominal generic record ({ key: K, value: V }), so it flows throughunify/compatible/displayand the ADR 0183 non-boundary rule like any generic-record instantiation; its fields are resolved by name incheck_field_access(it has no user-visibleTypeDecl, likeDecodeError). - named_
ty - Build a
Ty::Namedfor the given declaration (no applied type arguments). - named_
ty_ with_ args - Build a
Ty::Namedfor the given declaration with the given applied type arguments (empty for a non-generic reference). - record_
type_ refs - v0.25 (ADR 0053): record a binding edge for every
Namedreference inside a type-ref that resolved. Called alongside theresolve_type_ref*annotation sites;skipholds the enclosing fn’s type parameters (rigid vars are not type symbols). Handler signatures and body annotations never pass through the resolver’s reference walk, so these sites are their only recording point; where both passes run, assembly dedupes. - refinement_
example - #2686: the
@example(<arg>)annotation’s argument on a refinement, if one is written (well-formed or not:check_refinement_annotationsreports a malformed one, andValmust not pile aneeds_pinon top). - reset_
compared_ cache - #1688: clear the cache of generic functions’ compared type parameters.
A project check calls this once before its per-unit loop; a single-file
checkcalls it itself. - resolve_
type_ ref - resolve_
type_ ref_ in - v0.20a: like
resolve_type_ref, with a set of in-scope type parameters: aNamedreference matching one resolves toTy::Var(checked before the type-table lookup — a type parameter shadows a same-named declaration; the collision is diagnosed at the declaration). - row_
base_ fields - The names of
T‘s row fields whose type isbase(directly, through anOption, or under a refined or opaque type): the columns a dialect’s pass over the parsed rows converts before the codec runs (Boolfor SQLite’s0/1;IntandInstantfor Postgres’ text forms, #3320). - row_
bool_ fields - The names of
T’s row fields that decode asBool(directly, through anOption, or under a refined or opaque type), forJson.decodeSql’s pass over SQLite’s0/1.Thas passedcheck_row_shape. - split_
regex_ flags - K6c (#2600): a checked regex literal as the emitter writes it, the pattern
and its
RegExpflags. The checker has already refused a malformed flag group, so this only splits. - string_
refinement_ violation - #2869: the first predicate of a refined or opaque
Stringtype thatvaluefails, in the order the emitted boundary checks them (Nonewhen it holds every one, or when the type carries no refinement).bynk tokenvalidates a--subagainst a Bearer actor’s identity type with it, so the token it signs is one the seam’s own refinement check accepts. - type_
from_ decl - Build a
Tyfrom a TypeDecl name reference. - type_
param_ subst - v0.157 (ADR 0183): the substitution mapping a generic record’s declared
type parameters onto a concrete instantiation’s arguments. Empty when the
type is non-generic or
argsis empty (an under-applied reference — the resolver reports that separately). - variants_
of pubsince P6.4 (#1157, Decision A) — seeVariantInfo’s own doc comment for whybynk-emitneeds this exact function rather than a re-derived copy (R5.11, for the IR side).- zero_
value - The zero value of
type_ref(with an optional inline field refinement), orNoneif the type is not zeroable.