Expand description
Per-type serialise / deserialise helper generation for workers mode (v0.8 §3.4 / §5.2).
Every Bynk type that crosses a context boundary needs:
serialise_<Type>(value): JsonValue— structural lowering.deserialise_<Type>(json): Result<<Type>, BoundaryError>— structural validation + refinement re-validation, then a nominal cast back to the receiving context’s view.
Helpers live in the owning module — commons modules emit helpers for commons types, context modules emit helpers for the types they declare.
Functions§
- collect_
codec_ closure - v0.22b: the codec closure for a set of
Json.encode/Json.decode[T]target type-refs — the named types needing per-type helpers (transitively through record fields and sum payloads) plus the generic instantiations needing specialised helpers. The same closure logic as the boundary collectors, rooted at expressions instead of service signatures. - decls_
as_ stmts - Collects
declsinto real statements — the shared shape every caller ofemit_helpers_for_owner/emit_generic_helpers(and their_qualifiedtwins) collects into its own returnedVec<TsStmt>. Arc F slice 1 (#1451): consolidates what used to be ten separatewrite!-family call sites into this one; #1478 made it the one real implementation (dropping a hand-duplicatedout: &mut String-printing sibling); #1479 removed that sibling’s own last two production callers (project/ tests_emit.rs’s codec-helper glue), so every caller in the crate is on thisVec<TsStmt>form directly now. #1486: no more explicit blankTsStmtafter each declaration — none of these are import/comment-kind, so the printer’s automatic top-level spacing policy already supplies exactly one blank between every adjacent pair (and after the last one, before whatever follows) once a real caller prints through it. - decls_
as_ stmts_ block - As
decls_as_stmts, plus one extra forced trailing blankTsStmtwhen anything was collected — the sharedif emitted_any { ... }trailer everyemit_helpers_for_owner/[emit_helpers_for_owner_ qualified] caller needs. Under the pre-#1486 flat-print regime this trailer’s own blank stacked on top ofdecls_as_stmts’s own per-decl blank (oneTsStmt::blankafter every decl, including the last), giving this group’s own tail two blank lines total — a genuine, stronger “owner group” section break (confirmed against118_workers_target_with_consume’s own real fixture output: thelocal_boundaryhelpers group and the followingby_commonsre-export group are separated by two blank lines, not one), not a redundant duplicate of the ordinary one-blank-between-decls spacingdecls_as_stmtsnow gets for free from the printer’s automatic policy.no_blank_beforeon the extra blank itself suppresses its own automatic lead-in (which would otherwise stack with the ordinary one the policy already supplies between the last real decl and this blank), leaving exactly one blank line from this statement’s own render plus the policy’s own ordinary blank before whatever follows — two lines total, matching the pre-#1486 text exactly. - deserialise_
ref_ via - v0.176 (#642): a deserialise reference for
ns, shaped tocallService’sdeserialiseResultparameter. The inline arms become a lambda rather than the unvalidated((j: any) => ({ tag: "Ok", value: j }))identity the caller path used to fall back to. - emit_
generic_ helpers_ qualified - #661: as
emit_generic_helpers, but the value-type positions of each specialised helper are named through the typeQual— so a consumer’sdeserialise_Result_AuthId_PaymentErrorreturnsResult<commerce_payment.AuthId, commerce_payment.PaymentError>while its codec calls stay local. The codec suffix (Result_AuthId_PaymentError) is namespace-independent by construction, which is exactly what keeps the caller’s and callee’s names in agreement across the wire. - emit_
helpers_ for_ owner_ qualified - #661: as
emit_helpers_for_owner, but the caller supplies a typeQual. With an empty qualifier this is the owner’s own module (every type named bare, refined validation through.of). With a non-empty one it is a consumer generating its own view of another context’s boundary types: the qualified names reach through theimport type * as <ns>alias, and refined validation inlines (transparent) or casts structurally (opaque) because the owner’s.ofis not importable. - root_
names_ any - #3066: whether a codec root names one of
names(a suite’s own types) anywhere, through generic arguments. Such a root is served by the suite runner’s own local codecs (super::emit::emit_suite_decls), not the module-level closure, which cannot name a type declared inside a runner. - serialise_
expr_ via - v0.176 (#642): the one serialise dispatch for the workers cross-context
boundary, reaching helpers through
ns. Replaces the two parallel dispatches this boundary used to carry —emit.rs’sworkers_serialise_expr(which droppedList/Mapto a bareas JsonValuecast) andworkers_entry.rs’sserialise_call(which did the same toBytes, the asymmetry that forcedbynk.types.bytes_at_workers_boundary).